Skip to content

Commit 2cc62d0

Browse files
committed
profiling: limit reported method instances
Cap the number of method instances we report to the profiler for a single LLVM_MODULE_FINISH to 10.
1 parent 25f9eed commit 2cc62d0

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

src/jitlayers.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,12 @@ static jl_callptr_t _jl_compile_codeinst(
248248
IndirectCodeinsts += emitted.size() - 1;
249249
}
250250

251+
size_t i = 0;
251252
for (auto &def : emitted) {
252253
jl_code_instance_t *this_code = def.first;
253-
jl_timing_show_func_sig(this_code->def->specTypes, JL_TIMING_CURRENT_BLOCK);
254+
if (i < 10)
255+
jl_timing_show_func_sig(this_code->def->specTypes, JL_TIMING_CURRENT_BLOCK);
256+
254257
jl_llvm_functions_t decls = std::get<1>(def.second);
255258
jl_callptr_t addr;
256259
bool isspecsig = false;
@@ -292,7 +295,10 @@ static jl_callptr_t _jl_compile_codeinst(
292295
}
293296
if (this_code == codeinst)
294297
fptr = addr;
298+
i++;
295299
}
300+
if (i > 10)
301+
jl_timing_printf(JL_TIMING_CURRENT_BLOCK, "... <%d methods truncated>", i - 10);
296302

297303
uint64_t end_time = 0;
298304
if (timed)

src/timing.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,24 @@ JL_DLLEXPORT void jl_timing_show_func_sig(jl_value_t *v, jl_timing_block_t *cur_
187187
#endif
188188
}
189189

190+
JL_DLLEXPORT void jl_timing_printf(jl_timing_block_t *cur_block, const char *format, ...) {
191+
va_list args;
192+
va_start(args, format);
193+
194+
#ifdef USE_TRACY
195+
ios_t buf;
196+
ios_mem(&buf, IOS_INLSIZE);
197+
buf.growable = 0; // Restrict to inline buffer to avoid allocation
198+
199+
jl_vprintf((JL_STREAM*)&buf, format, args);
200+
if (buf.size == buf.maxsize)
201+
memset(&buf.buf[IOS_INLSIZE - 3], '.', 3);
202+
203+
TracyCZoneText(*(cur_block->tracy_ctx), buf.buf, buf.size);
204+
#endif
205+
va_end(args);
206+
}
207+
190208
JL_DLLEXPORT int jl_timing_set_enable(const char *subsystem, uint8_t enabled) {
191209
for (int i = 0; i < JL_TIMING_LAST; i++) {
192210
if (strcmp(subsystem, jl_timing_names[i]) == 0) {

src/timing.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ void jl_destroy_timing(void) JL_NOTSAFEPOINT;
3333
#define jl_timing_show_filename(f, b)
3434
#define jl_timing_show_method_instance(mi, b)
3535
#define jl_timing_show_func_sig(tt, b)
36+
#define jl_timing_printf(s, f, ...)
3637
#define jl_timing_block_enter_task(ct, ptls, blk)
3738
#define jl_timing_block_exit_task(ct, ptls) ((jl_timing_block_t *)NULL)
3839
#define jl_pop_timing_block(blk)
@@ -61,6 +62,7 @@ void jl_timing_show_module(jl_module_t *m, jl_timing_block_t *cur_block);
6162
void jl_timing_show_filename(const char *path, jl_timing_block_t *cur_block);
6263
void jl_timing_show_method_instance(jl_method_instance_t *mi, jl_timing_block_t *cur_block);
6364
void jl_timing_show_func_sig(jl_value_t *v, jl_timing_block_t *cur_block);
65+
void jl_timing_printf(jl_timing_block_t *cur_block, const char *format, ...);
6466

6567
// Update the enable bit-mask to enable/disable tracing events for
6668
// the subsystem in `jl_timing_names` matching the provided string.

0 commit comments

Comments
 (0)