#NEWLINE# def results( self ) : #NEWLINE# #INDENT# 'Return sampling results in a dictionary for template context.' #NEWLINE# total_samples = len ( self . samples ) #NEWLINE# frames = [ ] #NEWLINE# frame_indexes = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for sample in self . samples : #NEWLINE# #INDENT# for frame_desc in sample . get_frame_descriptions ( ) : #NEWLINE# #INDENT# if ( not ( frame_desc in frame_indexes ) ) : #NEWLINE# #INDENT# frame_indexes [ frame_desc ] = len ( frames ) #NEWLINE# frames . append ( frame_desc ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# samples = [ { #NEWLINE# #INDENT# 'timestamp_ms' : util . milliseconds_fmt ( sample . timestamp_ms , 1 ) , #NEWLINE# 'memory_used' : self . memory_samples . get ( sample . timestamp_ms ) , #NEWLINE# 'stack_frames' : [ frame_indexes [ desc ] for desc in sample . get_frame_descriptions ( ) ] , #NEWLINE# #UNINDENT# } for sample in self . samples ] #NEWLINE# if self . memory_sample_every : #NEWLINE# #INDENT# Profile . annotate_prev_samples ( samples , 'prev_memory_sample_index' ) #NEWLINE# Profile . annotate_prev_samples ( samples , 'next_memory_sample_index' , rev = True ) #NEWLINE# #UNINDENT# results = { #NEWLINE# #INDENT# 'frame_names' : [ util . short_method_fmt ( frame ) for frame in frames ] , #NEWLINE# 'samples' : samples , #NEWLINE# 'total_samples' : total_samples , #NEWLINE# #UNINDENT# } #NEWLINE# if ( self . memory_sample_every and self . memory_samples ) : #NEWLINE# #INDENT# results . update ( { #NEWLINE# #INDENT# 'start_memory' : round ( self . memory_samples . values ( ) [ 0 ] , 2 ) , #NEWLINE# 'max_memory' : round ( max ( self . memory_samples . values ( ) ) , 2 ) , #NEWLINE# 'end_memory' : round ( self . memory_samples . values ( ) [ ( - 1 ) ] , 2 ) , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# return results