1 #define USE_THE_INDEX_VARIABLE
3 #include "environment.h"
5 #include "parse-options.h"
6 #include "read-cache-ll.h"
7 #include "repository.h"
17 static int analyze_step
;
20 * Dump the contents of the "dir" and "name" hash tables to stdout.
21 * If you sort the result, you can compare it with the other type
22 * mode and verify that both single and multi produce the same set.
24 static void dump_run(void)
26 struct hashmap_iter iter_dir
;
27 struct hashmap_iter iter_cache
;
29 /* Stolen from name-hash.c */
31 struct hashmap_entry ent
;
32 struct dir_entry
*parent
;
35 char name
[FLEX_ARRAY
];
38 struct dir_entry
*dir
;
39 struct cache_entry
*ce
;
41 repo_read_index(the_repository
);
43 test_lazy_init_name_hash(&the_index
, 0);
45 int nr_threads_used
= test_lazy_init_name_hash(&the_index
, 1);
47 die("non-threaded code path used");
50 hashmap_for_each_entry(&the_index
.dir_hash
, &iter_dir
, dir
,
51 ent
/* member name */)
52 printf("dir %08x %7d %s\n", dir
->ent
.hash
, dir
->nr
, dir
->name
);
54 hashmap_for_each_entry(&the_index
.name_hash
, &iter_cache
, ce
,
55 ent
/* member name */)
56 printf("name %08x %s\n", ce
->ent
.hash
, ce
->name
);
58 discard_index(&the_index
);
62 * Run the single or multi threaded version "count" times and
63 * report on the time taken.
65 static uint64_t time_runs(int try_threaded
)
73 for (i
= 0; i
< count
; i
++) {
75 repo_read_index(the_repository
);
77 nr_threads_used
= test_lazy_init_name_hash(&the_index
, try_threaded
);
82 if (try_threaded
&& !nr_threads_used
)
83 die("non-threaded code path used");
86 printf("%f %f %d multi %d\n",
87 ((double)(t1
- t0
))/1000000000,
88 ((double)(t2
- t1
))/1000000000,
92 printf("%f %f %d single\n",
93 ((double)(t1
- t0
))/1000000000,
94 ((double)(t2
- t1
))/1000000000,
98 discard_index(&the_index
);
103 printf("avg %f %s\n",
104 (double)avg
/1000000000,
105 (try_threaded
) ? "multi" : "single");
111 * Try a series of runs varying the "istate->cache_nr" and
112 * try to find a good value for the multi-threaded criteria.
114 static void analyze_run(void)
116 uint64_t t1s
, t1m
, t2s
, t2m
;
118 int nr_threads_used
= 0;
122 repo_read_index(the_repository
);
123 cache_nr_limit
= the_index
.cache_nr
;
124 discard_index(&the_index
);
128 uint64_t sum_single
= 0;
129 uint64_t sum_multi
= 0;
133 if (nr
> cache_nr_limit
)
136 for (i
= 0; i
< count
; i
++) {
137 repo_read_index(the_repository
);
138 the_index
.cache_nr
= nr
; /* cheap truncate of index */
140 test_lazy_init_name_hash(&the_index
, 0);
142 sum_single
+= (t2s
- t1s
);
143 the_index
.cache_nr
= cache_nr_limit
;
144 discard_index(&the_index
);
146 repo_read_index(the_repository
);
147 the_index
.cache_nr
= nr
; /* cheap truncate of index */
149 nr_threads_used
= test_lazy_init_name_hash(&the_index
, 1);
151 sum_multi
+= (t2m
- t1m
);
152 the_index
.cache_nr
= cache_nr_limit
;
153 discard_index(&the_index
);
155 if (!nr_threads_used
)
156 printf(" [size %8d] [single %f] non-threaded code path used\n",
157 nr
, ((double)(t2s
- t1s
))/1000000000);
159 printf(" [size %8d] [single %f] %c [multi %f %d]\n",
161 ((double)(t2s
- t1s
))/1000000000,
162 (((t2s
- t1s
) < (t2m
- t1m
)) ? '<' : '>'),
163 ((double)(t2m
- t1m
))/1000000000,
168 avg_single
= sum_single
/ count
;
169 avg_multi
= sum_multi
/ count
;
170 if (!nr_threads_used
)
171 printf("avg [size %8d] [single %f]\n",
173 (double)avg_single
/1000000000);
175 printf("avg [size %8d] [single %f] %c [multi %f %d]\n",
177 (double)avg_single
/1000000000,
178 (avg_single
< avg_multi
? '<' : '>'),
179 (double)avg_multi
/1000000000,
184 if (nr
>= cache_nr_limit
)
190 int cmd__lazy_init_name_hash(int argc
, const char **argv
)
192 const char *usage
[] = {
193 "test-tool lazy-init-name-hash -d (-s | -m)",
194 "test-tool lazy-init-name-hash -p [-c c]",
195 "test-tool lazy-init-name-hash -a a [--step s] [-c c]",
196 "test-tool lazy-init-name-hash (-s | -m) [-c c]",
197 "test-tool lazy-init-name-hash -s -m [-c c]",
200 struct option options
[] = {
201 OPT_BOOL('s', "single", &single
, "run single-threaded code"),
202 OPT_BOOL('m', "multi", &multi
, "run multi-threaded code"),
203 OPT_INTEGER('c', "count", &count
, "number of passes"),
204 OPT_BOOL('d', "dump", &dump
, "dump hash tables"),
205 OPT_BOOL('p', "perf", &perf
, "compare single vs multi"),
206 OPT_INTEGER('a', "analyze", &analyze
, "analyze different multi sizes"),
207 OPT_INTEGER(0, "step", &analyze_step
, "analyze step factor"),
211 uint64_t avg_single
, avg_multi
;
213 prefix
= setup_git_directory();
215 argc
= parse_options(argc
, argv
, prefix
, options
, usage
, 0);
218 * istate->dir_hash is only created when ignore_case is set.
223 if (perf
|| analyze
> 0)
224 die("cannot combine dump, perf, or analyze");
226 die("count not valid with dump");
228 die("cannot use both single and multi with dump");
229 if (!single
&& !multi
)
230 die("dump requires either single or multi");
237 die("cannot combine dump, perf, or analyze");
239 die("cannot use single or multi with perf");
240 avg_single
= time_runs(0);
241 avg_multi
= time_runs(1);
242 if (avg_multi
> avg_single
)
243 die("multi is slower");
249 die("analyze must be at least 500");
251 analyze_step
= analyze
;
253 die("cannot use single or multi with analyze");
258 if (!single
&& !multi
)
259 die("require either -s or -m or both");