trace2:data: add trace2 instrumentation to index read/write

Add trace2 events to measure reading and writing the index. Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff Hostetler committed Feb 22, 2019 at 14:25 UTC 42fee7a3889b558aa8b79dfa2802d8fd8fbd8c60
1 file changed +50 -1
read-cache.c
+50 -1
@@ -2220,6 +2220,16 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)
2220 load_index_extensions(&p);
2221 }
2222 munmap((void *)mmap, mmap_size);
2223 +
2224 + /*
2225 + * TODO trace2: replace "the_repository" with the actual repo instance
2226 + * that is associated with the given "istate".
2227 + */
2228 + trace2_data_intmax("index", the_repository, "read/version",
2229 + istate->version);
2230 + trace2_data_intmax("index", the_repository, "read/cache_nr",
2231 + istate->cache_nr);
2232 +
2233 return istate->cache_nr;
2234
2235 unmap:
@@ -2251,9 +2261,17 @@ int read_index_from(struct index_state *istate, const char *path,
2261 if (istate->initialized)
2262 return istate->cache_nr;
2263
2264 + /*
2265 + * TODO trace2: replace "the_repository" with the actual repo instance
2266 + * that is associated with the given "istate".
2267 + */
2268 + trace2_region_enter_printf("index", "do_read_index", the_repository,
2269 + "%s", path);
2270 trace_performance_enter();
2271 ret = do_read_index(istate, path, 0);
2272 trace_performance_leave("read cache %s", path);
2273 + trace2_region_leave_printf("index", "do_read_index", the_repository,
2274 + "%s", path);
2275
2276 split_index = istate->split_index;
2277 if (!split_index || is_null_oid(&split_index->base_oid)) {
@@ -2269,7 +2287,11 @@ int read_index_from(struct index_state *istate, const char *path,
2287
2288 base_oid_hex = oid_to_hex(&split_index->base_oid);
2289 base_path = xstrfmt("%s/sharedindex.%s", gitdir, base_oid_hex);
2290 + trace2_region_enter_printf("index", "shared/do_read_index",
2291 + the_repository, "%s", base_path);
2292 ret = do_read_index(split_index->base, base_path, 1);
2293 + trace2_region_leave_printf("index", "shared/do_read_index",
2294 + the_repository, "%s", base_path);
2295 if (!oideq(&split_index->base_oid, &split_index->base->oid))
2296 die(_("broken index, expect %s in %s, got %s"),
2297 base_oid_hex, base_path,
@@ -2976,6 +2998,16 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
2998 istate->timestamp.sec = (unsigned int)st.st_mtime;
2999 istate->timestamp.nsec = ST_MTIME_NSEC(st);
3000 trace_performance_since(start, "write index, changed mask = %x", istate->cache_changed);
3001 +
3002 + /*
3003 + * TODO trace2: replace "the_repository" with the actual repo instance
3004 + * that is associated with the given "istate".
3005 + */
3006 + trace2_data_intmax("index", the_repository, "write/version",
3007 + istate->version);
3008 + trace2_data_intmax("index", the_repository, "write/cache_nr",
3009 + istate->cache_nr);
3010 +
3011 return 0;
3012 }
3013
@@ -2995,7 +3027,18 @@ static int commit_locked_index(struct lock_file *lk)
3027 static int do_write_locked_index(struct index_state *istate, struct lock_file *lock,
3028 unsigned flags)
3029 {
2998 - int ret = do_write_index(istate, lock->tempfile, 0);
3030 + int ret;
3031 +
3032 + /*
3033 + * TODO trace2: replace "the_repository" with the actual repo instance
3034 + * that is associated with the given "istate".
3035 + */
3036 + trace2_region_enter_printf("index", "do_write_index", the_repository,
3037 + "%s", lock->tempfile->filename.buf);
3038 + ret = do_write_index(istate, lock->tempfile, 0);
3039 + trace2_region_leave_printf("index", "do_write_index", the_repository,
3040 + "%s", lock->tempfile->filename.buf);
3041 +
3042 if (ret)
3043 return ret;
3044 if (flags & COMMIT_LOCK)
@@ -3080,7 +3123,13 @@ static int write_shared_index(struct index_state *istate,
3123 int ret;
3124
3125 move_cache_to_base_index(istate);
3126 +
3127 + trace2_region_enter_printf("index", "shared/do_write_index",
3128 + the_repository, "%s", (*temp)->filename.buf);
3129 ret = do_write_index(si->base, *temp, 1);
3130 + trace2_region_enter_printf("index", "shared/do_write_index",
3131 + the_repository, "%s", (*temp)->filename.buf);
3132 +
3133 if (ret)
3134 return ret;
3135 ret = adjust_shared_perm(get_tempfile_path(*temp));