Skip to content

Commit 090dbea

Browse files
committed
Merge branch 'nd/trace-index-ops'
* nd/trace-index-ops: trace: measure where the time is spent in the index-heavy operations
2 parents 9b6734e + ca54d9b commit 090dbea

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
@@ -2245,6 +2245,7 @@ int read_directory(struct dir_struct *dir, struct index_state *istate,
22452245
const char *path, int len, const struct pathspec *pathspec)
22462246
{
22472247
struct untracked_cache_dir *untracked;
2248+
uint64_t start = getnanotime();
22482249

22492250
if (has_symlink_leading_path(path, len))
22502251
return dir->nr;
@@ -2283,6 +2284,7 @@ int read_directory(struct dir_struct *dir, struct index_state *istate,
22832284
dir->nr = i;
22842285
}
22852286

2287+
trace_performance_since(start, "read directory %.*s", len, path);
22862288
if (dir->untracked) {
22872289
static struct trace_key trace_untracked_stats = TRACE_KEY_INIT(UNTRACKED_STATS);
22882290
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
@@ -1371,6 +1371,7 @@ int refresh_index(struct index_state *istate, unsigned int flags,
13711371
const char *typechange_fmt;
13721372
const char *added_fmt;
13731373
const char *unmerged_fmt;
1374+
uint64_t start = getnanotime();
13741375

13751376
modified_fmt = (in_porcelain ? "M\t%s\n" : "%s: needs update\n");
13761377
deleted_fmt = (in_porcelain ? "D\t%s\n" : "%s: needs update\n");
@@ -1441,6 +1442,7 @@ int refresh_index(struct index_state *istate, unsigned int flags,
14411442

14421443
replace_index_entry(istate, i, new);
14431444
}
1445+
trace_performance_since(start, "refresh index");
14441446
return has_errors;
14451447
}
14461448

@@ -1871,6 +1873,7 @@ static void freshen_shared_index(const char *shared_index, int warn)
18711873
int read_index_from(struct index_state *istate, const char *path,
18721874
const char *gitdir)
18731875
{
1876+
uint64_t start = getnanotime();
18741877
struct split_index *split_index;
18751878
int ret;
18761879
char *base_sha1_hex;
@@ -1881,6 +1884,7 @@ int read_index_from(struct index_state *istate, const char *path,
18811884
return istate->cache_nr;
18821885

18831886
ret = do_read_index(istate, path, 0);
1887+
trace_performance_since(start, "read cache %s", path);
18841888

18851889
split_index = istate->split_index;
18861890
if (!split_index || is_null_sha1(split_index->base_sha1)) {
@@ -1904,6 +1908,7 @@ int read_index_from(struct index_state *istate, const char *path,
19041908
freshen_shared_index(base_path, 0);
19051909
merge_base_index(istate);
19061910
post_read_index_from(istate);
1911+
trace_performance_since(start, "read cache %s", base_path);
19071912
free(base_path);
19081913
return ret;
19091914
}
@@ -2233,6 +2238,7 @@ void update_index_if_able(struct index_state *istate, struct lock_file *lockfile
22332238
static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
22342239
int strip_extensions)
22352240
{
2241+
uint64_t start = getnanotime();
22362242
int newfd = tempfile->fd;
22372243
git_SHA_CTX c;
22382244
struct cache_header hdr;
@@ -2373,6 +2379,7 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
23732379
return -1;
23742380
istate->timestamp.sec = (unsigned int)st.st_mtime;
23752381
istate->timestamp.nsec = ST_MTIME_NSEC(st);
2382+
trace_performance_since(start, "write index, changed mask = %x", istate->cache_changed);
23762383
return 0;
23772384
}
23782385

0 commit comments

Comments
 (0)