3 #include "parse-options.h"
11 static int analyze_step;
14 * Dump the contents of the "dir" and "name" hash tables to stdout.
15 * If you sort the result, you can compare it with the other type
16 * mode and verify that both single and multi produce the same set.
18 static void dump_run(void)
20 struct hashmap_iter iter_dir;
21 struct hashmap_iter iter_cache;
23 /* Stolen from name-hash.c */
25 struct hashmap_entry ent;
26 struct dir_entry *parent;
29 char name[FLEX_ARRAY];
32 struct dir_entry *dir;
33 struct cache_entry *ce;
37 test_lazy_init_name_hash(&the_index, 0);
39 int nr_threads_used = test_lazy_init_name_hash(&the_index, 1);
41 die("non-threaded code path used");
44 hashmap_for_each_entry(&the_index.dir_hash, &iter_dir, dir,
45 ent /* member name */)
46 printf("dir %08x %7d %s\n", dir->ent.hash, dir->nr, dir->name);
48 hashmap_for_each_entry(&the_index.name_hash, &iter_cache, ce,
49 ent /* member name */)
50 printf("name %08x %s\n", ce->ent.hash, ce->name);
56 * Run the single or multi threaded version "count" times and
57 * report on the time taken.
59 static uint64_t time_runs(int try_threaded)
67 for (i = 0; i < count; i++) {
71 nr_threads_used = test_lazy_init_name_hash(&the_index, try_threaded);
76 if (try_threaded && !nr_threads_used)
77 die("non-threaded code path used");
80 printf("%f %f %d multi %d\n",
81 ((double)(t1 - t0))/1000000000,
82 ((double)(t2 - t1))/1000000000,
86 printf("%f %f %d single\n",
87 ((double)(t1 - t0))/1000000000,
88 ((double)(t2 - t1))/1000000000,
98 (double)avg/1000000000,
99 (try_threaded) ? "multi" : "single");
105 * Try a series of runs varying the "istate->cache_nr" and
106 * try to find a good value for the multi-threaded criteria.
108 static void analyze_run(void)
110 uint64_t t1s, t1m, t2s, t2m;
112 int nr_threads_used = 0;
117 cache_nr_limit = the_index.cache_nr;
122 uint64_t sum_single = 0;
123 uint64_t sum_multi = 0;
127 if (nr > cache_nr_limit)
130 for (i = 0; i < count; i++) {
132 the_index.cache_nr = nr; /* cheap truncate of index */
134 test_lazy_init_name_hash(&the_index, 0);
136 sum_single += (t2s - t1s);
137 the_index.cache_nr = cache_nr_limit;
141 the_index.cache_nr = nr; /* cheap truncate of index */
143 nr_threads_used = test_lazy_init_name_hash(&the_index, 1);
145 sum_multi += (t2m - t1m);
146 the_index.cache_nr = cache_nr_limit;
149 if (!nr_threads_used)
150 printf(" [size %8d] [single %f] non-threaded code path used\n",
151 nr, ((double)(t2s - t1s))/1000000000);
153 printf(" [size %8d] [single %f] %c [multi %f %d]\n",
155 ((double)(t2s - t1s))/1000000000,
156 (((t2s - t1s) < (t2m - t1m)) ? '<' : '>'),
157 ((double)(t2m - t1m))/1000000000,
162 avg_single = sum_single / count;
163 avg_multi = sum_multi / count;
164 if (!nr_threads_used)
165 printf("avg [size %8d] [single %f]\n",
167 (double)avg_single/1000000000);
169 printf("avg [size %8d] [single %f] %c [multi %f %d]\n",
171 (double)avg_single/1000000000,
172 (avg_single < avg_multi ? '<' : '>'),
173 (double)avg_multi/1000000000,
178 if (nr >= cache_nr_limit)
184 int cmd__lazy_init_name_hash(int argc, const char **argv)
186 const char *usage[] = {
187 "test-tool lazy-init-name-hash -d (-s | -m)",
188 "test-tool lazy-init-name-hash -p [-c c]",
189 "test-tool lazy-init-name-hash -a a [--step s] [-c c]",
190 "test-tool lazy-init-name-hash (-s | -m) [-c c]",
191 "test-tool lazy-init-name-hash -s -m [-c c]",
194 struct option options[] = {
195 OPT_BOOL('s', "single", &single, "run single-threaded code"),
196 OPT_BOOL('m', "multi", &multi, "run multi-threaded code"),
197 OPT_INTEGER('c', "count", &count, "number of passes"),
198 OPT_BOOL('d', "dump", &dump, "dump hash tables"),
199 OPT_BOOL('p', "perf", &perf, "compare single vs multi"),
200 OPT_INTEGER('a', "analyze", &analyze, "analyze different multi sizes"),
201 OPT_INTEGER(0, "step", &analyze_step, "analyze step factor"),
205 uint64_t avg_single, avg_multi;
207 prefix = setup_git_directory();
209 argc = parse_options(argc, argv, prefix, options, usage, 0);
212 * istate->dir_hash is only created when ignore_case is set.
217 if (perf || analyze > 0)
218 die("cannot combine dump, perf, or analyze");
220 die("count not valid with dump");
222 die("cannot use both single and multi with dump");
223 if (!single && !multi)
224 die("dump requires either single or multi");
231 die("cannot combine dump, perf, or analyze");
233 die("cannot use single or multi with perf");
234 avg_single = time_runs(0);
235 avg_multi = time_runs(1);
236 if (avg_multi > avg_single)
237 die("multi is slower");
243 die("analyze must be at least 500");
245 analyze_step = analyze;
247 die("cannot use single or multi with analyze");
252 if (!single && !multi)
253 die("require either -s or -m or both");