summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2014-04-29 11:29:49 -0700
committerRussell Belfer <rb@github.com>2014-05-02 09:21:33 -0700
commitb23b112dfe8eceb39eaaea2d5e60d971c4371aa0 (patch)
tree56a6c981856e5f1bf830c3b647a8a58838b044f5 /src
parent225aab5d6a611076b22f00ae5a28184d92b5259c (diff)
downloadlibgit2-b23b112dfe8eceb39eaaea2d5e60d971c4371aa0.tar.gz
Add payloads, bitmaps to trace API
This is a proposed adjustment to the trace APIs. This makes the trace levels into a bitmask so that they can be selectively enabled and adds a callback-level payload, plus a message-level payload. This makes it easier for me to a GIT_TRACE_PERF callbacks that are simply bypassed if the PERF level is not set.
Diffstat (limited to 'src')
-rw-r--r--src/diff.c12
-rw-r--r--src/iterator.c4
-rw-r--r--src/trace.c15
-rw-r--r--src/trace.h19
4 files changed, 28 insertions, 22 deletions
diff --git a/src/diff.c b/src/diff.c
index 8b7433c62..5a6b127a1 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -555,7 +555,7 @@ int git_diff__oid_for_entry(
if (!entry.mode) {
struct stat st;
- git_trace(GIT_TRACE_TRACE, "stat=1");
+ git_trace(GIT_TRACE_PERF, NULL, "stat");
if (p_stat(full_path.ptr, &st) < 0) {
error = git_path_set_error(errno, entry.path, "stat");
git_buf_free(&full_path);
@@ -570,7 +570,7 @@ int git_diff__oid_for_entry(
if (S_ISGITLINK(entry.mode)) {
git_submodule *sm;
- git_trace(GIT_TRACE_TRACE, "submodule_lookup=1");
+ git_trace(GIT_TRACE_PERF, NULL, "submodule_lookup");
if (!git_submodule_lookup(&sm, diff->repo, entry.path)) {
const git_oid *sm_oid = git_submodule_wd_id(sm);
if (sm_oid)
@@ -583,7 +583,7 @@ int git_diff__oid_for_entry(
giterr_clear();
}
} else if (S_ISLNK(entry.mode)) {
- git_trace(GIT_TRACE_TRACE, "oid_calculation=1");
+ git_trace(GIT_TRACE_PERF, NULL, "oid_calculation");
error = git_odb__hashlink(out, full_path.ptr);
} else if (!git__is_sizet(entry.file_size)) {
giterr_set(GITERR_OS, "File size overflow (for 32-bits) on '%s'",
@@ -596,7 +596,7 @@ int git_diff__oid_for_entry(
if (fd < 0)
error = fd;
else {
- git_trace(GIT_TRACE_TRACE, "oid_calculation=1");
+ git_trace(GIT_TRACE_PERF, NULL, "oid_calculation");
error = git_odb__hashfd_filtered(
out, fd, (size_t)entry.file_size, GIT_OBJ_BLOB, fl);
p_close(fd);
@@ -655,7 +655,7 @@ static int maybe_modified_submodule(
ign == GIT_SUBMODULE_IGNORE_ALL)
return 0;
- git_trace(GIT_TRACE_TRACE, "submodule_lookup=1");
+ git_trace(GIT_TRACE_PERF, NULL, "submodule_lookup");
if ((error = git_submodule_lookup(
&sub, diff->repo, info->nitem->path)) < 0) {
@@ -965,7 +965,7 @@ static int handle_unmatched_new_item(
delta_type = GIT_DELTA_ADDED;
else if (nitem->mode == GIT_FILEMODE_COMMIT) {
- git_trace(GIT_TRACE_TRACE, "submodule_lookup=1");
+ git_trace(GIT_TRACE_PERF, NULL, "submodule_lookup");
/* ignore things that are not actual submodules */
if (git_submodule_lookup(NULL, info->repo, nitem->path) != 0) {
diff --git a/src/iterator.c b/src/iterator.c
index bebdeba84..0d7e5918d 100644
--- a/src/iterator.c
+++ b/src/iterator.c
@@ -1018,7 +1018,7 @@ static int fs_iterator__expand_dir(fs_iterator *fi)
return GIT_ENOTFOUND;
}
- git_trace(GIT_TRACE_TRACE, "stat=%ld", (long)ff->entries.length);
+ git_trace(GIT_TRACE_PERF, &ff->entries.length, "stat");
fs_iterator__seek_frame_start(fi, ff);
@@ -1310,7 +1310,7 @@ static int workdir_iterator__enter_dir(fs_iterator *fi)
if (!S_ISDIR(entry->st.st_mode) || !strcmp(GIT_DIR, entry->path))
continue;
- git_trace(GIT_TRACE_TRACE, "submodule_lookup=1");
+ git_trace(GIT_TRACE_PERF, entry->path, "submodule_lookup");
if (git_submodule__is_submodule(fi->base.repo, entry->path)) {
entry->st.st_mode = GIT_FILEMODE_COMMIT;
entry->path_len--;
diff --git a/src/trace.c b/src/trace.c
index ee5039f56..6ee2cf2ce 100644
--- a/src/trace.c
+++ b/src/trace.c
@@ -17,22 +17,25 @@ struct git_trace_data git_trace__data = {0};
#endif
-int git_trace_set(git_trace_level_t level, git_trace_callback callback)
+int git_trace_set(
+ git_trace_level_t level, git_trace_callback cb, void *cb_payload)
{
#ifdef GIT_TRACE
- assert(level == 0 || callback != NULL);
+ assert(level == 0 || cb != NULL);
git_trace__data.level = level;
- git_trace__data.callback = callback;
+ git_trace__data.callback = cb;
+ git_trace__data.callback_payload = cb_payload;
GIT_MEMORY_BARRIER;
return 0;
#else
GIT_UNUSED(level);
- GIT_UNUSED(callback);
+ GIT_UNUSED(cb);
+ GIT_UNUSED(cb_payload);
- giterr_set(GITERR_INVALID,
- "This version of libgit2 was not built with tracing.");
+ giterr_set(
+ GITERR_INVALID, "This version of libgit2 was not built with tracing.");
return -1;
#endif
}
diff --git a/src/trace.h b/src/trace.h
index 4d4e3bf53..b35e3808f 100644
--- a/src/trace.h
+++ b/src/trace.h
@@ -15,13 +15,16 @@
struct git_trace_data {
git_trace_level_t level;
git_trace_callback callback;
+ void *callback_payload;
};
extern struct git_trace_data git_trace__data;
GIT_INLINE(void) git_trace__write_fmt(
git_trace_level_t level,
- const char *fmt, ...)
+ void *message_payload,
+ const char *fmt,
+ ...)
{
git_trace_callback callback = git_trace__data.callback;
git_buf message = GIT_BUF_INIT;
@@ -31,18 +34,18 @@ GIT_INLINE(void) git_trace__write_fmt(
git_buf_vprintf(&message, fmt, ap);
va_end(ap);
- callback(level, git_buf_cstr(&message));
+ callback(
+ level, git_trace__data.callback_payload, message_payload,
+ git_buf_cstr(&message));
git_buf_free(&message);
}
#define git_trace_level() (git_trace__data.level)
-#define git_trace(l, ...) { \
- if (git_trace__data.level >= l && \
- git_trace__data.callback != NULL) { \
- git_trace__write_fmt(l, __VA_ARGS__); \
- } \
- }
+#define git_trace(l, p, ...) do { \
+ if ((git_trace__data.level & (l)) != 0 && git_trace__data.callback) { \
+ git_trace__write_fmt((l), (p), __VA_ARGS__); \
+ } } while (0)
#else