]>
git.ipfire.org Git - thirdparty/git.git/blob - t/helper/test-lazy-init-name-hash.c
1 #define USE_THE_INDEX_VARIABLE
4 #include "environment.h"
5 #include "parse-options.h"
6 #include "repository.h"
16 static int analyze_step
;
19 * Dump the contents of the "dir" and "name" hash tables to stdout.
20 * If you sort the result, you can compare it with the other type
21 * mode and verify that both single and multi produce the same set.
23 static void dump_run(void)
25 struct hashmap_iter iter_dir
;
26 struct hashmap_iter iter_cache
;
28 /* Stolen from name-hash.c */
30 struct hashmap_entry ent
;
31 struct dir_entry
*parent
;
34 char name
[FLEX_ARRAY
];
37 struct dir_entry
*dir
;
38 struct cache_entry
*ce
;
40 repo_read_index(the_repository
);
42 test_lazy_init_name_hash(&the_index
, 0);
44 int nr_threads_used
= test_lazy_init_name_hash(&the_index
, 1);
46 die("non-threaded code path used");
49 hashmap_for_each_entry(&the_index
.dir_hash
, &iter_dir
, dir
,
50 ent
/* member name */)
51 printf("dir %08x %7d %s\n", dir
->ent
.hash
, dir
->nr
, dir
->name
);
53 hashmap_for_each_entry(&the_index
.name_hash
, &iter_cache
, ce
,
54 ent
/* member name */)
55 printf("name %08x %s\n", ce
->ent
.hash
, ce
->name
);
57 discard_index(&the_index
);
61 * Run the single or multi threaded version "count" times and
62 * report on the time taken.
64 static uint64_t time_runs(int try_threaded
)
72 for (i
= 0; i
< count
; i
++) {
74 repo_read_index(the_repository
);
76 nr_threads_used
= test_lazy_init_name_hash(&the_index
, try_threaded
);
81 if (try_threaded
&& !nr_threads_used
)
82 die("non-threaded code path used");
85 printf("%f %f %d multi %d\n",
86 ((double)(t1
- t0
))/1000000000,
87 ((double)(t2
- t1
))/1000000000,
91 printf("%f %f %d single\n",
92 ((double)(t1
- t0
))/1000000000,
93 ((double)(t2
- t1
))/1000000000,
97 discard_index(&the_index
);
102 printf("avg %f %s\n",
103 (double)avg
/1000000000,
104 (try_threaded
) ? "multi" : "single");
110 * Try a series of runs varying the "istate->cache_nr" and
111 * try to find a good value for the multi-threaded criteria.
113 static void analyze_run(void)
115 uint64_t t1s
, t1m
, t2s
, t2m
;
117 int nr_threads_used
= 0;
121 repo_read_index(the_repository
);
122 cache_nr_limit
= the_index
.cache_nr
;
123 discard_index(&the_index
);
127 uint64_t sum_single
= 0;
128 uint64_t sum_multi
= 0;
132 if (nr
> cache_nr_limit
)
135 for (i
= 0; i
< count
; i
++) {
136 repo_read_index(the_repository
);
137 the_index
.cache_nr
= nr
; /* cheap truncate of index */
139 test_lazy_init_name_hash(&the_index
, 0);
141 sum_single
+= (t2s
- t1s
);
142 the_index
.cache_nr
= cache_nr_limit
;
143 discard_index(&the_index
);
145 repo_read_index(the_repository
);
146 the_index
.cache_nr
= nr
; /* cheap truncate of index */
148 nr_threads_used
= test_lazy_init_name_hash(&the_index
, 1);
150 sum_multi
+= (t2m
- t1m
);
151 the_index
.cache_nr
= cache_nr_limit
;
152 discard_index(&the_index
);
154 if (!nr_threads_used
)
155 printf(" [size %8d] [single %f] non-threaded code path used\n",
156 nr
, ((double)(t2s
- t1s
))/1000000000);
158 printf(" [size %8d] [single %f] %c [multi %f %d]\n",
160 ((double)(t2s
- t1s
))/1000000000,
161 (((t2s
- t1s
) < (t2m
- t1m
)) ? '<' : '>'),
162 ((double)(t2m
- t1m
))/1000000000,
167 avg_single
= sum_single
/ count
;
168 avg_multi
= sum_multi
/ count
;
169 if (!nr_threads_used
)
170 printf("avg [size %8d] [single %f]\n",
172 (double)avg_single
/1000000000);
174 printf("avg [size %8d] [single %f] %c [multi %f %d]\n",
176 (double)avg_single
/1000000000,
177 (avg_single
< avg_multi
? '<' : '>'),
178 (double)avg_multi
/1000000000,
183 if (nr
>= cache_nr_limit
)
189 int cmd__lazy_init_name_hash(int argc
, const char **argv
)
191 const char *usage
[] = {
192 "test-tool lazy-init-name-hash -d (-s | -m)",
193 "test-tool lazy-init-name-hash -p [-c c]",
194 "test-tool lazy-init-name-hash -a a [--step s] [-c c]",
195 "test-tool lazy-init-name-hash (-s | -m) [-c c]",
196 "test-tool lazy-init-name-hash -s -m [-c c]",
199 struct option options
[] = {
200 OPT_BOOL('s', "single", &single
, "run single-threaded code"),
201 OPT_BOOL('m', "multi", &multi
, "run multi-threaded code"),
202 OPT_INTEGER('c', "count", &count
, "number of passes"),
203 OPT_BOOL('d', "dump", &dump
, "dump hash tables"),
204 OPT_BOOL('p', "perf", &perf
, "compare single vs multi"),
205 OPT_INTEGER('a', "analyze", &analyze
, "analyze different multi sizes"),
206 OPT_INTEGER(0, "step", &analyze_step
, "analyze step factor"),
210 uint64_t avg_single
, avg_multi
;
212 prefix
= setup_git_directory();
214 argc
= parse_options(argc
, argv
, prefix
, options
, usage
, 0);
217 * istate->dir_hash is only created when ignore_case is set.
222 if (perf
|| analyze
> 0)
223 die("cannot combine dump, perf, or analyze");
225 die("count not valid with dump");
227 die("cannot use both single and multi with dump");
228 if (!single
&& !multi
)
229 die("dump requires either single or multi");
236 die("cannot combine dump, perf, or analyze");
238 die("cannot use single or multi with perf");
239 avg_single
= time_runs(0);
240 avg_multi
= time_runs(1);
241 if (avg_multi
> avg_single
)
242 die("multi is slower");
248 die("analyze must be at least 500");
250 analyze_step
= analyze
;
252 die("cannot use single or multi with analyze");
257 if (!single
&& !multi
)
258 die("require either -s or -m or both");