#NEWLINE# def _display( self , top ) : #NEWLINE# #INDENT# log = self . stream . write #NEWLINE# snapshot = self . _snapshot #NEWLINE# has_snapshot = ( snapshot is not None ) #NEWLINE# stats = top . top_stats #NEWLINE# stats . sort ( key = operator . itemgetter ( 2 ) , reverse = True ) #NEWLINE# count = min ( self . top_count , len ( stats ) ) #NEWLINE# if self . show_lineno : #NEWLINE# #INDENT# text = 'file and line' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# text = 'file' #NEWLINE# #UNINDENT# text = ( 'Top %s allocations per %s' % ( count , text ) ) #NEWLINE# if self . color : #NEWLINE# #INDENT# text = ( _FORMAT_CYAN % text ) #NEWLINE# #UNINDENT# if has_snapshot : #NEWLINE# #INDENT# text += ( ' (compared to %s)' % snapshot . name ) #NEWLINE# #UNINDENT# name = top . name #NEWLINE# if self . color : #NEWLINE# #INDENT# name = ( _FORMAT_BOLD % name ) #NEWLINE# #UNINDENT# log ( ( '%s: %s\n' % ( name , text ) ) ) #NEWLINE# total = [ 0 , 0 , 0 , 0 ] #NEWLINE# other = None #NEWLINE# for ( index , item ) in enumerate ( stats ) : #NEWLINE# #INDENT# ( filename , lineno , trace ) = item #NEWLINE# if ( index < self . top_count ) : #NEWLINE# #INDENT# filename = self . cleanup_filename ( filename ) #NEWLINE# if ( lineno is not None ) : #NEWLINE# #INDENT# filename = ( '%s:%s' % ( filename , lineno ) ) #NEWLINE# #UNINDENT# text = self . _format_trace ( trace , has_snapshot ) #NEWLINE# if self . color : #NEWLINE# #INDENT# filename = _colorize_filename ( filename ) #NEWLINE# #UNINDENT# log ( ( '#%s: %s: %s\n' % ( ( 1 + index ) , filename , text ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( other is None ) : #NEWLINE# #INDENT# other = tuple ( total ) #NEWLINE# #UNINDENT# #UNINDENT# total [ 0 ] += trace [ 0 ] #NEWLINE# total [ 1 ] += snapshot [ 1 ] #NEWLINE# total [ 2 ] += trace [ 2 ] #NEWLINE# total [ 3 ] += trace [ 3 ] #NEWLINE# #UNINDENT# nother = ( len ( stats ) - self . top_count ) #NEWLINE# if ( nother > 0 ) : #NEWLINE# #INDENT# other = [ ( total [ 0 ] - other [ 0 ] ) , ( total [ 1 ] - other [ 1 ] ) , ( total [ 2 ] - other [ 2 ] ) , ( total [ 3 ] - other [ 3 ] ) ] #NEWLINE# text = self . _format_trace ( other , has_snapshot ) #NEWLINE# log ( ( '%s more: %s\n' % ( nother , text ) ) ) #NEWLINE# #UNINDENT# text = self . _format_trace ( total , has_snapshot ) #NEWLINE# log ( ( 'Total Python memory: %s\n' % text ) ) #NEWLINE# if top . process_memory : #NEWLINE# #INDENT# trace = [ 0 , top . process_memory , 0 , 0 ] #NEWLINE# if has_snapshot : #NEWLINE# #INDENT# trace [ 0 ] = ( trace [ 1 ] - snapshot . process_memory ) #NEWLINE# #UNINDENT# text = self . _format_trace ( trace , has_snapshot ) #NEWLINE# ignore = ( ' (ignore tracemalloc: %s)' % _format_size ( top . tracemalloc_size , False ) ) #NEWLINE# if self . color : #NEWLINE# #INDENT# ignore = ( _FORMAT_CYAN % ignore ) #NEWLINE# #UNINDENT# text += ignore #NEWLINE# log ( ( 'Total process memory: %s\n' % text ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# text = ( 'Ignore tracemalloc: %s' % _format_size ( top . tracemalloc_size , False ) ) #NEWLINE# if self . color : #NEWLINE# #INDENT# text = ( _FORMAT_CYAN % text ) #NEWLINE# #UNINDENT# log ( ( text + '\n' ) ) #NEWLINE# #UNINDENT# if top . user_data : #NEWLINE# #INDENT# for ( index , item ) in enumerate ( top . user_data ) : #NEWLINE# #INDENT# ( title , format , value ) = item #NEWLINE# if ( format == 'size' ) : #NEWLINE# #INDENT# trace = [ 0 , value , 0 , 0 ] #NEWLINE# if has_snapshot : #NEWLINE# #INDENT# trace [ 0 ] = ( trace [ 1 ] - snapshot . user_data [ index ] [ 2 ] ) #NEWLINE# #UNINDENT# text = self . _format_trace ( trace , has_snapshot ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# text = str ( value ) #NEWLINE# #UNINDENT# log ( ( '%s: %s\n' % ( title , text ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# log ( '\n' ) #NEWLINE# self . stream . flush ( )