@@ -38,7 +38,7 @@ def start(self):
3838 return
3939
4040 if not runtime_info .OS_LINUX and not runtime_info .OS_DARWIN :
41- self .agent .log ('Time profiler is only supported on Linux and OS X.' )
41+ self .agent .log ('Block profiler is only supported on Linux and OS X.' )
4242 return
4343
4444 sample_time = self .SAMPLING_RATE * 1000
@@ -56,20 +56,8 @@ def _sample(signum, signal_frame):
5656
5757 with self .profile_lock :
5858 try :
59- if self .block_profile :
60- start = time .clock ()
61-
62- current_frames = sys ._current_frames ()
63- for thread_id , thread_frame in current_frames .items ():
64- if thread_id == main_thread_id :
65- thread_frame = signal_frame
66-
67- stack = self .recover_stack (thread_frame )
68- if stack :
69- self .update_block_profile (stack , sample_time )
70- self .update_http_profile (stack , sample_time )
71-
72- self .block_profile ._overhead += (time .clock () - start )
59+ self .process_sample (signal_frame , sample_time , main_thread_id )
60+ signal_frame = None
7361 except Exception :
7462 self .agent .exception ()
7563
@@ -86,7 +74,8 @@ def destroy(self):
8674 if self .agent .get_option ('block_profiler_disabled' ):
8775 return
8876
89- if self .prev_signal_handler :
77+ if self .prev_signal_handler != None :
78+ signal .setitimer (signal .ITIMER_REAL , 0 )
9079 signal .signal (signal .SIGALRM , self .prev_signal_handler )
9180
9281 if self .profiler_scheduler :
@@ -103,17 +92,39 @@ def record(self, duration):
10392 if self .agent .config .is_profiling_disabled ():
10493 return
10594
106- self .agent .log ('Activating blocking call profiler.' )
95+ self .agent .log ('Activating block profiler.' )
10796
10897 signal .setitimer (signal .ITIMER_REAL , self .SAMPLING_RATE , self .SAMPLING_RATE )
10998 time .sleep (duration )
11099 signal .setitimer (signal .ITIMER_REAL , 0 )
111100
112- self .agent .log ('Deactivating blocking call profiler.' )
101+ self .agent .log ('Deactivating block profiler.' )
113102
114103 self .profile_duration += duration
115104
116- self .agent .log ('Time profiler CPU overhead per activity second: {0} seconds' .format (self .block_profile ._overhead / self .profile_duration ))
105+ self .agent .log ('Block profiler CPU overhead per activity second: {0} seconds' .format (self .block_profile ._overhead / self .profile_duration ))
106+
107+
108+ def process_sample (self , signal_frame , sample_time , main_thread_id ):
109+ if self .block_profile :
110+ start = time .clock ()
111+
112+ current_frames = sys ._current_frames ()
113+ for thread_id , thread_frame in current_frames .items ():
114+ if thread_id == main_thread_id :
115+ thread_frame = signal_frame
116+
117+ stack = self .recover_stack (thread_frame )
118+ if stack :
119+ self .update_block_profile (stack , sample_time )
120+ self .update_http_profile (stack , sample_time )
121+
122+ thread_id , thread_frame , stack = None , None , None
123+
124+ current_frames = None
125+
126+ self .block_profile ._overhead += (time .clock () - start )
127+
117128
118129
119130 def recover_stack (self , thread_frame ):
0 commit comments