#NEWLINE# def run( self ) : #NEWLINE# #INDENT# 'Start periodic profiler inspections.\n\n        This will run, periodically inspecting and then sleeping, until\n        manually stopped via stop().\n\n        We try to "stay on schedule" by keeping track of the time we should be\n        at and sleeping until that time. This means that if we stop running for\n        a while due to context switching or other pauses, we\'ll start sampling\n        faster to catch up, so we\'ll get the right number of samples in the\n        end, but the samples may not be perfectly even.' #NEWLINE# next_sample_time_seconds = self . time_fxn ( ) #NEWLINE# sample_number = 0 #NEWLINE# while ( not self . should_stop ( ) ) : #NEWLINE# #INDENT# self . profile . take_sample ( sample_number ) #NEWLINE# sample_number += 1 #NEWLINE# next_sample_time_seconds += ( 1.0 / InspectingThread . SAMPLES_PER_SECOND ) #NEWLINE# seconds_to_sleep = ( next_sample_time_seconds - self . time_fxn ( ) ) #NEWLINE# if ( seconds_to_sleep > 0 ) : #NEWLINE# #INDENT# time . sleep ( seconds_to_sleep ) #NEWLINE# #UNINDENT# #UNINDENT# self . profile . take_sample ( sample_number , force_memory = True )