Skip to content

apply unpack-trees and cache tree optimizations for testing and perf runs #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cache-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,9 @@ int cache_tree_update(struct index_state *istate, int flags)

if (i)
return i;
trace_performance_enter();
i = update_one(it, cache, entries, "", 0, &skip, flags);
trace_performance_leave("cache_tree_update");
if (i < 0)
return i;
istate->cache_changed |= CACHE_TREE_CHANGED;
Expand Down
4 changes: 2 additions & 2 deletions diff-lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -514,8 +514,8 @@ static int diff_cache(struct rev_info *revs,
int run_diff_index(struct rev_info *revs, int cached)
{
struct object_array_entry *ent;
uint64_t start = getnanotime();

trace_performance_enter();
ent = revs->pending.objects;
if (diff_cache(revs, &ent->item->oid, ent->name, cached))
exit(128);
Expand All @@ -524,7 +524,7 @@ int run_diff_index(struct rev_info *revs, int cached)
diffcore_fix_diff_index(&revs->diffopt);
diffcore_std(&revs->diffopt);
diff_flush(&revs->diffopt);
trace_performance_since(start, "diff-index");
trace_performance_leave("diff-index");
return 0;
}

Expand Down
4 changes: 2 additions & 2 deletions dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -2334,11 +2334,11 @@ int read_directory(struct dir_struct *dir, struct index_state *istate,
const char *path, int len, const struct pathspec *pathspec)
{
struct untracked_cache_dir *untracked;
uint64_t start = getnanotime();

if (has_symlink_leading_path(path, len))
return dir->nr;

trace_performance_enter();
untracked = validate_untracked_cache(dir, len, pathspec);
if (!untracked)
/*
Expand Down Expand Up @@ -2373,7 +2373,7 @@ int read_directory(struct dir_struct *dir, struct index_state *istate,
dir->nr = i;
}

trace_performance_since(start, "read directory %.*s", len, path);
trace_performance_leave("read directory %.*s", len, path);
if (dir->untracked) {
static int force_untracked_cache = -1;
static struct trace_key trace_untracked_stats = TRACE_KEY_INIT(UNTRACKED_STATS);
Expand Down
4 changes: 2 additions & 2 deletions name-hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -578,10 +578,10 @@ static void threaded_lazy_init_name_hash(

static void lazy_init_name_hash(struct index_state *istate)
{
uint64_t start = getnanotime();

if (istate->name_hash_initialized)
return;
trace_performance_enter();
hashmap_init(&istate->name_hash, cache_entry_cmp, NULL, istate->cache_nr);
hashmap_init(&istate->dir_hash, dir_entry_cmp, NULL, istate->cache_nr);

Expand All @@ -602,7 +602,7 @@ static void lazy_init_name_hash(struct index_state *istate)
}

istate->name_hash_initialized = 1;
trace_performance_since(start, "initialize name hash");
trace_performance_leave("initialize name hash");
}

/*
Expand Down
4 changes: 2 additions & 2 deletions preload-index.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ void preload_index(struct index_state *index, const struct pathspec *pathspec)
{
int threads, i, work, offset;
struct thread_data data[MAX_PARALLEL];
uint64_t start = getnanotime();

if (!core_preload_index)
return;
Expand All @@ -86,6 +85,7 @@ void preload_index(struct index_state *index, const struct pathspec *pathspec)
threads = 2;
if (threads < 2)
return;
trace_performance_enter();
if (threads > MAX_PARALLEL)
threads = MAX_PARALLEL;
offset = 0;
Expand All @@ -108,8 +108,8 @@ void preload_index(struct index_state *index, const struct pathspec *pathspec)
if (pthread_join(p->pthread, NULL))
die("unable to join threaded lstat");
}
trace_performance_since(start, "preload index");
enable_fscache(0);
trace_performance_leave("preload index");
}
#endif

Expand Down
13 changes: 8 additions & 5 deletions read-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -1469,8 +1469,8 @@ int refresh_index(struct index_state *istate, unsigned int flags,
const char *typechange_fmt;
const char *added_fmt;
const char *unmerged_fmt;
uint64_t start = getnanotime();

trace_performance_enter();
modified_fmt = (in_porcelain ? "M\t%s\n" : "%s: needs update\n");
deleted_fmt = (in_porcelain ? "D\t%s\n" : "%s: needs update\n");
typechange_fmt = (in_porcelain ? "T\t%s\n" : "%s needs update\n");
Expand Down Expand Up @@ -1540,7 +1540,7 @@ int refresh_index(struct index_state *istate, unsigned int flags,

replace_index_entry(istate, i, new_entry);
}
trace_performance_since(start, "refresh index");
trace_performance_leave("refresh index");
return has_errors;
}

Expand Down Expand Up @@ -1992,7 +1992,6 @@ static void freshen_shared_index(const char *shared_index, int warn)
int read_index_from(struct index_state *istate, const char *path,
const char *gitdir)
{
uint64_t start = getnanotime();
struct split_index *split_index;
int ret;
char *base_sha1_hex;
Expand All @@ -2002,15 +2001,17 @@ int read_index_from(struct index_state *istate, const char *path,
if (istate->initialized)
return istate->cache_nr;

trace_performance_enter();
ret = do_read_index(istate, path, 0);
trace_performance_since(start, "read cache %s", path);
trace_performance_leave("read cache %s", path);

split_index = istate->split_index;
if (!split_index || is_null_sha1(split_index->base_sha1)) {
post_read_index_from(istate);
return ret;
}

trace_performance_enter();
if (split_index->base)
discard_index(split_index->base);
else
Expand All @@ -2027,8 +2028,8 @@ int read_index_from(struct index_state *istate, const char *path,
freshen_shared_index(base_path, 0);
merge_base_index(istate);
post_read_index_from(istate);
trace_performance_since(start, "read cache %s", base_path);
free(base_path);
trace_performance_leave("read cache %s", base_path);
return ret;
}

Expand Down Expand Up @@ -2890,6 +2891,8 @@ void move_index_extensions(struct index_state *dst, struct index_state *src)
{
dst->untracked = src->untracked;
src->untracked = NULL;
dst->cache_tree = src->cache_tree;
src->cache_tree = NULL;
}

/*
Expand Down
69 changes: 63 additions & 6 deletions trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,30 @@ void trace_strbuf_fl(const char *file, int line, struct trace_key *key,
strbuf_release(&buf);
}

static uint64_t perf_start_times[10];
static int perf_indent;

uint64_t trace_performance_enter(void)
{
uint64_t now;

if (!trace_want(&trace_perf_key))
return 0;

now = getnanotime();
perf_start_times[perf_indent] = now;
if (perf_indent + 1 < ARRAY_SIZE(perf_start_times))
perf_indent++;
else
BUG("Too deep indentation");
return now;
}

static void trace_performance_vprintf_fl(const char *file, int line,
uint64_t nanos, const char *format,
va_list ap)
{
static const char space[] = " ";
struct strbuf buf = STRBUF_INIT;

if (!prepare_trace_line(file, line, &trace_perf_key, &buf))
Expand All @@ -187,7 +207,10 @@ static void trace_performance_vprintf_fl(const char *file, int line,
strbuf_addf(&buf, "performance: %.9f s", (double) nanos / 1000000000);

if (format && *format) {
strbuf_addstr(&buf, ": ");
if (perf_indent >= strlen(space))
BUG("Too deep indentation");

strbuf_addf(&buf, ":%.*s ", perf_indent, space);
strbuf_vaddf(&buf, format, ap);
}

Expand Down Expand Up @@ -243,6 +266,24 @@ void trace_performance_since(uint64_t start, const char *format, ...)
va_end(ap);
}

void trace_performance_leave(const char *format, ...)
{
va_list ap;
uint64_t since;

if (perf_indent)
perf_indent--;

if (!format) /* Allow callers to leave without tracing anything */
return;

since = perf_start_times[perf_indent];
va_start(ap, format);
trace_performance_vprintf_fl(NULL, 0, getnanotime() - since,
format, ap);
va_end(ap);
}

#else

void trace_printf_key_fl(const char *file, int line, struct trace_key *key,
Expand Down Expand Up @@ -272,6 +313,24 @@ void trace_performance_fl(const char *file, int line, uint64_t nanos,
va_end(ap);
}

void trace_performance_leave_fl(const char *file, int line,
uint64_t nanos, const char *format, ...)
{
va_list ap;
uint64_t since;

if (perf_indent)
perf_indent--;

if (!format) /* Allow callers to leave without tracing anything */
return;

since = perf_start_times[perf_indent];
va_start(ap, format);
trace_performance_vprintf_fl(file, line, nanos - since, format, ap);
va_end(ap);
}

#endif /* HAVE_VARIADIC_MACROS */


Expand Down Expand Up @@ -411,24 +470,22 @@ uint64_t getnanotime(void)
}
}

