diff options
author | Rusty Russell <rusty@rustcorp.com.au> | 2009-10-20 12:19:41 +1030 |
---|---|---|
committer | Rusty Russell <rusty@rustcorp.com.au> | 2009-10-22 00:00:12 +1030 |
commit | 703004340c3e0f43f741bd368d2525cfd187d590 (patch) | |
tree | 586695354ca782f374b2bcffc46a015e70a5fa79 /lib/tdb/common/open.c | |
parent | 1467e5eaab24b2b5c90ba0dd4e9dad4f321568c3 (diff) | |
download | samba-703004340c3e0f43f741bd368d2525cfd187d590.tar.gz samba-703004340c3e0f43f741bd368d2525cfd187d590.tar.bz2 samba-703004340c3e0f43f741bd368d2525cfd187d590.zip |
lib/tdb: TDB_TRACE support (for developers)
When TDB_TRACE is defined (in tdb_private.h), verbose tracing of tdb operations is enabled.
This can be replayed using "replay_trace" from http://ccan.ozlabs.org/info/tdb.
The majority of this patch comes from moving internal functions to _<funcname> to
avoid double-tracing. There should be no additional overhead for the normal (!TDB_TRACE)
case.
Note that the verbose traces compress really well with rzip.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Diffstat (limited to 'lib/tdb/common/open.c')
-rw-r--r-- | lib/tdb/common/open.c | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/lib/tdb/common/open.c b/lib/tdb/common/open.c index 141e6fe517..f0061d7b31 100644 --- a/lib/tdb/common/open.c +++ b/lib/tdb/common/open.c @@ -205,6 +205,10 @@ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int tdb_flags, TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_open_ex: tdb_new_database failed!")); goto fail; } +#ifdef TDB_TRACE + /* All tracing will fail. That's ok. */ + tdb->tracefd = -1; +#endif goto internal; } @@ -315,6 +319,22 @@ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int tdb_flags, goto fail; } +#ifdef TDB_TRACE + { + char tracefile[strlen(name) + 32]; + + snprintf(tracefile, sizeof(tracefile), + "%s.trace.%li", name, (long)getpid()); + tdb->tracefd = open(tracefile, O_WRONLY|O_CREAT|O_EXCL, 0600); + if (tdb->tracefd >= 0) { + tdb_enable_seqnum(tdb); + tdb_trace_open(tdb, "tdb_open", hash_size, tdb_flags, + open_flags); + } else + TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_open_ex: failed to open trace file %s!\n", tracefile)); + } +#endif + internal: /* Internal (memory-only) databases skip all the code above to * do with disk files, and resume here by releasing their @@ -330,7 +350,10 @@ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int tdb_flags, if (!tdb) return NULL; - + +#ifdef TDB_TRACE + close(tdb->tracefd); +#endif if (tdb->map_ptr) { if (tdb->flags & TDB_INTERNAL) SAFE_FREE(tdb->map_ptr); @@ -366,8 +389,9 @@ int tdb_close(struct tdb_context *tdb) struct tdb_context **i; int ret = 0; + tdb_trace(tdb, "tdb_close"); if (tdb->transaction) { - tdb_transaction_cancel(tdb); + _tdb_transaction_cancel(tdb); } if (tdb->map_ptr) { @@ -389,6 +413,9 @@ int tdb_close(struct tdb_context *tdb) } } +#ifdef TDB_TRACE + close(tdb->tracefd); +#endif memset(tdb, 0, sizeof(*tdb)); SAFE_FREE(tdb); |