88
99#include <stdio.h>
1010
11- void IO_Event_Profile_Call_initialize (struct IO_Event_Profile_Call * event ) {
12- event -> enter_time .tv_sec = 0 ;
13- event -> enter_time .tv_nsec = 0 ;
14- event -> exit_time .tv_sec = 0 ;
15- event -> exit_time .tv_nsec = 0 ;
11+ void IO_Event_Profile_Call_initialize (struct IO_Event_Profile_Call * call ) {
12+ call -> enter_time .tv_sec = 0 ;
13+ call -> enter_time .tv_nsec = 0 ;
14+ call -> exit_time .tv_sec = 0 ;
15+ call -> exit_time .tv_nsec = 0 ;
1616
17- event -> nesting = 0 ;
17+ call -> nesting = 0 ;
1818
19- event -> event_flag = 0 ;
20- event -> id = 0 ;
19+ call -> event_flag = 0 ;
20+ call -> id = 0 ;
2121
22- event -> path = NULL ;
23- event -> line = 0 ;
22+ call -> path = NULL ;
23+ call -> line = 0 ;
2424}
2525
26- void IO_Event_Profile_Call_free (struct IO_Event_Profile_Call * event ) {
27- if (event -> path ) {
28- free ((void * )event -> path );
26+ void IO_Event_Profile_Call_free (struct IO_Event_Profile_Call * call ) {
27+ if (call -> path ) {
28+ free ((void * )call -> path );
2929 }
3030}
3131
@@ -41,49 +41,49 @@ static void profile_event_callback(rb_event_flag_t event_flag, VALUE data, VALUE
4141 struct IO_Event_Profile * profile = (struct IO_Event_Profile * )data ;
4242
4343 if (event_flag_call_p (event_flag )) {
44- struct IO_Event_Profile_Call * event = IO_Event_Array_push (& profile -> events );
45- IO_Event_Time_current (& event -> enter_time );
44+ struct IO_Event_Profile_Call * call = IO_Event_Array_push (& profile -> calls );
45+ IO_Event_Time_current (& call -> enter_time );
4646
47- event -> event_flag = event_flag ;
47+ call -> event_flag = event_flag ;
4848
49- event -> parent = profile -> current ;
50- profile -> current = event ;
49+ call -> parent = profile -> current ;
50+ profile -> current = call ;
5151
52- event -> nesting = profile -> nesting ;
52+ call -> nesting = profile -> nesting ;
5353 profile -> nesting += 1 ;
5454
5555 if (id ) {
56- event -> id = id ;
57- event -> klass = klass ;
56+ call -> id = id ;
57+ call -> klass = klass ;
5858 } else {
59- rb_frame_method_id_and_class (& event -> id , & event -> klass );
59+ rb_frame_method_id_and_class (& call -> id , & call -> klass );
6060 }
6161
6262 const char * path = rb_sourcefile ();
6363 if (path ) {
64- event -> path = strdup (path );
64+ call -> path = strdup (path );
6565 }
66- event -> line = rb_sourceline ();
66+ call -> line = rb_sourceline ();
6767 } else if (event_flag_return_p (event_flag )) {
68- struct IO_Event_Profile_Call * event = profile -> current ;
68+ struct IO_Event_Profile_Call * call = profile -> current ;
6969
70- // Bad event sequence?
71- if (event == NULL ) return ;
70+ // Bad call sequence?
71+ if (call == NULL ) return ;
7272
73- IO_Event_Time_current (& event -> exit_time );
73+ IO_Event_Time_current (& call -> exit_time );
7474
75- profile -> current = event -> parent ;
75+ profile -> current = call -> parent ;
7676 profile -> nesting -= 1 ;
7777 }
7878}
7979
8080void IO_Event_Profile_initialize (struct IO_Event_Profile * profile , VALUE fiber ) {
8181 profile -> fiber = fiber ;
8282
83- profile -> events .element_initialize = (void (* )(void * ))IO_Event_Profile_Call_initialize ;
84- profile -> events .element_free = (void (* )(void * ))IO_Event_Profile_Call_free ;
83+ profile -> calls .element_initialize = (void (* )(void * ))IO_Event_Profile_Call_initialize ;
84+ profile -> calls .element_free = (void (* )(void * ))IO_Event_Profile_Call_free ;
8585
86- IO_Event_Array_initialize (& profile -> events , 0 , sizeof (struct IO_Event_Profile_Call ));
86+ IO_Event_Array_initialize (& profile -> calls , 0 , sizeof (struct IO_Event_Profile_Call ));
8787}
8888
8989void IO_Event_Profile_start (struct IO_Event_Profile * profile ) {
@@ -104,7 +104,7 @@ void IO_Event_Profile_stop(struct IO_Event_Profile *profile) {
104104}
105105
106106void IO_Event_Profile_free (struct IO_Event_Profile * profile ) {
107- IO_Event_Array_free (& profile -> events );
107+ IO_Event_Array_free (& profile -> calls );
108108}
109109
110110static const float IO_EVENT_PROFILE_PRINT_MINIMUM_PROPORTION = 0.01 ;
@@ -115,28 +115,28 @@ void IO_Event_Profile_print(FILE *restrict stream, struct IO_Event_Profile *prof
115115
116116 size_t skipped = 0 ;
117117
118- for (size_t i = 0 ; i < profile -> events .limit ; i += 1 ) {
119- struct IO_Event_Profile_Call * event = profile -> events .base [i ];
118+ for (size_t i = 0 ; i < profile -> calls .limit ; i += 1 ) {
119+ struct IO_Event_Profile_Call * call = profile -> calls .base [i ];
120120
121121 struct timespec duration = {};
122122
123- IO_Event_Time_elapsed (& event -> enter_time , & event -> exit_time , & duration );
123+ IO_Event_Time_elapsed (& call -> enter_time , & call -> exit_time , & duration );
124124
125- // Skip events that are too short to be meaningful:
125+ // Skip calls that are too short to be meaningful:
126126 if (IO_Event_Time_proportion (& duration , & total_duration ) < IO_EVENT_PROFILE_PRINT_MINIMUM_PROPORTION ) {
127127 skipped += 1 ;
128128 continue ;
129129 }
130130
131- for (size_t i = 0 ; i < event -> nesting ; i += 1 ) {
131+ for (size_t i = 0 ; i < call -> nesting ; i += 1 ) {
132132 fputc ('\t' , stream );
133133 }
134134
135- const char * name = rb_id2name (event -> id );
136- fprintf (stream , "\t%s:%d in '%s#%s' (" IO_EVENT_TIME_PRINTF_TIMESPEC "s)\n" , event -> path , event -> line , RSTRING_PTR (rb_inspect (event -> klass )), name , IO_EVENT_TIME_PRINTF_TIMESPEC_ARGUMENTS (duration ));
135+ const char * name = rb_id2name (call -> id );
136+ fprintf (stream , "\t%s:%d in '%s#%s' (" IO_EVENT_TIME_PRINTF_TIMESPEC "s)\n" , call -> path , call -> line , RSTRING_PTR (rb_inspect (call -> klass )), name , IO_EVENT_TIME_PRINTF_TIMESPEC_ARGUMENTS (duration ));
137137 }
138138
139139 if (skipped > 0 ) {
140- fprintf (stream , "Skipped %zu events that were too short to be meaningful.\n" , skipped );
140+ fprintf (stream , "Skipped %zu calls that were too short to be meaningful.\n" , skipped );
141141 }
142142}
0 commit comments