Pretty statistics
authorArt Cancro <ajc@citadel.org>
Fri, 14 Jul 2023 23:58:27 +0000 (14:58 -0900)
committerArt Cancro <ajc@citadel.org>
Fri, 14 Jul 2023 23:58:27 +0000 (14:58 -0900)
citadel/utils/ctdlload.c

index bf6c55f420f14804858a97ee5f6e3bdc42f96b52..6ddf69c22a5752978b115f40a759e1727f56c6cb 100644 (file)
@@ -50,15 +50,6 @@ DB_ENV *open_dbenv(char *dirname) {
        u_int32_t flags = 0;
        int dbversion_major, dbversion_minor, dbversion_patch;
 
-       fprintf(stderr, "db: open_dbenv() starting\n"
-               "db:    Linked zlib: %s\n"
-               "db: Compiled libdb: %s\n"
-               "db:   Linked libdb: %s\n",
-               zlibVersion(),
-               DB_VERSION_STRING,
-               db_version(&dbversion_major, &dbversion_minor, &dbversion_patch)
-       );
-
        // Create synthetic integer version numbers and compare them.
        // Never run with a libdb older than the one with which it was compiled.
        int compiled_db_version = ( (DB_VERSION_MAJOR * 1000000) + (DB_VERSION_MINOR * 1000) + (DB_VERSION_PATCH) );
@@ -69,7 +60,6 @@ DB_ENV *open_dbenv(char *dirname) {
                exit(CTDLEXIT_DB);
        }
 
-       fprintf(stderr,"db: Setting up DB environment\n");
        ret = db_env_create(&dbenv, 0);
        if (ret) {
                fprintf(stderr,"db: db_env_create: %s\n", db_strerror(ret));
@@ -94,7 +84,6 @@ DB_ENV *open_dbenv(char *dirname) {
        }
 
        flags = DB_CREATE | DB_INIT_MPOOL | DB_PRIVATE | DB_INIT_LOG;
-       fprintf(stderr,"db: dbenv open(dir=%s, flags=%d)\n", dirname, flags);
        ret = dbenv->open(dbenv, dirname, flags, 0);
        if (ret) {
                fprintf(stderr,"db: dbenv->open: %s\n", db_strerror(ret));
@@ -108,7 +97,6 @@ DB_ENV *open_dbenv(char *dirname) {
 
 
 void close_dbenv(DB_ENV *dbenv) {
-       fprintf(stderr,"db: closing dbenv\n");
        int ret = dbenv->close(dbenv, 0);
        if (ret) {
                fprintf(stderr,"db: dbenv->close: %s\n", db_strerror(ret));
@@ -240,6 +228,8 @@ int convert_user(char *line, DBT *out_key, DBT *out_data) {
 // Ingest one line of dump data.  NOT REENTRANT
 void ingest_one(char *line, DB_ENV *dst_dbenv) {
 
+       static int good_rows = 0;
+       static int bad_rows = 0;
        static int previous_cdb = -1 ;
        static int current_cdb = -1 ;
        static DB *dst_dbp;
@@ -276,8 +266,13 @@ void ingest_one(char *line, DB_ENV *dst_dbenv) {
                                fprintf(stderr, "db: db_close: %s\n", db_strerror(ret));
                        }
                }
+               if (previous_cdb > 0) {
+                       fprintf(stderr, "\n");
+               }
 
                if (current_cdb >= 0) {
+                       good_rows = 0;
+                       bad_rows = 0;
                        snprintf(dbfilename, sizeof dbfilename, "cdb.%02x", current_cdb);
 
                        // create a database handle for the destination table
@@ -320,15 +315,24 @@ void ingest_one(char *line, DB_ENV *dst_dbenv) {
        else                                                    row_was_good = 0;
 
        if (row_was_good) {
+               ++good_rows;
                ret = dst_dbp->put(dst_dbp, NULL, &out_key, &out_data, 0);
                if (ret) {
-                       fprintf(stderr, "db: cdb_put(%d): %s", current_cdb, db_strerror(ret));
+                       fprintf(stderr, "db: cdb_put(%x): %s", current_cdb, db_strerror(ret));
                        exit(CTDLEXIT_DB);
                }
        }
+       else {
+               ++bad_rows;
+       }
 
        free(out_key.data);
        free(out_data.data);
+
+       if (current_cdb > 0) {
+               fprintf(stderr, "   %02x %9d %8d\r", current_cdb, good_rows, bad_rows);
+               fflush(stderr);
+       }
 }
 
 
@@ -339,6 +343,8 @@ void ingest(DB_ENV *dst_dbenv) {
        static size_t line_len = 0;
        char ch;
 
+       fprintf(stderr, "table good_rows bad_rows\n");
+       fprintf(stderr, "----- --------- --------\n");
        line = reallok(NULL, line_alloc);
 
        do {