Better tdb tracing, start of decent replay_trace.
[ccan] / ccan / tdb / traverse.c
index 6397930b469da5385663cee6987b2568af5d0a03..3159b014a22283f71ebbdb5978d5a7322839805a 100644 (file)
@@ -169,10 +169,7 @@ static int tdb_traverse_internal(struct tdb_context *tdb,
                dbuf.dptr = key.dptr + rec.key_len;
                dbuf.dsize = rec.data_len;
 
-               tdb_trace(tdb, "traverse ");
-               tdb_trace_record(tdb, key);
-               tdb_trace_record(tdb, dbuf);
-               tdb_trace(tdb, "\n");
+               tdb_trace_1rec_retrec(tdb, "traverse", key, dbuf);
 
                /* Drop chain lock, call out */
                if (tdb_unlock(tdb, tl->hash, tl->lock_rw) != 0) {
@@ -182,7 +179,7 @@ static int tdb_traverse_internal(struct tdb_context *tdb,
                }
                if (fn && fn(tdb, key, dbuf, private_data)) {
                        /* They want us to terminate traversal */
-                       tdb_trace(tdb, "tdb_traverse_end = %i\n", count);
+                       tdb_trace_ret(tdb, "tdb_traverse_end", count);
                        ret = count;
                        if (tdb_unlock_record(tdb, tl->off) != 0) {
                                TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_traverse: unlock_record failed!\n"));;
@@ -193,7 +190,7 @@ static int tdb_traverse_internal(struct tdb_context *tdb,
                }
                SAFE_FREE(key.dptr);
        }
-       tdb_trace(tdb, "tdb_traverse_end\n");
+       tdb_trace(tdb, "tdb_traverse_end");
 out:
        tdb->travlocks.next = tl->next;
        if (ret < 0)
@@ -219,7 +216,7 @@ int tdb_traverse_read(struct tdb_context *tdb,
        }
 
        tdb->traverse_read++;
-       tdb_trace(tdb, "tdb_traverse_read_start\n");
+       tdb_trace(tdb, "tdb_traverse_read_start");
        ret = tdb_traverse_internal(tdb, fn, private_data, &tl);
        tdb->traverse_read--;
 
@@ -253,7 +250,7 @@ int tdb_traverse(struct tdb_context *tdb,
        }
 
        tdb->traverse_write++;
-       tdb_trace(tdb, "tdb_traverse_start\n");
+       tdb_trace(tdb, "tdb_traverse_start");
        ret = tdb_traverse_internal(tdb, fn, private_data, &tl);
        tdb->traverse_write--;
 
@@ -279,16 +276,14 @@ TDB_DATA tdb_firstkey(struct tdb_context *tdb)
 
        /* Grab first record: locks chain and returned record. */
        if (tdb_next_lock(tdb, &tdb->travlocks, &rec) <= 0) {
-               tdb_trace(tdb, "tdb_firstkey = ENOENT\n");
+               tdb_trace_retrec(tdb, "tdb_firstkey", tdb_null);
                return tdb_null;
        }
        /* now read the key */
        key.dsize = rec.key_len;
        key.dptr =tdb_alloc_read(tdb,tdb->travlocks.off+sizeof(rec),key.dsize);
 
-       tdb_trace(tdb, "tdb_firstkey = ");
-       tdb_trace_record(tdb, key);
-       tdb_trace(tdb, "\n");
+       tdb_trace_retrec(tdb, "tdb_firstkey", key);
 
        /* Unlock the hash chain of the record we just read. */
        if (tdb_unlock(tdb, tdb->travlocks.hash, tdb->travlocks.lock_rw) != 0)
@@ -314,9 +309,8 @@ TDB_DATA tdb_nextkey(struct tdb_context *tdb, TDB_DATA oldkey)
                    || memcmp(k, oldkey.dptr, oldkey.dsize) != 0) {
                        /* No, it wasn't: unlock it and start from scratch */
                        if (tdb_unlock_record(tdb, tdb->travlocks.off) != 0) {
-                               tdb_trace(tdb, "tdb_nextkey ");
-                               tdb_trace_record(tdb, oldkey);
-                               tdb_trace(tdb, "= ENOENT\n");
+                               tdb_trace_1rec_retrec(tdb, "tdb_nextkey",
+                                                     oldkey, tdb_null);
                                SAFE_FREE(k);
                                return tdb_null;
                        }
@@ -334,9 +328,7 @@ TDB_DATA tdb_nextkey(struct tdb_context *tdb, TDB_DATA oldkey)
                /* No previous element: do normal find, and lock record */
                tdb->travlocks.off = tdb_find_lock_hash(tdb, oldkey, tdb->hash_fn(&oldkey), tdb->travlocks.lock_rw, &rec);
                if (!tdb->travlocks.off) {
-                       tdb_trace(tdb, "tdb_nextkey ");
-                       tdb_trace_record(tdb, oldkey);
-                       tdb_trace(tdb, "= ENOENT\n");
+                       tdb_trace_1rec_retrec(tdb, "tdb_nextkey", oldkey, tdb_null);
                        return tdb_null;
                }
                tdb->travlocks.hash = BUCKET(rec.full_hash);
@@ -360,11 +352,7 @@ TDB_DATA tdb_nextkey(struct tdb_context *tdb, TDB_DATA oldkey)
        /* Unlock the chain of old record */
        if (tdb_unlock(tdb, BUCKET(oldhash), tdb->travlocks.lock_rw) != 0)
                TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_nextkey: WARNING tdb_unlock failed!\n"));
-       tdb_trace(tdb, "tdb_nextkey ");
-       tdb_trace_record(tdb, oldkey);
-       tdb_trace(tdb, "= ");
-       tdb_trace_record(tdb, key);
-       tdb_trace(tdb, "\n");
+       tdb_trace_1rec_retrec(tdb, "tdb_nextkey", oldkey, key);
        return key;
 }