]> mj.ucw.cz Git - libucw.git/commitdiff
Libucw: Cleaned up logging in fb-atomic.
authorMartin Mares <mj@ucw.cz>
Sun, 27 Jul 2008 15:38:14 +0000 (17:38 +0200)
committerMartin Mares <mj@ucw.cz>
Sun, 27 Jul 2008 15:38:14 +0000 (17:38 +0200)
Original patch by Michal, slightly changed by me.

ucw/Makefile
ucw/fb-atomic.c
ucw/fb-atomic.t

index e2574f832da937a1e561963df8e06b30ad855ed4..bd513a551ebefd0e28d3855a4b995d913e48321d 100644 (file)
@@ -117,6 +117,7 @@ $(o)/ucw/redblack-test.test: $(o)/ucw/redblack-test
 $(o)/ucw/basecode.test: $(o)/ucw/basecode
 $(addprefix $(o)/ucw/fb-,file.test grow.test pool.test socket.test atomic.test \
        limfd.test temp.test mem.test buffer.test mmap.test): %.test: %-t
+$(o)/ucw/fb-atomic-tt.o: CFLAGS += -DFB_ATOMIC_TRACE
 $(o)/ucw/url.test: $(o)/ucw/url-t
 
 ifdef CONFIG_UCW_THREADS
index bc350f636944a1486d09875060fe26800e128e13..5eca3905770afb4a62be08b3d8739665a500d515 100644 (file)
  *             or -(expected maximum record length) for variable-sized ones.
  */
 
-#define LOCAL_DEBUG
-
 #include "ucw/lib.h"
 #include "ucw/fastbuf.h"
 #include "ucw/lfs.h"
+#include "ucw/conf.h"
 
 #include <string.h>
 #include <fcntl.h>
 #include <unistd.h>
 
+static uns trace;
+
+static struct cf_section fbatomic_config = {
+  CF_ITEMS {
+    CF_UNS("Trace", &trace)
+  }
+};
+
+static void CONSTRUCTOR fbatomic_init_config(void)
+{
+  cf_declare_section("FBAtomic", &fbatomic_config, 1);
+}
+
+#define TRACE(m...) do { if(trace) msg(L_DEBUG, "FB_ATOMIC: " m); } while(0)
+
 struct fb_atomic_file {
   int fd;
   int use_count;
@@ -79,7 +93,7 @@ fbatomic_spout(struct fastbuf *f)
       uns written = f->bptr - f->buffer;
       uns size = f->bufend - f->buffer + F->slack_size;
       F->slack_size *= 2;
-      DBG("Reallocating buffer for atomic file %s with slack %d", f->name, F->slack_size);
+      TRACE("Reallocating buffer for atomic file %s with slack %d", f->name, F->slack_size);
       f->buffer = xrealloc(f->buffer, size);
       f->bufend = f->buffer + size;
       f->bptr = f->buffer + written;
@@ -145,6 +159,9 @@ int main(int argc UNUSED, char **argv UNUSED)
 {
   struct fastbuf *f, *g;
 
+  // Always trace in the test
+  trace = 1;
+
   msg(L_INFO, "Testing block writes");
   f = fbatomic_open("test", NULL, 16, 4);
   for (u32 i=0; i<17; i++)
index be70c63b3582647629b312b6645f25358e8a7329..6db6c06a8685328c097d9e77ccb1cd0d04626612 100644 (file)
@@ -3,5 +3,5 @@
 Run:   ../obj/ucw/fb-atomic-t 2>&1 | sed -e 's/^\(.\) [^ ]* [^ ]* /\1 /'
 Out:   I Testing block writes
        I Testing interleaved var-size writes
-       D Reallocating buffer for atomic file test2 with slack 10
-       D Reallocating buffer for atomic file test2 with slack 10
+       D FB_ATOMIC: Reallocating buffer for atomic file test2 with slack 10
+       D FB_ATOMIC: Reallocating buffer for atomic file test2 with slack 10