فهرست منبع

Fix profiling.

Stefano Cossu 3 سال پیش
والد
کامیت
dbdfb5807e
4فایلهای تغییر یافته به همراه55 افزوده شده و 43 حذف شده
  1. 10 4
      Makefile
  2. 33 29
      docs/dev/deps.dot
  3. BIN
      docs/dev/deps.pdf
  4. 12 10
      profile.c

+ 10 - 4
Makefile

@@ -14,6 +14,7 @@ PREFIX = /usr/local
 bindir = $(PREFIX)/bin
 libdir = $(PREFIX)/lib
 includedir = $(PREFIX)/include/lsup_rdf
+CALLGRIND_DUMP = /tmp/lsup_callgrind.%p.out
 
 INCLUDE_BASE = . -Iinclude -Iext/xxHash -Iext/openldap/libraries/liblmdb \
 	-Iext/tpl/src -Iext/uthash/src -Iext/log/src
@@ -137,14 +138,19 @@ memcheck:
 memtest: test memcheck
 
 
-profile: build_parsers
+bin/profile: $(OBJ) $(DEPLIBS)
 	$(CC) \
-		$(CFLAGS) -g -DTESTING \
-		$(INCLUDE) \
-		$(SRC) profile.c \
+		$(CFLAGS) -g -DTESTING $(SRC) $(CODEC_SRC) profile.c -L. $(LDFLAGS) \
 		-o bin/profile
 
 
+.PHONY: profile
+profile: bin/profile
+	exec valgrind --tool=callgrind --callgrind-out-file="$(CALLGRIND_DUMP)" \
+		bin/profile 10000 && \
+		echo "Profile dump written at $(CALLGRIND_DUMP)"
+
+
 py_test:
 	pip3 install --user . && \
 	python3 test/cpython_test.py

+ 33 - 29
docs/dev/deps.dot

@@ -5,41 +5,45 @@ digraph "source tree" {
     fontsize="16";
     fontname="Helvetica";
 	clusterrank="local";
-	"environment" -> "store_mdb"
-	"buffer" -> "xxhash"
+	"py_triple" -> "py_term"
+	"store_mdb" -> "namespace"
+	"store_htable" -> "uthash"
 	"graph" -> "store_htable"
-	"profile" -> "lsup_rdf"
-	"graph" -> "environment"
-	"py_graph" -> "graph"
-	"py_lsup_rdf" -> "py_namespace"
-	"namespace" -> "core"
-	"graph" -> "term"
 	"store_htable" -> "buffer"
+	"nt_parser" -> "nt_grammar"
+	"py_graph" -> "codec_nt"
+	"codec_nt" -> "nt_parser"
 	"codec_nt" -> "codec_base"
 	"codec_base" -> "graph"
-	"term" -> "buffer"
-	"term" -> "uthash"
-	"py_namespace" -> "namespace"
-	"py_graph" -> "codec_nt"
-	"namespace" -> "uthash"
-	"store_htable" -> "uthash"
-	"py_lsup_rdf" -> "py_graph"
-	"term" -> "tpl"
-	"py_term" -> "term"
-	"lsup_rdf" -> "codec_nt"
-	"nt_parser" -> "graph"
-	"core" -> "log"
-	"graph" -> "store_mdb"
-	"py_graph" -> "py_triple"
-	"buffer" -> "core"
 	"store_mdb" -> "lmdb"
+	"core" -> "lmdb"
+	"graph" -> "store_mdb"
 	"store_mdb" -> "buffer"
-	"term" -> "namespace"
-	"codec_nt" -> "nt_parser"
+	"graph" -> "environment"
+	"buffer" -> "core"
+	"core" -> "log"
 	"nt_grammar" -> "graph"
-	"store_mdb" -> "bootstrap"
-	"py_triple" -> "py_term"
+	"py_term" -> "term"
+	"py_graph" -> "graph"
+	"graph" -> "term"
+	"term" -> "buffer"
+	"environment" -> "term"
+	"profile" -> "lsup_rdf"
+	"py_term" -> "py_namespace"
+	"buffer" -> "xxhash"
+	"py_lsup_rdf" -> "py_graph"
+	"namespace" -> "core"
 	"store_mdb" -> "store"
-	"core" -> "lmdb"
-	"nt_parser" -> "nt_grammar"
+	"environment" -> "store_mdb"
+	"namespace" -> "uthash"
+	"store_mdb" -> "bootstrap"
+	"store_mdb" -> "uthash"
+	"lsup_rdf" -> "codec_nt"
+	"term" -> "namespace"
+	"py_namespace" -> "namespace"
+	"py_graph" -> "py_triple"
+	"term" -> "tpl"
+	"nt_parser" -> "graph"
+	"py_lsup_rdf" -> "py_namespace"
+	"term" -> "uthash"
 }

