Browse Source

Fix mem issue in profile; measure peak memory usage.

Stefano Cossu 1 year ago
parent
commit
a52682bd35
2 changed files with 17 additions and 4 deletions
  1. 12 2
      Makefile
  2. 5 2
      profile.c

+ 12 - 2
Makefile

@@ -16,6 +16,7 @@ MDB_DIR = ext/openldap/libraries/liblmdb
 XXHASH_DIR = ext/xxHash
 XXHASH_DIR = ext/xxHash
 VALGRIND_DUMP = /tmp/lsup_valgrind.log
 VALGRIND_DUMP = /tmp/lsup_valgrind.log
 CALLGRIND_DUMP = /tmp/lsup_callgrind.out
 CALLGRIND_DUMP = /tmp/lsup_callgrind.out
+MASSIF_DUMP = /tmp/lsup_massif.out
 
 
 INCLUDE_BASE ::= . -Iinclude -I$(MDB_DIR) -I$(XXHASH_DIR) \
 INCLUDE_BASE ::= . -Iinclude -I$(MDB_DIR) -I$(XXHASH_DIR) \
 	-Iext/tpl/src -Iext/hashmap -Iext/log/src
 	-Iext/tpl/src -Iext/hashmap -Iext/log/src
@@ -235,10 +236,19 @@ perftest: bin/perftest ## Run a performance test by creating, inserting and look
 
 
 
 
 .PHONY: profile
 .PHONY: profile
-profile: bin/perftest ## Run a profiling session. Output can be inspected with KCachegrind.
+profile: bin/profile ## Run a profiling session. Output can be inspected with KCachegrind.
 	LSUP_MDB_MAPSIZE=800000 valgrind --tool=callgrind \
 	LSUP_MDB_MAPSIZE=800000 valgrind --tool=callgrind \
 		--callgrind-out-file="$(CALLGRIND_DUMP)" bin/perftest 1000
 		--callgrind-out-file="$(CALLGRIND_DUMP)" bin/perftest 1000
-	@echo "Profile dump written at $(CALLGRIND_DUMP)"
+	@echo "Profile dump written at $(CALLGRIND_DUMP). Open it with "\
+		"qcachegrind, kcachegrind, etc."
+
+
+.PHONY: footprint
+footprint: bin/perftest ## Measure memory footprint of storing 100K triples.
+	LSUP_MDB_MAPSIZE=80000000 valgrind --tool=massif \
+		--massif-out-file=$(MASSIF_DUMP) bin/perftest 100000
+	@echo "Memory stats file written at $(MASSIF_DUMP). Open it with "\
+		"massiftool or similar."
 
 
 
 
 .PHONY: pytest
 .PHONY: pytest

+ 5 - 2
profile.c

@@ -78,15 +78,18 @@ int main(int argc, char *argv[])
 
 
     log_info ("Lookup...");
     log_info ("Lookup...");
     ct = 0;
     ct = 0;
-    LSUP_Triple *spo = TRP_DUMMY;
     LSUP_Term *s = LSUP_iriref_new ("urn:s:8", NULL);
     LSUP_Term *s = LSUP_iriref_new ("urn:s:8", NULL);
     LSUP_Term *p = LSUP_iriref_new ("urn:p:0", NULL);
     LSUP_Term *p = LSUP_iriref_new ("urn:p:0", NULL);
     LSUP_Term *o = LSUP_iriref_new ("urn:o:300", NULL);
     LSUP_Term *o = LSUP_iriref_new ("urn:o:300", NULL);
     LSUP_GraphIterator *it = LSUP_graph_lookup(gr, s, NULL, NULL, &ct);
     LSUP_GraphIterator *it = LSUP_graph_lookup(gr, s, NULL, NULL, &ct);
     log_info ("Found triples by count: %lu", ct);
     log_info ("Found triples by count: %lu", ct);
+    LSUP_Triple *spo = NULL;
     ct = 0;
     ct = 0;
-    while (LSUP_graph_iter_next (it, spo) != LSUP_END)
+    while (LSUP_graph_iter_next (it, &spo) != LSUP_END) {
         ct ++;
         ct ++;
+        LSUP_triple_free (spo);
+        spo = NULL;
+    }
     log_info ("Found triples by iteration: %lu", ct);
     log_info ("Found triples by iteration: %lu", ct);
     LSUP_graph_iter_free (it);
     LSUP_graph_iter_free (it);
     end = clock();
     end = clock();