@@ -150,11 +150,11 @@ def setup_profiler(options):
150
150
global _scheduler
151
151
152
152
if _scheduler is not None :
153
- logger .debug ("profiling is already setup" )
153
+ logger .debug ("[Profiling] Profiler is already setup" )
154
154
return False
155
155
156
156
if not PY33 :
157
- logger .warn ("profiling is only supported on Python >= 3.3" )
157
+ logger .warn ("[Profiling] Profiler requires Python >= 3.3" )
158
158
return False
159
159
160
160
frequency = DEFAULT_SAMPLING_FREQUENCY
@@ -184,6 +184,9 @@ def setup_profiler(options):
184
184
else :
185
185
raise ValueError ("Unknown profiler mode: {}" .format (profiler_mode ))
186
186
187
+ logger .debug (
188
+ "[Profiling] Setting up profiler in {mode} mode" .format (mode = _scheduler .mode )
189
+ )
187
190
_scheduler .setup ()
188
191
189
192
atexit .register (teardown_profiler )
@@ -440,6 +443,11 @@ def __init__(
440
443
def update_active_thread_id (self ):
441
444
# type: () -> None
442
445
self .active_thread_id = get_current_thread_id ()
446
+ logger .debug (
447
+ "[Profiling] updating active thread id to {tid}" .format (
448
+ tid = self .active_thread_id
449
+ )
450
+ )
443
451
444
452
def _set_initial_sampling_decision (self , sampling_context ):
445
453
# type: (SamplingContext) -> None
@@ -456,11 +464,17 @@ def _set_initial_sampling_decision(self, sampling_context):
456
464
# The corresponding transaction was not sampled,
457
465
# so don't generate a profile for it.
458
466
if not self .sampled :
467
+ logger .debug (
468
+ "[Profiling] Discarding profile because transaction is discarded."
469
+ )
459
470
self .sampled = False
460
471
return
461
472
462
473
# The profiler hasn't been properly initialized.
463
474
if self .scheduler is None :
475
+ logger .debug (
476
+ "[Profiling] Discarding profile because profiler was not started."
477
+ )
464
478
self .sampled = False
465
479
return
466
480
@@ -478,6 +492,9 @@ def _set_initial_sampling_decision(self, sampling_context):
478
492
# The profiles_sample_rate option was not set, so profiling
479
493
# was never enabled.
480
494
if sample_rate is None :
495
+ logger .debug (
496
+ "[Profiling] Discarding profile because profiling was not enabled."
497
+ )
481
498
self .sampled = False
482
499
return
483
500
@@ -486,6 +503,15 @@ def _set_initial_sampling_decision(self, sampling_context):
486
503
# to a float (True becomes 1.0 and False becomes 0.0)
487
504
self .sampled = random .random () < float (sample_rate )
488
505
506
+ if self .sampled :
507
+ logger .debug ("[Profiling] Initializing profile" )
508
+ else :
509
+ logger .debug (
510
+ "[Profiling] Discarding profile because it's not included in the random sample (sample rate = {sample_rate})" .format (
511
+ sample_rate = float (sample_rate )
512
+ )
513
+ )
514
+
489
515
def get_profile_context (self ):
490
516
# type: () -> ProfileContext
491
517
return {"profile_id" : self .event_id }
@@ -496,6 +522,7 @@ def start(self):
496
522
return
497
523
498
524
assert self .scheduler , "No scheduler specified"
525
+ logger .debug ("[Profiling] Starting profile" )
499
526
self .active = True
500
527
self .start_ns = nanosecond_time ()
501
528
self .scheduler .start_profiling (self )
@@ -506,6 +533,7 @@ def stop(self):
506
533
return
507
534
508
535
assert self .scheduler , "No scheduler specified"
536
+ logger .debug ("[Profiling] Stopping profile" )
509
537
self .active = False
510
538
self .scheduler .stop_profiling (self )
511
539
self .stop_ns = nanosecond_time ()
@@ -651,11 +679,14 @@ def to_json(self, event_opt, options):
651
679
652
680
def valid (self ):
653
681
# type: () -> bool
654
- return (
655
- self .sampled is not None
656
- and self .sampled
657
- and self .unique_samples >= PROFILE_MINIMUM_SAMPLES
658
- )
682
+ if self .sampled is None or not self .sampled :
683
+ return False
684
+
685
+ if self .unique_samples < PROFILE_MINIMUM_SAMPLES :
686
+ logger .debug ("[Profiling] Discarding profile because insufficient samples." )
687
+ return False
688
+
689
+ return True
659
690
660
691
661
692
class Scheduler (object ):
0 commit comments