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.
This commit is contained in:
Russell Belfer
2014-05-02 09:21:33 -07:00
parent 225aab5d6a
commit b23b112dfe
10 changed files with 122 additions and 104 deletions
+19
View File
@@ -229,3 +229,22 @@ void diff_print_raw(FILE *fp, git_diff *diff)
git_diff_print(diff, GIT_DIFF_FORMAT_RAW,
git_diff_print_callback__to_file_handle, fp ? fp : stderr));
}
void diff_perf_track_stats(
git_trace_level_t level,
void *cb_payload,
void *msg_payload,
const char *msg)
{
diff_perf *data = cb_payload;
if (!(level & GIT_TRACE_PERF))
return;
if (!strcmp("stat", msg))
data->stat_calls += msg_payload ? *((size_t *)msg_payload) : 1;
else if (!strcmp("submodule_lookup", msg))
data->submodule_lookups++;
else if (!strcmp("oid_calculation", msg))
data->oid_calcs++;
}
+14
View File
@@ -62,3 +62,17 @@ extern int diff_foreach_via_iterator(
extern void diff_print(FILE *fp, git_diff *diff);
extern void diff_print_raw(FILE *fp, git_diff *diff);
#include "git2/trace.h"
typedef struct {
size_t stat_calls;
size_t oid_calcs;
size_t submodule_lookups;
} diff_perf;
extern void diff_perf_track_stats(
git_trace_level_t level,
void *cb_payload,
void *msg_payload,
const char *msg);
+4 -25
View File
@@ -1,40 +1,19 @@
#include "clar_libgit2.h"
#include "diff_helpers.h"
#include "repository.h"
#include <git2/trace.h>
static git_repository *g_repo = NULL;
#ifdef GIT_TRACE
static struct {
size_t stat_calls;
size_t oid_calcs;
size_t submodule_lookups;
} g_diff_perf;
static void add_stats(git_trace_level_t level, const char *msg)
{
const char *assign = strchr(msg, '=');
GIT_UNUSED(level);
if (!assign)
return;
if (!strncmp("stat", msg, (assign - msg)))
g_diff_perf.stat_calls += atoi(assign + 1);
else if (!strncmp("submodule_lookup", msg, (assign - msg)))
g_diff_perf.submodule_lookups += atoi(assign + 1);
else if (!strncmp("oid_calculation", msg, (assign - msg)))
g_diff_perf.oid_calcs += atoi(assign + 1);
}
static diff_perf g_diff_perf;
#endif
void test_diff_workdir__initialize(void)
{
#ifdef GIT_TRACE
memset(&g_diff_perf, 0, sizeof(g_diff_perf));
cl_git_pass(git_trace_set(GIT_TRACE_TRACE, add_stats));
cl_git_pass(git_trace_set(
GIT_TRACE_PERF, diff_perf_track_stats, &g_diff_perf));
#endif
}
@@ -42,7 +21,7 @@ void test_diff_workdir__cleanup(void)
{
cl_git_sandbox_cleanup();
#ifdef GIT_TRACE
cl_git_pass(git_trace_set(0, NULL));
cl_git_pass(git_trace_set(GIT_TRACE_NONE, NULL, NULL));
#endif
}