summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2014-04-29 15:05:58 -0700
committerRussell Belfer <rb@github.com>2014-05-02 09:21:33 -0700
commit9c8ed4999740e921ecc2966bbcd0dbcfc725f59a (patch)
treecf801e2026c9fca6b4e28bfc2c35e981d9ccea6e /src
parent7a2e56a3f6115c3a145e4f73d0aa8bea6dded899 (diff)
downloadlibgit2-9c8ed4999740e921ecc2966bbcd0dbcfc725f59a.tar.gz
Remove trace / add git_diff_perfdata struct + api
Diffstat (limited to 'src')
-rw-r--r--src/diff.c76
-rw-r--r--src/diff.h2
-rw-r--r--src/iterator.c5
-rw-r--r--src/iterator.h1
-rw-r--r--src/status.c36
-rw-r--r--src/trace.c15
-rw-r--r--src/trace.h19
7 files changed, 88 insertions, 66 deletions
diff --git a/src/diff.c b/src/diff.c
index b34d15312..26e671dce 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -14,7 +14,6 @@
#include "index.h"
#include "odb.h"
#include "submodule.h"
-#include "trace.h"
#define DIFF_FLAG_IS_SET(DIFF,FLAG) (((DIFF)->opts.flags & (FLAG)) != 0)
#define DIFF_FLAG_ISNT_SET(DIFF,FLAG) (((DIFF)->opts.flags & (FLAG)) == 0)
@@ -555,7 +554,8 @@ int git_diff__oid_for_entry(
if (!entry.mode) {
struct stat st;
- git_trace(GIT_TRACE_PERF, NULL, "stat");
+ diff->perf.stat_calls++;
+
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,6 @@ int git_diff__oid_for_entry(
if (S_ISGITLINK(entry.mode)) {
git_submodule *sm;
- 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,8 +582,8 @@ int git_diff__oid_for_entry(
giterr_clear();
}
} else if (S_ISLNK(entry.mode)) {
- git_trace(GIT_TRACE_PERF, NULL, "oid_calculation");
error = git_odb__hashlink(out, full_path.ptr);
+ diff->perf.oid_calculations++;
} else if (!git__is_sizet(entry.file_size)) {
giterr_set(GITERR_OS, "File size overflow (for 32-bits) on '%s'",
entry.path);
@@ -596,10 +595,10 @@ int git_diff__oid_for_entry(
if (fd < 0)
error = fd;
else {
- 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);
+ diff->perf.oid_calculations++;
}
git_filter_list_free(fl);
@@ -655,8 +654,6 @@ static int maybe_modified_submodule(
ign == GIT_SUBMODULE_IGNORE_ALL)
return 0;
- git_trace(GIT_TRACE_PERF, NULL, "submodule_lookup");
-
if ((error = git_submodule_lookup(
&sub, diff->repo, info->nitem->path)) < 0) {
@@ -965,8 +962,6 @@ static int handle_unmatched_new_item(
delta_type = GIT_DELTA_ADDED;
else if (nitem->mode == GIT_FILEMODE_COMMIT) {
- 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) {
giterr_clear();
@@ -1119,6 +1114,8 @@ int git_diff__from_iterators(
error = 0;
}
+ diff->perf.stat_calls += old_iter->stat_calls + new_iter->stat_calls;
+
cleanup:
if (!error)
*diff_ptr = diff;
@@ -1313,6 +1310,22 @@ int git_diff_is_sorted_icase(const git_diff *diff)
return (diff->opts.flags & GIT_DIFF_IGNORE_CASE) != 0;
}
+static int diff_options_bad_version(int version, const char *thing)
+{
+ giterr_set(GITERR_INVALID, "Invalid version %d for %s", version, thing);
+ return -1;
+}
+
+int git_diff_get_perfdata(git_diff_perfdata *out, const git_diff *diff)
+{
+ if (!out || out->version != GIT_DIFF_PERFDATA_VERSION)
+ return diff_options_bad_version(
+ out ? out->version : 0, "git_diff_perfdata");
+ out->stat_calls = diff->perf.stat_calls;
+ out->oid_calculations = diff->perf.oid_calculations;
+ return 0;
+}
+
int git_diff__paired_foreach(
git_diff *head2idx,
git_diff *idx2wd,
@@ -1615,38 +1628,29 @@ int git_diff_commit_as_email(
return error;
}
-int git_diff_init_options(git_diff_options* opts, int version)
+int git_diff_init_options(git_diff_options* opts, unsigned int version)
{
- if (version != GIT_DIFF_OPTIONS_VERSION) {
- giterr_set(GITERR_INVALID, "Invalid version %d for git_diff_options", version);
- return -1;
- } else {
- git_diff_options o = GIT_DIFF_OPTIONS_INIT;
- memcpy(opts, &o, sizeof(o));
- return 0;
- }
+ git_diff_options o = GIT_DIFF_OPTIONS_INIT;
+ if (version != o.version)
+ return diff_options_bad_version(version, "git_diff_options");
+ memcpy(opts, &o, sizeof(o));
+ return 0;
}
-int git_diff_find_init_options(git_diff_find_options* opts, int version)
+int git_diff_find_init_options(git_diff_find_options* opts, unsigned int version)
{
- if (version != GIT_DIFF_FIND_OPTIONS_VERSION) {
- giterr_set(GITERR_INVALID, "Invalid version %d for git_diff_find_options", version);
- return -1;
- } else {
- git_diff_find_options o = GIT_DIFF_FIND_OPTIONS_INIT;
- memcpy(opts, &o, sizeof(o));
- return 0;
- }
+ git_diff_find_options o = GIT_DIFF_FIND_OPTIONS_INIT;
+ if (version != o.version)
+ return diff_options_bad_version(version, "git_diff_find_options");
+ memcpy(opts, &o, sizeof(o));
+ return 0;
}
-int git_diff_format_email_init_options(git_diff_format_email_options* opts, int version)
+int git_diff_format_email_init_options(git_diff_format_email_options* opts, unsigned int version)
{
- if (version != GIT_DIFF_FORMAT_EMAIL_OPTIONS_VERSION) {
- giterr_set(GITERR_INVALID, "Invalid version %d for git_diff_format_email_options", version);
- return -1;
- } else {
- git_diff_format_email_options o = GIT_DIFF_FORMAT_EMAIL_OPTIONS_INIT;
- memcpy(opts, &o, sizeof(o));
- return 0;
- }
+ git_diff_format_email_options o = GIT_DIFF_FORMAT_EMAIL_OPTIONS_INIT;
+ if (version != o.version)
+ return diff_options_bad_version(version, "git_diff_format_email_options");
+ memcpy(opts, &o, sizeof(o));
+ return 0;
}
diff --git a/src/diff.h b/src/diff.h
index 2e7ce0b7d..3305238d0 100644
--- a/src/diff.h
+++ b/src/diff.h
@@ -8,6 +8,7 @@
#define INCLUDE_diff_h__
#include "git2/diff.h"
+#include "git2/sys/diff.h"
#include "git2/oid.h"
#include <stdio.h>
@@ -62,6 +63,7 @@ struct git_diff {
git_iterator_type_t old_src;
git_iterator_type_t new_src;
uint32_t diffcaps;
+ git_diff_perfdata perf;
int (*strcomp)(const char *, const char *);
int (*strncomp)(const char *, const char *, size_t);
diff --git a/src/iterator.c b/src/iterator.c
index 0d7e5918d..4f8087c8d 100644
--- a/src/iterator.c
+++ b/src/iterator.c
@@ -11,7 +11,6 @@
#include "ignore.h"
#include "buffer.h"
#include "submodule.h"
-#include "trace.h"
#include <ctype.h>
#define ITERATOR_SET_CB(P,NAME_LC) do { \
@@ -1017,8 +1016,7 @@ static int fs_iterator__expand_dir(fs_iterator *fi)
fs_iterator__free_frame(ff);
return GIT_ENOTFOUND;
}
-
- git_trace(GIT_TRACE_PERF, &ff->entries.length, "stat");
+ fi->base.stat_calls += ff->entries.length;
fs_iterator__seek_frame_start(fi, ff);
@@ -1310,7 +1308,6 @@ 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_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/iterator.h b/src/iterator.h
index ba9c1e486..f67830212 100644
--- a/src/iterator.h
+++ b/src/iterator.h
@@ -52,6 +52,7 @@ struct git_iterator {
char *start;
char *end;
int (*prefixcomp)(const char *str, const char *prefix);
+ size_t stat_calls;
unsigned int flags;
};
diff --git a/src/status.c b/src/status.c
index e418cf7b6..aab838bcf 100644
--- a/src/status.c
+++ b/src/status.c
@@ -518,14 +518,38 @@ int git_status_should_ignore(
return git_ignore_path_is_ignored(ignored, repo, path);
}
-int git_status_init_options(git_status_options* opts, int version)
+int git_status_init_options(git_status_options* opts, unsigned int version)
{
- if (version != GIT_STATUS_OPTIONS_VERSION) {
+ git_status_options o = GIT_STATUS_OPTIONS_INIT;
+ if (version != o.version) {
giterr_set(GITERR_INVALID, "Invalid version %d for git_status_options", version);
return -1;
- } else {
- git_status_options o = GIT_STATUS_OPTIONS_INIT;
- memcpy(opts, &o, sizeof(o));
- return 0;
}
+ memcpy(opts, &o, sizeof(o));
+ return 0;
+}
+
+int git_status_list_get_perfdata(
+ git_diff_perfdata *out, const git_status_list *status)
+{
+ if (!out || out->version != GIT_DIFF_PERFDATA_VERSION) {
+ giterr_set(GITERR_INVALID, "Invalid version %d for git_diff_perfdata",
+ out ? out->version : 0);
+ return -1;
+ }
+
+ out->stat_calls = 0;
+ out->oid_calculations = 0;
+
+ if (status->head2idx) {
+ out->stat_calls += status->head2idx->perf.stat_calls;
+ out->oid_calculations += status->head2idx->perf.oid_calculations;
+ }
+ if (status->idx2wd) {
+ out->stat_calls += status->idx2wd->perf.stat_calls;
+ out->oid_calculations += status->idx2wd->perf.oid_calculations;
+ }
+
+ return 0;
}
+
diff --git a/src/trace.c b/src/trace.c
index 6ee2cf2ce..ee5039f56 100644
--- a/src/trace.c
+++ b/src/trace.c
@@ -17,25 +17,22 @@ struct git_trace_data git_trace__data = {0};
#endif
-int git_trace_set(
- git_trace_level_t level, git_trace_callback cb, void *cb_payload)
+int git_trace_set(git_trace_level_t level, git_trace_callback callback)
{
#ifdef GIT_TRACE
- assert(level == 0 || cb != NULL);
+ assert(level == 0 || callback != NULL);
git_trace__data.level = level;
- git_trace__data.callback = cb;
- git_trace__data.callback_payload = cb_payload;
+ git_trace__data.callback = callback;
GIT_MEMORY_BARRIER;
return 0;
#else
GIT_UNUSED(level);
- GIT_UNUSED(cb);
- GIT_UNUSED(cb_payload);
+ GIT_UNUSED(callback);
- 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 b35e3808f..4d4e3bf53 100644
--- a/src/trace.h
+++ b/src/trace.h
@@ -15,16 +15,13 @@
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,
- void *message_payload,
- const char *fmt,
- ...)
+ const char *fmt, ...)
{
git_trace_callback callback = git_trace__data.callback;
git_buf message = GIT_BUF_INIT;
@@ -34,18 +31,18 @@ GIT_INLINE(void) git_trace__write_fmt(
git_buf_vprintf(&message, fmt, ap);
va_end(ap);
- callback(
- level, git_trace__data.callback_payload, message_payload,
- git_buf_cstr(&message));
+ callback(level, git_buf_cstr(&message));
git_buf_free(&message);
}
#define git_trace_level() (git_trace__data.level)
-#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)
+#define git_trace(l, ...) { \
+ if (git_trace__data.level >= l && \
+ git_trace__data.callback != NULL) { \
+ git_trace__write_fmt(l, __VA_ARGS__); \
+ } \
+ }
#else