static uint64_t command_start_time;
static struct strbuf command_line = STRBUF_INIT;

static void print_command_performance_atexit(void)
{
trace_performance_since(command_start_time, "git command:%s",
command_line.buf);
trace_performance_leave("git command:%s", command_line.buf);
}

void trace_command_performance(const char **argv)
{
if (!trace_want(&trace_perf_key))
return;

if (!command_start_time)
if (!command_line.len)
atexit(print_command_performance_atexit);

strbuf_reset(&command_line);
sq_quote_argv_pretty(&command_line, argv);
command_start_time = getnanotime();
trace_performance_enter();
}
15 changes: 15 additions & 0 deletions trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ extern void trace_disable(struct trace_key *key);
extern uint64_t getnanotime(void);
extern void trace_command_performance(const char **argv);
extern void trace_verbatim(struct trace_key *key, const void *buf, unsigned len);
uint64_t trace_performance_enter(void);

#ifndef HAVE_VARIADIC_MACROS

Expand All @@ -44,6 +45,9 @@ extern void trace_performance(uint64_t nanos, const char *format, ...);
__attribute__((format (printf, 2, 3)))
extern void trace_performance_since(uint64_t start, const char *format, ...);

__attribute__((format (printf, 1, 2)))
void trace_performance_leave(const char *format, ...);

#else

/*
Expand Down Expand Up @@ -117,6 +121,14 @@ extern void trace_performance_since(uint64_t start, const char *format, ...);
__VA_ARGS__); \
} while (0)

#define trace_performance_leave(...) \
do { \
if (trace_pass_fl(&trace_perf_key)) \
trace_performance_leave_fl(TRACE_CONTEXT, __LINE__, \
getnanotime(), \
__VA_ARGS__); \
} while (0)

/* backend functions, use non-*fl macros instead */
__attribute__((format (printf, 4, 5)))
extern void trace_printf_key_fl(const char *file, int line, struct trace_key *key,
Expand All @@ -129,6 +141,9 @@ extern void trace_strbuf_fl(const char *file, int line, struct trace_key *key,
__attribute__((format (printf, 4, 5)))
extern void trace_performance_fl(const char *file, int line,
uint64_t nanos, const char *fmt, ...);
__attribute__((format (printf, 4, 5)))
extern void trace_performance_leave_fl(const char *file, int line,
uint64_t nanos, const char *fmt, ...);
static inline int trace_pass_fl(struct trace_key *key)
{
return key->fd || !key->initialized;
Expand Down
Loading