Skip to content

Commit ca54d9b

Browse files
pcloudsgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5be1f00 commit ca54d9b

File tree

5 files changed

+18
-0
lines changed

5 files changed

+18
-0
lines changed

diff-lib.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
9292
int diff_unmerged_stage = revs->max_count;
9393
unsigned ce_option = ((option & DIFF_RACY_IS_MODIFIED)
9494
? CE_MATCH_RACY_IS_DIRTY : 0);
95+
uint64_t start = getnanotime();
9596

9697
diff_set_mnemonic_prefix(&revs->diffopt, "i/", "w/");
9798

@@ -246,6 +247,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
246247
}
247248
diffcore_std(&revs->diffopt);
248249
diff_flush(&revs->diffopt);
250+
trace_performance_since(start, "diff-files");
249251
return 0;
250252
}
251253

@@ -512,6 +514,7 @@ static int diff_cache(struct rev_info *revs,
512514
int run_diff_index(struct rev_info *revs, int cached)
513515
{
514516
struct object_array_entry *ent;
517+
uint64_t start = getnanotime();
515518

516519
ent = revs->pending.objects;
517520
if (diff_cache(revs, &ent->item->oid, ent->name, cached))
@@ -521,6 +524,7 @@ int run_diff_index(struct rev_info *revs, int cached)
521524
diffcore_fix_diff_index(&revs->diffopt);
522525
diffcore_std(&revs->diffopt);
523526
diff_flush(&revs->diffopt);
527+
trace_performance_since(start, "diff-index");
524528
return 0;
525529
}
526530

dir.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2248,6 +2248,7 @@ int read_directory(struct dir_struct *dir, struct index_state *istate,
22482248
const char *path, int len, const struct pathspec *pathspec)
22492249
{
22502250
struct untracked_cache_dir *untracked;
2251+
uint64_t start = getnanotime();
22512252

22522253
if (has_symlink_leading_path(path, len))
22532254
return dir->nr;
@@ -2286,6 +2287,7 @@ int read_directory(struct dir_struct *dir, struct index_state *istate,
22862287
dir->nr = i;
22872288
}
22882289

2290+
trace_performance_since(start, "read directory %.*s", len, path);
22892291
if (dir->untracked) {
22902292
static struct trace_key trace_untracked_stats = TRACE_KEY_INIT(UNTRACKED_STATS);
22912293
trace_printf_key(&trace_untracked_stats,

name-hash.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,8 @@ static void threaded_lazy_init_name_hash(
578578

579579
static void lazy_init_name_hash(struct index_state *istate)
580580
{
581+
uint64_t start = getnanotime();
582+
581583
if (istate->name_hash_initialized)
582584
return;
583585
hashmap_init(&istate->name_hash, cache_entry_cmp, NULL, istate->cache_nr);
@@ -600,6 +602,7 @@ static void lazy_init_name_hash(struct index_state *istate)
600602
}
601603

602604
istate->name_hash_initialized = 1;
605+
trace_performance_since(start, "initialize name hash");
603606
}
604607

605608
/*

preload-index.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ static void preload_index(struct index_state *index,
7878
{
7979
int threads, i, work, offset;
8080
struct thread_data data[MAX_PARALLEL];
81+
uint64_t start = getnanotime();
8182

8283
if (!core_preload_index)
8384
return;
@@ -108,6 +109,7 @@ static void preload_index(struct index_state *index,
108109
if (pthread_join(p->pthread, NULL))
109110
die("unable to join threaded lstat");
110111
}
112+
trace_performance_since(start, "preload index");
111113
}
112114
#endif
113115

read-cache.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,6 +1372,7 @@ int refresh_index(struct index_state *istate, unsigned int flags,
13721372
const char *typechange_fmt;
13731373
const char *added_fmt;
13741374
const char *unmerged_fmt;
1375+
uint64_t start = getnanotime();
13751376

13761377
modified_fmt = (in_porcelain ? "M\t%s\n" : "%s: needs update\n");
13771378
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,
14421443

14431444
replace_index_entry(istate, i, new);
14441445
}
1446+
trace_performance_since(start, "refresh index");
14451447
return has_errors;
14461448
}
14471449

@@ -1873,6 +1875,7 @@ static void freshen_shared_index(char *base_sha1_hex, int warn)
18731875

18741876
int read_index_from(struct index_state *istate, const char *path)
18751877
{
1878+
uint64_t start = getnanotime();
18761879
struct split_index *split_index;
18771880
int ret;
18781881
char *base_sha1_hex;
@@ -1883,6 +1886,7 @@ int read_index_from(struct index_state *istate, const char *path)
18831886
return istate->cache_nr;
18841887

18851888
ret = do_read_index(istate, path, 0);
1889+
trace_performance_since(start, "read cache %s", path);
18861890

18871891
split_index = istate->split_index;
18881892
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)
19061910
freshen_shared_index(base_sha1_hex, 0);
19071911
merge_base_index(istate);
19081912
post_read_index_from(istate);
1913+
trace_performance_since(start, "read cache %s", base_path);
19091914
return ret;
19101915
}
19111916

@@ -2234,6 +2239,7 @@ void update_index_if_able(struct index_state *istate, struct lock_file *lockfile
22342239
static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
22352240
int strip_extensions)
22362241
{
2242+
uint64_t start = getnanotime();
22372243
int newfd = tempfile->fd;
22382244
git_SHA_CTX c;
22392245
struct cache_header hdr;
@@ -2374,6 +2380,7 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
23742380
return -1;
23752381
istate->timestamp.sec = (unsigned int)st.st_mtime;
23762382
istate->timestamp.nsec = ST_MTIME_NSEC(st);
2383+
trace_performance_since(start, "write index, changed mask = %x", istate->cache_changed);
23772384
return 0;
23782385
}
23792386

0 commit comments

Comments
 (0)