BIN
docs/dev/deps.pdf


+ 12 - 10
profile.c

@@ -1,9 +1,7 @@
 #include <time.h>
 #include "lsup_rdf.h"
 
-#ifndef NT
 #define NT 100000
-#endif
 
 static LSUP_Triple *
 generate_triples(size_t nt)
@@ -19,8 +17,8 @@ generate_triples(size_t nt)
         sprintf(pstr, "urn:p:%lu", i % (nt / 1000));
         sprintf(ostr, "urn:o:%lu", i);
         LSUP_triple_init(
-                trp + i, LSUP_uri_new (sstr),
-                LSUP_uri_new (pstr), LSUP_uri_new (ostr));
+                trp + i, LSUP_iriref_new (sstr, NULL),
+                LSUP_iriref_new (pstr, NULL), LSUP_iriref_new (ostr, NULL));
     }
     LSUP_triple_init (trp + nt, NULL, NULL, NULL);
     log_info ("Triples generated.");
@@ -37,7 +35,10 @@ int main(int argc, char *argv[])
     // Clear out database from previous test.
     rm_r (getenv ("LSUP_MDB_STORE_PATH"));
 
-    if (LSUP_init() != LSUP_OK) abort();
+    if (LSUP_init() != LSUP_OK) {
+        log_fatal ("Failed to initialize LSUP environment.");
+        exit (-1);
+    }
 
     int rc;
     clock_t start, tc1, tc2, end;
@@ -52,14 +53,15 @@ int main(int argc, char *argv[])
     log_info ("Time elapsed: %lf s", wallclock);
 
     log_info ("Inserting triples.");
-    LSUP_Graph *gr = LSUP_graph_new (LSUP_STORE_MDB);
+    LSUP_Graph *gr = LSUP_graph_new (
+            LSUP_iriref_new (NULL, NULL), LSUP_STORE_MDB);
     if (!gr) {
         log_error ("Error creating graph!");
         return -1;
     }
 
     size_t ct;
-    rc = LSUP_graph_add_trp(gr, trp, &ct);
+    rc = LSUP_graph_add(gr, trp, &ct);
     if (rc != LSUP_OK) log_warn ("Graph loading interrupted: %d.", rc);
     else log_info ("Graph populated with %lu triples.", ct);
 
@@ -78,9 +80,9 @@ int main(int argc, char *argv[])
     log_info ("Lookup...");
     ct = 0;
     LSUP_Triple *spo = TRP_DUMMY;
-    LSUP_Term *s = LSUP_uri_new ("urn:s:8");
-    LSUP_Term *p = LSUP_uri_new ("urn:p:0");
-    LSUP_Term *o = LSUP_uri_new ("urn:o:300");
+    LSUP_Term *s = LSUP_iriref_new ("urn:s:8", NULL);
+    LSUP_Term *p = LSUP_iriref_new ("urn:p:0", NULL);
+    LSUP_Term *o = LSUP_iriref_new ("urn:o:300", NULL);
     LSUP_GraphIterator *it = LSUP_graph_lookup(gr, s, NULL, NULL, &ct);
     log_info ("Found triples by count: %lu", ct);
     ct = 0;