trace: measure where the time is spent in the index-heavy operations
All the known heavy code blocks are measured (except object database access). This should help identify if an optimization is effective or not. An unoptimized git-status would give something like below: 0.001791141 s: read cache ... 0.004011363 s: preload index 0.000516161 s: refresh index 0.003139257 s: git command: ... 'status' '--porcelain=2' 0.006788129 s: diff-files 0.002090267 s: diff-index 0.001885735 s: initialize name hash 0.032013138 s: read directory 0.051781209 s: git command: './git' 'status' Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
5be1f00a9a
commit
ca54d9baa4
@ -1372,6 +1372,7 @@ 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();
|
||||
|
||||
modified_fmt = (in_porcelain ? "M\t%s\n" : "%s: needs update\n");
|
||||
deleted_fmt = (in_porcelain ? "D\t%s\n" : "%s: needs update\n");
|
||||
@ -1442,6 +1443,7 @@ int refresh_index(struct index_state *istate, unsigned int flags,
|
||||
|
||||
replace_index_entry(istate, i, new);
|
||||
}
|
||||
trace_performance_since(start, "refresh index");
|
||||
return has_errors;
|
||||
}
|
||||
|
||||
@ -1873,6 +1875,7 @@ static void freshen_shared_index(char *base_sha1_hex, int warn)
|
||||
|
||||
int read_index_from(struct index_state *istate, const char *path)
|
||||
{
|
||||
uint64_t start = getnanotime();
|
||||
struct split_index *split_index;
|
||||
int ret;
|
||||
char *base_sha1_hex;
|
||||
@ -1883,6 +1886,7 @@ int read_index_from(struct index_state *istate, const char *path)
|
||||
return istate->cache_nr;
|
||||
|
||||
ret = do_read_index(istate, path, 0);
|
||||
trace_performance_since(start, "read cache %s", path);
|
||||
|
||||
split_index = istate->split_index;
|
||||
if (!split_index || is_null_sha1(split_index->base_sha1)) {
|
||||
@ -1906,6 +1910,7 @@ int read_index_from(struct index_state *istate, const char *path)
|
||||
freshen_shared_index(base_sha1_hex, 0);
|
||||
merge_base_index(istate);
|
||||
post_read_index_from(istate);
|
||||
trace_performance_since(start, "read cache %s", base_path);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -2234,6 +2239,7 @@ void update_index_if_able(struct index_state *istate, struct lock_file *lockfile
|
||||
static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
|
||||
int strip_extensions)
|
||||
{
|
||||
uint64_t start = getnanotime();
|
||||
int newfd = tempfile->fd;
|
||||
git_SHA_CTX c;
|
||||
struct cache_header hdr;
|
||||
@ -2374,6 +2380,7 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
|
||||
return -1;
|
||||
istate->timestamp.sec = (unsigned int)st.st_mtime;
|
||||
istate->timestamp.nsec = ST_MTIME_NSEC(st);
|
||||
trace_performance_since(start, "write index, changed mask = %x", istate->cache_changed);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user