@@ -36,6 +36,11 @@ JL_DLLEXPORT uint64_t jl_timing_enable_mask = 0xFFFFFFFFFFFFFFFF;
3636#endif
3737
3838JL_DLLEXPORT uint64_t jl_timing_counts [(int )JL_TIMING_LAST ] = {0 };
39+
40+ // Used to as an item limit when several strings of metadata can
41+ // potentially be associated with a single timing zone.
42+ JL_DLLEXPORT uint32_t jl_timing_print_limit = 10 ;
43+
3944const char * jl_timing_names [(int )JL_TIMING_LAST ] =
4045 {
4146#define X (name ) #name
@@ -100,14 +105,16 @@ void jl_timing_block_enter_task(jl_task_t *ct, jl_ptls_t ptls, jl_timing_block_t
100105jl_timing_block_t * jl_timing_block_exit_task (jl_task_t * ct , jl_ptls_t ptls )
101106{
102107#ifdef USE_TRACY
103- // Tracy is fairly strict about not leaving a fiber that
104- // hasn't been entered, which happens often when
105- // connecting to a running Julia session.
108+ // Tracy is fairly strict about not leaving a fiber that hasn't
109+ // been entered, which happens often when connecting to a running
110+ // Julia session.
111+ //
112+ // Eventually, Tracy will support telling the server which fibers
113+ // are active upon connection, but until then we work around the
114+ // problem by not explicitly leaving the fiber at all.
106115 //
107- // Eventually, Tracy will support telling the server that
108- // which fibers are active upon connection, but until then
109- // work around around the problem by just entering the new
110- // fiber directly, which implicitly leaves any active fibers.
116+ // Later when we enter the new fiber directly, that will cause the
117+ // the active fiber to be left implicitly.
111118
112119 //TracyCFiberLeave;
113120#endif
@@ -220,11 +227,71 @@ JL_DLLEXPORT int jl_timing_set_enable(const char *subsystem, uint8_t enabled)
220227 return -1 ;
221228}
222229
230+ static void jl_timing_set_enable_from_env (void )
231+ {
232+ const char * env = getenv ("JULIA_TIMING_SUBSYSTEMS" );
233+ if (!env )
234+ return ;
235+
236+ // Copy `env`, so that we can modify it
237+ size_t sz = strlen (env ) + 1 ;
238+ char * env_copy = (char * )malloc (sz );
239+ memcpy (env_copy , env , sz );
240+
241+ char * subsystem = env_copy ;
242+ char * ch = subsystem ;
243+ uint8_t enable = 1 ;
244+ while (1 ) {
245+ // +SUBSYSTEM means enable, -SUBSYSTEM means disable
246+ if (* subsystem == '+' || * subsystem == '-' )
247+ enable = (* subsystem ++ == '+' );
248+
249+ if (* ch == ',' ) {
250+ * ch ++ = '\0' ;
251+ if ((* subsystem != '\0' ) && jl_timing_set_enable (subsystem , enable ))
252+ fprintf (stderr , "warning: unable to configure timing for non-existent subsystem \"%s\"\n" , subsystem );
253+
254+ subsystem = ch ;
255+ enable = 1 ;
256+ }
257+ else if (* ch == '\0' ) {
258+ if ((* subsystem != '\0' ) && jl_timing_set_enable (subsystem , enable ))
259+ fprintf (stderr , "warning: unable to configure timing for non-existent subsystem \"%s\"\n" , subsystem );
260+
261+ break ;
262+ }
263+ else ch ++ ;
264+ }
265+ free (env_copy );
266+ }
267+
268+ static void jl_timing_set_print_limit_from_env (void )
269+ {
270+ const char * const env = getenv ("JULIA_TIMING_METADATA_PRINT_LIMIT" );
271+ if (!env )
272+ return ;
273+
274+ char * endp ;
275+ long value = strtol (env , & endp , 10 );
276+ if (* endp == '\0' && value >= 0 && value <= UINT32_MAX )
277+ jl_timing_print_limit = (uint32_t )value ;
278+ }
279+
280+ void jl_timing_apply_env (void )
281+ {
282+ // JULIA_TIMING_SUBSYSTEMS
283+ jl_timing_set_enable_from_env ();
284+
285+ // JULIA_TIMING_METADATA_PRINT_LIMIT
286+ jl_timing_set_print_limit_from_env ();
287+ }
288+
223289#else
224290
225291void jl_init_timing (void ) { }
226292void jl_destroy_timing (void ) { }
227293JL_DLLEXPORT int jl_timing_set_enable (const char * subsystem , uint8_t enabled ) { return -1 ; }
294+ JL_DLLEXPORT uint32_t jl_timing_print_limit = 0 ;
228295
229296#endif
230297
0 commit comments