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 dir = hashmap_iter_first(&the_index.dir_hash, &iter_dir);
46 printf("dir %08x %7d %s\n", dir->ent.hash, dir->nr, dir->name);
47 dir = hashmap_iter_next(&iter_dir);
50 ce = hashmap_iter_first(&the_index.name_hash, &iter_cache);
52 printf("name %08x %s\n", ce->ent.hash, ce->name);
53 ce = hashmap_iter_next(&iter_cache);
60 * Run the single or multi threaded version "count" times and
61 * report on the time taken.
63 static uint64_t time_runs(int try_threaded)
71 for (i = 0; i < count; i++) {
75 nr_threads_used = test_lazy_init_name_hash(&the_index, try_threaded);
80 if (try_threaded && !nr_threads_used)
81 die("non-threaded code path used");
84 printf("%f %f %d multi %d\n",
85 ((double)(t1 - t0))/1000000000,
86 ((double)(t2 - t1))/1000000000,
90 printf("%f %f %d single\n",
91 ((double)(t1 - t0))/1000000000,
92 ((double)(t2 - t1))/1000000000,
101 printf("avg %f %s\n",
102 (double)avg/1000000000,
103 (try_threaded) ? "multi" : "single");
109 * Try a series of runs varying the "istate->cache_nr" and
110 * try to find a good value for the multi-threaded criteria.
112 static void analyze_run(void)
114 uint64_t t1s, t1m, t2s, t2m;
116 int nr_threads_used = 0;
121 cache_nr_limit = the_index.cache_nr;
126 uint64_t sum_single = 0;
127 uint64_t sum_multi = 0;
131 if (nr > cache_nr_limit)
134 for (i = 0; i < count; i++) {
136 the_index.cache_nr = nr; /* cheap truncate of index */
138 test_lazy_init_name_hash(&the_index, 0);
140 sum_single += (t2s - t1s);
141 the_index.cache_nr = cache_nr_limit;
145 the_index.cache_nr = nr; /* cheap truncate of index */
147 nr_threads_used = test_lazy_init_name_hash(&the_index, 1);
149 sum_multi += (t2m - t1m);
150 the_index.cache_nr = cache_nr_limit;
153 if (!nr_threads_used)
154 printf(" [size %8d] [single %f] non-threaded code path used\n",
155 nr, ((double)(t2s - t1s))/1000000000);
157 printf(" [size %8d] [single %f] %c [multi %f %d]\n",
159 ((double)(t2s - t1s))/1000000000,
160 (((t2s - t1s) < (t2m - t1m)) ? '<' : '>'),
161 ((double)(t2m - t1m))/1000000000,
166 avg_single = sum_single / count;
167 avg_multi = sum_multi / count;
168 if (!nr_threads_used)
169 printf("avg [size %8d] [single %f]\n",
171 (double)avg_single/1000000000);
173 printf("avg [size %8d] [single %f] %c [multi %f %d]\n",
175 (double)avg_single/1000000000,
176 (avg_single < avg_multi ? '<' : '>'),
177 (double)avg_multi/1000000000,
182 if (nr >= cache_nr_limit)
188 int cmd__lazy_init_name_hash(int argc, const char **argv)
190 const char *usage[] = {
191 "test-tool lazy-init-name-hash -d (-s | -m)",
192 "test-tool lazy-init-name-hash -p [-c c]",
193 "test-tool lazy-init-name-hash -a a [--step s] [-c c]",
194 "test-tool lazy-init-name-hash (-s | -m) [-c c]",
195 "test-tool lazy-init-name-hash -s -m [-c c]",
198 struct option options[] = {
199 OPT_BOOL('s', "single", &single, "run single-threaded code"),
200 OPT_BOOL('m', "multi", &multi, "run multi-threaded code"),
201 OPT_INTEGER('c', "count", &count, "number of passes"),
202 OPT_BOOL('d', "dump", &dump, "dump hash tables"),
203 OPT_BOOL('p', "perf", &perf, "compare single vs multi"),
204 OPT_INTEGER('a', "analyze", &analyze, "analyze different multi sizes"),
205 OPT_INTEGER(0, "step", &analyze_step, "analyze step factor"),
209 uint64_t avg_single, avg_multi;
211 prefix = setup_git_directory();
213 argc = parse_options(argc, argv, prefix, options, usage, 0);
216 * istate->dir_hash is only created when ignore_case is set.
221 if (perf || analyze > 0)
222 die("cannot combine dump, perf, or analyze");
224 die("count not valid with dump");
226 die("cannot use both single and multi with dump");
227 if (!single && !multi)
228 die("dump requires either single or multi");
235 die("cannot combine dump, perf, or analyze");
237 die("cannot use single or multi with perf");
238 avg_single = time_runs(0);
239 avg_multi = time_runs(1);
240 if (avg_multi > avg_single)
241 die("multi is slower");
247 die("analyze must be at least 500");
249 analyze_step = analyze;
251 die("cannot use single or multi with analyze");
256 if (!single && !multi)
257 die("require either -s or -m or both");