]> mj.ucw.cz Git - libucw.git/commitdiff
Minor improvements of debug messages.
authorMartin Mares <mj@ucw.cz>
Sat, 10 Feb 2007 11:20:09 +0000 (12:20 +0100)
committerMartin Mares <mj@ucw.cz>
Sat, 10 Feb 2007 11:20:09 +0000 (12:20 +0100)
lib/sorter/govern.c
lib/sorter/sbuck.c

index 297692c5cde8a957029346870af78f5346ad924f..b6dea908ee3ebc0686bd53ad5f0f1a67982fdebd 100644 (file)
@@ -102,7 +102,7 @@ sorter_twoway(struct sort_context *ctx, struct sort_bucket *b)
 
   if (!(sorter_debug & SORT_DEBUG_NO_PRESORT) || (b->flags & SBF_CUSTOM_PRESORT))
     {
-      SORT_XTRACE(2, "%s", ((b->flags & SBF_CUSTOM_PRESORT) ? "Custom presorting" : "Presorting"));
+      SORT_XTRACE(3, "%s", ((b->flags & SBF_CUSTOM_PRESORT) ? "Custom presorting" : "Presorting"));
       sorter_start_timer(ctx);
       ins[0] = sbuck_new(ctx);
       if (!sorter_presort(ctx, b, ins[0], join ? : ins[0]))
@@ -132,7 +132,7 @@ sorter_twoway(struct sort_context *ctx, struct sort_bucket *b)
       ins[0] = b;
     }
 
-  SORT_XTRACE(2, "Main sorting");
+  SORT_XTRACE(3, "Main sorting");
   uns pass = 0;
   do {
     ++pass;
@@ -140,12 +140,14 @@ sorter_twoway(struct sort_context *ctx, struct sort_bucket *b)
     if (ins[0]->runs == 1 && ins[1]->runs == 1 && join)
       {
        // This is guaranteed to produce a single run, so join if possible
+       sh_off_t join_size = sbuck_size(join);
        outs[0] = join;
        outs[1] = NULL;
        ctx->twoway_merge(ctx, ins, outs);
-       ASSERT(outs[0]->runs == 2);
-       outs[0]->runs--;
-       SORT_TRACE("Mergesort pass %d (final run, %s, %dMB/s)", pass, F_BSIZE(outs[0]), sorter_speed(ctx, sbuck_size(outs[0])));
+       ASSERT(join->runs == 2);
+       join->runs--;
+       join_size = sbuck_size(join) - join_size;
+       SORT_TRACE("Mergesort pass %d (final run, %s, %dMB/s)", pass, F_SIZE(join_size), sorter_speed(ctx, join_size));
        sbuck_drop(ins[0]);
        sbuck_drop(ins[1]);
        return;
@@ -223,10 +225,10 @@ sorter_run(struct sort_context *ctx)
   else
     bin->fb = ctx->in_fb;
   bin->ident = "in";
-  bin->size = ctx->in_size;            /* Sizes should be either sh_off_t or u64, not both; beware of ~0U */
+  bin->size = ctx->in_size;            /* FIXME: Sizes should be either sh_off_t or u64, not both; beware of ~0U */
   bin->hash_bits = ctx->hash_bits;
   clist_add_tail(&ctx->bucket_list, &bin->n);
-  SORT_XTRACE(2, "Input size: %s", (ctx->in_size == ~(u64)0 ? (byte*)"unknown" : F_BSIZE(bin)));
+  SORT_XTRACE(2, "Input size: %s", F_BSIZE(bin));
 
   // Create bucket for the output
   struct sort_bucket *bout = sbuck_new(ctx);
@@ -240,6 +242,7 @@ sorter_run(struct sort_context *ctx)
   struct sort_bucket *b;
   while (bout = clist_head(&ctx->bucket_list), b = clist_next(&ctx->bucket_list, &bout->n))
     {
+      SORT_XTRACE(2, "Next block: %s, %d hash bits", F_BSIZE(b), b->hash_bits);
       if (!sbuck_have(b))
        sbuck_drop(b);
       else if (b->runs == 1)
index 53dfed3133c52c7a2fc0cb7a685f1684f08e3b1b..287827ee3359f5a08b4162afee5c0eced00ce09e 100644 (file)
@@ -144,7 +144,7 @@ sorter_alloc_buf(struct sort_context *ctx)
   ctx->big_buf_size = 2*bs;
   ctx->big_buf_half = ((byte*) ctx->big_buf) + bs;
   ctx->big_buf_half_size = bs;
-  SORT_XTRACE(2, "Allocated sorting buffer (%jd bytes)", (uintmax_t) bs);
+  SORT_XTRACE(2, "Allocated sorting buffer (2*%jd bytes)", (uintmax_t) bs);
 }
 
 void
@@ -170,6 +170,8 @@ format_size(byte *buf, u64 x)
     sprintf(buf, "%dM", (int)(x/(1<<20)));
   else if (x < (u64)10<<30)
     sprintf(buf, "%.1fG", (double)x/(1<<30));
-  else
+  else if (x != ~(u64)0)
     sprintf(buf, "%dG", (int)(x/(1<<30)));
+  else
+    strcpy(buf, "unknown");
 }