@@ -49,17 +49,32 @@ static arraylist_t jl_timing_ittapi_events;
4949static jl_mutex_t jl_timing_ittapi_events_lock ;
5050#endif //USE_ITTAPI
5151
52+ #ifdef USE_TIMING_COUNTS
53+ static int cmp_counts_events (const void * a , const void * b ) {
54+ jl_timing_counts_event_t * event_a = * (jl_timing_counts_event_t * * )a ;
55+ jl_timing_counts_event_t * event_b = * (jl_timing_counts_event_t * * )b ;
56+ return strcmp (event_a -> name , event_b -> name );
57+ }
58+ #endif
59+
5260void jl_print_timings (void )
5361{
5462#ifdef USE_TIMING_COUNTS
63+ qsort (jl_timing_counts_events .items , jl_timing_counts_events .len ,
64+ sizeof (jl_timing_counts_event_t * ), cmp_counts_events );
65+
5566 JL_LOCK_NOGC (& jl_timing_counts_events_lock );
5667 uint64_t total_time = cycleclock () - t0 ;
5768 uint64_t root_time = total_time ;
58- for (int i = 1 ; i < jl_timing_counts_events .len ; i ++ ) {
69+ jl_timing_counts_event_t * root_event ;
70+ for (int i = 0 ; i < jl_timing_counts_events .len ; i ++ ) {
5971 jl_timing_counts_event_t * other_event = (jl_timing_counts_event_t * )jl_timing_counts_events .items [i ];
60- root_time -= jl_atomic_load_relaxed (& other_event -> self );
72+ if (strcmp (other_event -> name , "ROOT" ) == 0 ) {
73+ root_event = other_event ;
74+ } else {
75+ root_time -= jl_atomic_load_relaxed (& other_event -> self );
76+ }
6177 }
62- jl_timing_counts_event_t * root_event = (jl_timing_counts_event_t * )jl_timing_counts_events .items [0 ];
6378 jl_atomic_store_relaxed (& root_event -> self , root_time );
6479 jl_atomic_store_relaxed (& root_event -> total , total_time );
6580
@@ -90,7 +105,7 @@ void jl_print_timings(void)
90105#endif
91106}
92107
93- static const int indirect_strcmp (const void * a , const void * b ) {
108+ static int indirect_strcmp (const void * a , const void * b ) {
94109 return strcmp (* (const char * * )a , * (const char * * )b );
95110}
96111
@@ -106,12 +121,12 @@ void jl_init_timing(void)
106121 // Create events list for counts backend
107122 arraylist_new (& jl_timing_counts_events , 1 );
108123
109- jl_timing_counts_event_t * new_event = (jl_timing_counts_event_t * )malloc (sizeof (jl_timing_counts_event_t ));
110- arraylist_push (& jl_timing_counts_events , (void * )new_event );
124+ jl_timing_counts_event_t * root_event = (jl_timing_counts_event_t * )malloc (sizeof (jl_timing_counts_event_t ));
125+ arraylist_push (& jl_timing_counts_events , (void * )root_event );
111126
112- new_event -> name = "ROOT" ;
113- jl_atomic_store_relaxed (& new_event -> self , 0 );
114- jl_atomic_store_relaxed (& new_event -> total , 0 );
127+ root_event -> name = "ROOT" ;
128+ jl_atomic_store_relaxed (& root_event -> self , 0 );
129+ jl_atomic_store_relaxed (& root_event -> total , 0 );
115130#endif
116131
117132#ifdef USE_ITTAPI
@@ -121,10 +136,8 @@ void jl_init_timing(void)
121136#endif
122137
123138 // Sort the subsystem names for quick enable/disable lookups
124- qsort (
125- jl_timing_subsystems , JL_TIMING_SUBSYSTEM_LAST ,
126- sizeof (const char * ), indirect_strcmp
127- );
139+ qsort (jl_timing_subsystems , JL_TIMING_SUBSYSTEM_LAST ,
140+ sizeof (const char * ), indirect_strcmp );
128141
129142 int i __attribute__((unused )) = 0 ;
130143#ifdef USE_ITTAPI
0 commit comments