@@ -129,15 +129,15 @@ def try_continuous_profiling_auto_start():
129129 if not _scheduler .is_auto_start_enabled ():
130130 return
131131
132- _scheduler .ensure_running ()
132+ _scheduler .manual_start ()
133133
134134
135135def start_profiler ():
136136 # type: () -> None
137137 if _scheduler is None :
138138 return
139139
140- _scheduler .ensure_running ()
140+ _scheduler .manual_start ()
141141
142142
143143def stop_profiler ():
@@ -198,15 +198,15 @@ def is_auto_start_enabled(self):
198198 experiments = self .options .get ("_experiments" )
199199 if not experiments :
200200 return False
201- if not experiments .get ("continuous_profiling_auto_start" ):
202- return False
203201
204- # Ensure that the scheduler only autostarts once per process.
205- # This is necessary because many web servers use forks to spawn
206- # additional processes. And the profiler is only spawned on the
207- # master process, then it often only profiles the main process
208- # and not the ones where the requests are being handled.
209- return self .pid != os .getpid ()
202+ return experiments .get ("continuous_profiling_auto_start" )
203+
204+ def manual_start (self ):
205+ # type: () -> None
206+ if not self .sampled :
207+ return
208+
209+ self .ensure_running ()
210210
211211 def ensure_running (self ):
212212 # type: () -> None
@@ -305,10 +305,6 @@ def __init__(self, frequency, options, sdk_info, capture_func):
305305 def ensure_running (self ):
306306 # type: () -> None
307307
308- # if the current profile session is not sampled, ensure_running is noop
309- if not self .sampled :
310- return
311-
312308 pid = os .getpid ()
313309
314310 # is running on the right process
@@ -385,10 +381,6 @@ def ensure_running(self):
385381 # type: () -> None
386382 pid = os .getpid ()
387383
388- # if the current profile session is not sampled, ensure_running is noop
389- if not self .sampled :
390- return
391-
392384 # is running on the right process
393385 if self .running and self .pid == pid :
394386 return
@@ -415,7 +407,6 @@ def ensure_running(self):
415407 # longer allows us to spawn a thread and we have to bail.
416408 self .running = False
417409 self .thread = None
418- return
419410
420411 def teardown (self ):
421412 # type: () -> None
0 commit comments