]> git.ipfire.org Git - location/libloc.git/commitdiff
Log how long it takes to open the database
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 12 Dec 2017 17:02:46 +0000 (17:02 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 12 Dec 2017 17:02:46 +0000 (17:02 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/database.c
src/database.h

index e5460da3bb25bc5b49f1d2af9fc8f1f3985d7cf6..1512fd2a1fdfceed67a35679fb7290bf0b5bf4d5 100644 (file)
@@ -156,6 +156,27 @@ static FILE* copy_file_pointer(FILE* f) {
        return fdopen(fd, "r");
 }
 
+static int loc_database_read(struct loc_database* db) {
+       clock_t start = clock();
+
+       // Read magic bytes
+       int r = loc_database_read_magic(db);
+       if (r)
+               return r;
+
+       // Read the header
+       r = loc_database_read_header(db);
+       if (r)
+               return r;
+
+       clock_t end = clock();
+
+       INFO(db->ctx, "Opened database in %.8fs\n",
+               (double)(end - start) / CLOCKS_PER_SEC);
+
+       return 0;
+}
+
 LOC_EXPORT int loc_database_new(struct loc_ctx* ctx, struct loc_database** database, FILE* f) {
        struct loc_database* db = calloc(1, sizeof(*db));
        if (!db)
@@ -173,15 +194,11 @@ LOC_EXPORT int loc_database_new(struct loc_ctx* ctx, struct loc_database** datab
        if (!db->file)
                goto FAIL;
 
-       // Read magic bytes
-       int r = loc_database_read_magic(db);
-       if (r)
-               return r;
-
-       // Read the header
-       r = loc_database_read_header(db);
-       if (r)
+       int r = loc_database_read(db);
+       if (r) {
+               loc_database_unref(db);
                return r;
+       }
 
        *database = db;
 
index bec2f41bd5e7bd985a9a07ee2a10ee5607fa1c25..38dc4efd5eb9c58ee5a0d16394019d9f3eb936c7 100644 (file)
@@ -36,7 +36,6 @@ const char* loc_database_get_description(struct loc_database* db);
 int loc_database_get_as(struct loc_database* db, struct loc_as** as, uint32_t number);
 size_t loc_database_count_as(struct loc_database* db);
 
-int loc_database_read(struct loc_database* db, FILE* f);
 int loc_database_write(struct loc_database* db, FILE* f);
 
 #endif