@@ -38,7 +38,7 @@ def start(self):
38
38
return
39
39
40
40
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.' )
42
42
return
43
43
44
44
sample_time = self .SAMPLING_RATE * 1000
@@ -56,20 +56,8 @@ def _sample(signum, signal_frame):
56
56
57
57
with self .profile_lock :
58
58
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
73
61
except Exception :
74
62
self .agent .exception ()
75
63
@@ -86,7 +74,8 @@ def destroy(self):
86
74
if self .agent .get_option ('block_profiler_disabled' ):
87
75
return
88
76
89
- if self .prev_signal_handler :
77
+ if self .prev_signal_handler != None :
78
+ signal .setitimer (signal .ITIMER_REAL , 0 )
90
79
signal .signal (signal .SIGALRM , self .prev_signal_handler )
91
80
92
81
if self .profiler_scheduler :
@@ -103,17 +92,39 @@ def record(self, duration):
103
92
if self .agent .config .is_profiling_disabled ():
104
93
return
105
94
106
- self .agent .log ('Activating blocking call profiler.' )
95
+ self .agent .log ('Activating block profiler.' )
107
96
108
97
signal .setitimer (signal .ITIMER_REAL , self .SAMPLING_RATE , self .SAMPLING_RATE )
109
98
time .sleep (duration )
110
99
signal .setitimer (signal .ITIMER_REAL , 0 )
111
100
112
- self .agent .log ('Deactivating blocking call profiler.' )
101
+ self .agent .log ('Deactivating block profiler.' )
113
102
114
103
self .profile_duration += duration
115
104
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
+
117
128
118
129
119
130
def recover_stack (self , thread_frame ):
0 commit comments