Skip to content

Commit 520b639

Browse files
authored
Merge pull request #49647 from topolarity/timing-refactor
Make `jl_timer_block_t` allocation separate from timer-start (JL_TIMING)
2 parents c55000a + 74addd3 commit 520b639

File tree

12 files changed

+118
-137
lines changed

12 files changed

+118
-137
lines changed

src/ast.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ JL_DLLEXPORT jl_value_t *jl_fl_parse(const char *text, size_t text_len,
784784
size_t offset, jl_value_t *options)
785785
{
786786
JL_TIMING(PARSING, PARSING);
787-
jl_timing_show_filename(jl_string_data(filename), JL_TIMING_CURRENT_BLOCK);
787+
jl_timing_show_filename(jl_string_data(filename), JL_TIMING_DEFAULT_BLOCK);
788788
if (offset > text_len) {
789789
jl_value_t *textstr = jl_pchar_to_string(text, text_len);
790790
JL_GC_PUSH1(&textstr);

src/codegen.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8517,7 +8517,7 @@ jl_llvm_functions_t jl_emit_code(
85178517
jl_codegen_params_t &params)
85188518
{
85198519
JL_TIMING(CODEGEN, CODEGEN_LLVM);
8520-
jl_timing_show_func_sig((jl_value_t *)li->specTypes, JL_TIMING_CURRENT_BLOCK);
8520+
jl_timing_show_func_sig((jl_value_t *)li->specTypes, JL_TIMING_DEFAULT_BLOCK);
85218521
// caller must hold codegen_lock
85228522
jl_llvm_functions_t decls = {};
85238523
assert((params.params == &jl_default_cgparams /* fast path */ || !params.cache ||
@@ -8579,7 +8579,7 @@ jl_llvm_functions_t jl_emit_codeinst(
85798579
jl_codegen_params_t &params)
85808580
{
85818581
JL_TIMING(CODEGEN, CODEGEN_Codeinst);
8582-
jl_timing_show_method_instance(codeinst->def, JL_TIMING_CURRENT_BLOCK);
8582+
jl_timing_show_method_instance(codeinst->def, JL_TIMING_DEFAULT_BLOCK);
85838583
JL_GC_PUSH1(&src);
85848584
if (!src) {
85858585
src = (jl_code_info_t*)jl_atomic_load_relaxed(&codeinst->inferred);

src/dlload.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ JL_DLLEXPORT void *jl_load_dynamic_library(const char *modname, unsigned flags,
284284

285285
JL_TIMING(DL_OPEN, DL_OPEN);
286286
if (!(flags & JL_RTLD_NOLOAD))
287-
jl_timing_puts(JL_TIMING_CURRENT_BLOCK, modname);
287+
jl_timing_puts(JL_TIMING_DEFAULT_BLOCK, modname);
288288

289289
// Detect if our `modname` is something like `@rpath/libfoo.dylib`
290290
#ifdef _OS_DARWIN_
@@ -342,7 +342,7 @@ JL_DLLEXPORT void *jl_load_dynamic_library(const char *modname, unsigned flags,
342342
#endif
343343
handle = jl_dlopen(path, flags);
344344
if (handle && !(flags & JL_RTLD_NOLOAD))
345-
jl_timing_puts(JL_TIMING_CURRENT_BLOCK, jl_pathname_for_handle(handle));
345+
jl_timing_puts(JL_TIMING_DEFAULT_BLOCK, jl_pathname_for_handle(handle));
346346
if (handle)
347347
return handle;
348348
#ifdef _OS_WINDOWS_
@@ -364,7 +364,7 @@ JL_DLLEXPORT void *jl_load_dynamic_library(const char *modname, unsigned flags,
364364
snprintf(path, PATHBUF, "%s%s", modname, ext);
365365
handle = jl_dlopen(path, flags);
366366
if (handle && !(flags & JL_RTLD_NOLOAD))
367-
jl_timing_puts(JL_TIMING_CURRENT_BLOCK, jl_pathname_for_handle(handle));
367+
jl_timing_puts(JL_TIMING_DEFAULT_BLOCK, jl_pathname_for_handle(handle));
368368
if (handle)
369369
return handle;
370370
#ifdef _OS_WINDOWS_

src/gc.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ void jl_gc_wait_for_the_world(jl_ptls_t* gc_all_tls_states, int gc_n_threads)
205205
{
206206
JL_TIMING(GC, GC_Stop);
207207
#ifdef USE_TRACY
208-
TracyCZoneCtx ctx = *(JL_TIMING_CURRENT_BLOCK->tracy_ctx);
208+
TracyCZoneCtx ctx = JL_TIMING_DEFAULT_BLOCK->tracy_ctx;
209209
TracyCZoneColor(ctx, 0x696969);
210210
#endif
211211
assert(gc_n_threads);
@@ -3307,12 +3307,13 @@ static int _jl_gc_collect(jl_ptls_t ptls, jl_gc_collection_t collection)
33073307
uint64_t start_sweep_time = jl_hrtime();
33083308
JL_PROBE_GC_SWEEP_BEGIN(sweep_full);
33093309
{
3310-
JL_TIMING(GC, GC_Sweep);
3310+
JL_TIMING_CREATE_BLOCK(incremental_timing_block,
3311+
GC, GC_IncrementalSweep);
3312+
JL_TIMING_CREATE_BLOCK(full_timing_block,
3313+
GC, GC_FullSweep);
3314+
jl_timing_block_start(sweep_full ? &full_timing_block : &incremental_timing_block);
33113315
#ifdef USE_TRACY
3312-
if (sweep_full) {
3313-
TracyCZoneCtx ctx = *(JL_TIMING_CURRENT_BLOCK->tracy_ctx);
3314-
TracyCZoneColor(ctx, 0xFFA500);
3315-
}
3316+
TracyCZoneColor(full_timing_block.tracy_ctx, 0xFFA500);
33163317
#endif
33173318
sweep_weak_refs();
33183319
sweep_stack_pools();
@@ -3456,7 +3457,7 @@ JL_DLLEXPORT void jl_gc_collect(jl_gc_collection_t collection)
34563457
return;
34573458
}
34583459

3459-
JL_TIMING_SUSPEND(GC, ct);
3460+
JL_TIMING_SUSPEND_TASK(GC, ct);
34603461
JL_TIMING(GC, GC);
34613462

34623463
int last_errno = errno;

src/gf.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ jl_code_info_t *jl_type_infer(jl_method_instance_t *mi, size_t world, int force)
367367
fargs[1] = (jl_value_t*)mi;
368368
fargs[2] = jl_box_ulong(world);
369369

370-
jl_timing_show_method_instance(mi, JL_TIMING_CURRENT_BLOCK);
370+
jl_timing_show_method_instance(mi, JL_TIMING_DEFAULT_BLOCK);
371371
#ifdef TRACE_INFERENCE
372372
if (mi->specTypes != (jl_value_t*)jl_emptytuple_type) {
373373
jl_printf(JL_STDERR,"inference on ");
@@ -1986,7 +1986,7 @@ JL_DLLEXPORT void jl_method_table_insert(jl_methtable_t *mt, jl_method_t *method
19861986
JL_TIMING(ADD_METHOD, ADD_METHOD);
19871987
assert(jl_is_method(method));
19881988
assert(jl_is_mtable(mt));
1989-
jl_timing_show_method(method, JL_TIMING_CURRENT_BLOCK);
1989+
jl_timing_show_method(method, JL_TIMING_DEFAULT_BLOCK);
19901990
jl_value_t *type = method->sig;
19911991
jl_value_t *oldvalue = NULL;
19921992
jl_array_t *oldmi = NULL;

src/jitlayers.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,7 @@ static jl_callptr_t _jl_compile_codeinst(
190190
JL_TIMING(CODEINST_COMPILE, CODEINST_COMPILE);
191191
#ifdef USE_TRACY
192192
if (is_recompile) {
193-
TracyCZoneCtx ctx = *(JL_TIMING_CURRENT_BLOCK->tracy_ctx);
194-
TracyCZoneColor(ctx, 0xFFA500);
193+
TracyCZoneColor(JL_TIMING_DEFAULT_BLOCK->tracy_ctx, 0xFFA500);
195194
}
196195
#endif
197196
jl_callptr_t fptr = NULL;
@@ -252,7 +251,7 @@ static jl_callptr_t _jl_compile_codeinst(
252251
for (auto &def : emitted) {
253252
jl_code_instance_t *this_code = def.first;
254253
if (i < jl_timing_print_limit)
255-
jl_timing_show_func_sig(this_code->def->specTypes, JL_TIMING_CURRENT_BLOCK);
254+
jl_timing_show_func_sig(this_code->def->specTypes, JL_TIMING_DEFAULT_BLOCK);
256255

257256
jl_llvm_functions_t decls = std::get<1>(def.second);
258257
jl_callptr_t addr;
@@ -301,7 +300,7 @@ static jl_callptr_t _jl_compile_codeinst(
301300
i++;
302301
}
303302
if (i > jl_timing_print_limit)
304-
jl_timing_printf(JL_TIMING_CURRENT_BLOCK, "... <%d methods truncated>", i - 10);
303+
jl_timing_printf(JL_TIMING_DEFAULT_BLOCK, "... <%d methods truncated>", i - 10);
305304

306305
uint64_t end_time = 0;
307306
if (timed)

src/method.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ JL_DLLEXPORT jl_code_info_t *jl_code_for_staged(jl_method_instance_t *linfo, siz
569569
JL_TIMING(STAGED_FUNCTION, STAGED_FUNCTION);
570570
jl_value_t *tt = linfo->specTypes;
571571
jl_method_t *def = linfo->def.method;
572-
jl_timing_show_method_instance(linfo, JL_TIMING_CURRENT_BLOCK);
572+
jl_timing_show_method_instance(linfo, JL_TIMING_DEFAULT_BLOCK);
573573
jl_value_t *generator = def->generator;
574574
assert(generator != NULL);
575575
assert(jl_is_method(def));

src/safepoint.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ void jl_safepoint_end_gc(void)
151151
void jl_safepoint_wait_gc(void)
152152
{
153153
jl_task_t *ct = jl_current_task; (void)ct;
154-
JL_TIMING_SUSPEND(GC_SAFEPOINT, ct);
154+
JL_TIMING_SUSPEND_TASK(GC_SAFEPOINT, ct);
155155
// The thread should have set this is already
156156
assert(jl_atomic_load_relaxed(&ct->ptls->gc_state) != 0);
157157
// Use normal volatile load in the loop for speed until GC finishes.

src/staticdata.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3367,7 +3367,7 @@ static jl_value_t *jl_validate_cache_file(ios_t *f, jl_array_t *depmods, uint64_
33673367
static jl_value_t *jl_restore_package_image_from_stream(ios_t *f, jl_image_t *image, jl_array_t *depmods, int completeinfo, const char *pkgname)
33683368
{
33693369
JL_TIMING(LOAD_IMAGE, LOAD_Pkgimg);
3370-
jl_timing_printf(JL_TIMING_CURRENT_BLOCK, pkgname);
3370+
jl_timing_printf(JL_TIMING_DEFAULT_BLOCK, pkgname);
33713371
uint64_t checksum = 0;
33723372
int64_t dataendpos = 0;
33733373
int64_t datastartpos = 0;

src/timing.c

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,12 @@ JL_DLLEXPORT uint32_t jl_timing_print_limit = 10;
4444
const char *jl_timing_names[(int)JL_TIMING_LAST] =
4545
{
4646
#define X(name) #name,
47-
JL_TIMING_OWNERS
47+
JL_TIMING_SUBSYSTEMS
4848
#undef X
4949
};
5050

5151
JL_DLLEXPORT jl_timing_counter_t jl_timing_counters[JL_TIMING_COUNTER_LAST];
5252

53-
#ifdef USE_ITTAPI
54-
JL_DLLEXPORT __itt_event jl_timing_ittapi_events[(int)JL_TIMING_EVENT_LAST];
55-
#endif
56-
5753
void jl_print_timings(void)
5854
{
5955
#ifdef USE_TIMING_COUNTS
@@ -91,9 +87,6 @@ void jl_init_timing(void)
9187

9288
int i __attribute__((unused)) = 0;
9389
#ifdef USE_ITTAPI
94-
#define X(name) jl_timing_ittapi_events[i++] = __itt_event_create(#name, strlen(#name));
95-
JL_TIMING_EVENTS
96-
#undef X
9790
i = 0;
9891
#define X(name) jl_timing_counters[i++].ittapi_counter = __itt_counter_create(#name, "julia.runtime");
9992
JL_TIMING_COUNTERS
@@ -187,7 +180,7 @@ JL_DLLEXPORT void jl_timing_show(jl_value_t *v, jl_timing_block_t *cur_block)
187180
if (buf.size == buf.maxsize)
188181
memset(&buf.buf[IOS_INLSIZE - 3], '.', 3);
189182

190-
TracyCZoneText(*(cur_block->tracy_ctx), buf.buf, buf.size);
183+
TracyCZoneText(cur_block->tracy_ctx, buf.buf, buf.size);
191184
#endif
192185
}
193186

@@ -197,7 +190,7 @@ JL_DLLEXPORT void jl_timing_show_module(jl_module_t *m, jl_timing_block_t *cur_b
197190
jl_module_t *root = jl_module_root(m);
198191
if (root == m || root == jl_main_module) {
199192
const char *module_name = jl_symbol_name(m->name);
200-
TracyCZoneText(*(cur_block->tracy_ctx), module_name, strlen(module_name));
193+
TracyCZoneText(cur_block->tracy_ctx, module_name, strlen(module_name));
201194
} else {
202195
jl_timing_printf(cur_block, "%s.%s", jl_symbol_name(root->name), jl_symbol_name(m->name));
203196
}
@@ -208,7 +201,7 @@ JL_DLLEXPORT void jl_timing_show_filename(const char *path, jl_timing_block_t *c
208201
{
209202
#ifdef USE_TRACY
210203
const char *filename = gnu_basename(path);
211-
TracyCZoneText(*(cur_block->tracy_ctx), filename, strlen(filename));
204+
TracyCZoneText(cur_block->tracy_ctx, filename, strlen(filename));
212205
#endif
213206
}
214207

@@ -243,7 +236,7 @@ JL_DLLEXPORT void jl_timing_show_func_sig(jl_value_t *v, jl_timing_block_t *cur_
243236
if (buf.size == buf.maxsize)
244237
memset(&buf.buf[IOS_INLSIZE - 3], '.', 3);
245238

246-
TracyCZoneText(*(cur_block->tracy_ctx), buf.buf, buf.size);
239+
TracyCZoneText(cur_block->tracy_ctx, buf.buf, buf.size);
247240
#endif
248241
}
249242

@@ -261,15 +254,15 @@ JL_DLLEXPORT void jl_timing_printf(jl_timing_block_t *cur_block, const char *for
261254
if (buf.size == buf.maxsize)
262255
memset(&buf.buf[IOS_INLSIZE - 3], '.', 3);
263256

264-
TracyCZoneText(*(cur_block->tracy_ctx), buf.buf, buf.size);
257+
TracyCZoneText(cur_block->tracy_ctx, buf.buf, buf.size);
265258
#endif
266259
va_end(args);
267260
}
268261

269262
JL_DLLEXPORT void jl_timing_puts(jl_timing_block_t *cur_block, const char *str)
270263
{
271264
#ifdef USE_TRACY
272-
TracyCZoneText(*(cur_block->tracy_ctx), str, strlen(str));
265+
TracyCZoneText(cur_block->tracy_ctx, str, strlen(str));
273266
#endif
274267
}
275268

0 commit comments

Comments
 (0)