#NEWLINE# def main( ) : #NEWLINE# #INDENT# from optparse import OptionParser #NEWLINE# print ( ( 'tracemalloc %s' % __version__ ) ) #NEWLINE# print ( '' ) #NEWLINE# parser = OptionParser ( usage = '%prog trace1.pickle [trace2.pickle  trace3.pickle ...]' ) #NEWLINE# parser . add_option ( '-l' , '--line-number' , help = 'Display line number' , action = 'store_true' , default = False ) #NEWLINE# parser . add_option ( '-n' , '--number' , help = 'Number of traces displayed per top (default: 10)' , type = 'int' , action = 'store' , default = 10 ) #NEWLINE# parser . add_option ( '--first' , help = 'Compare with the first trace, instead of with the previous trace' , action = 'store_true' , default = False ) #NEWLINE# parser . add_option ( '--include' , metavar = 'MATCH' , help = 'Only include filenames matching pattern MATCH, the option can be specified multiple times' , action = 'append' , type = str ) #NEWLINE# parser . add_option ( '--exclude' , metavar = 'MATCH' , help = 'Exclude filenames matching pattern MATCH, the option can be specified multiple times' , action = 'append' , type = str ) #NEWLINE# parser . add_option ( '-S' , '--hide-size' , help = 'Hide the size of allocations' , action = 'store_true' , default = False ) #NEWLINE# parser . add_option ( '-C' , '--hide-count' , help = 'Hide the number of allocations' , action = 'store_true' , default = False ) #NEWLINE# parser . add_option ( '-A' , '--hide-average' , help = 'Hide the average size of allocations' , action = 'store_true' , default = False ) #NEWLINE# parser . add_option ( '-P' , '--filename-parts' , help = 'Number of displayed filename parts (default: 3)' , type = 'int' , action = 'store' , default = 3 ) #NEWLINE# parser . add_option ( '--color' , help = 'Enable colors even if stdout is not a TTY' , action = 'store_true' , default = False ) #NEWLINE# parser . add_option ( '--no-color' , help = 'Disable colors' , action = 'store_true' , default = False ) #NEWLINE# ( options , filenames ) = parser . parse_args ( ) #NEWLINE# if ( not filenames ) : #NEWLINE# #INDENT# parser . print_usage ( ) #NEWLINE# sys . exit ( 1 ) #NEWLINE# #UNINDENT# filenames = list ( set ( filenames ) ) #NEWLINE# snapshots = [ ] #NEWLINE# for filename in filenames : #NEWLINE# #INDENT# snapshot = Snapshot . load ( filename ) #NEWLINE# if options . include : #NEWLINE# #INDENT# snapshot . filter_filenames ( options . include , True ) #NEWLINE# #UNINDENT# if options . exclude : #NEWLINE# #INDENT# snapshot . filter_filenames ( options . exclude , False ) #NEWLINE# #UNINDENT# snapshots . append ( snapshot ) #NEWLINE# #UNINDENT# snapshots . sort ( key = ( lambda snapshot : snapshot . timestamp ) ) #NEWLINE# pids = set ( ( snapshot . pid for snapshot in snapshots ) ) #NEWLINE# show_pid = ( len ( pids ) > 1 ) #NEWLINE# if show_pid : #NEWLINE# #INDENT# pids = ', ' . join ( map ( str , sorted ( pids ) ) ) #NEWLINE# print ( ( 'WARNING: Traces generated by different processes: %s' % pids ) ) #NEWLINE# print ( '' ) #NEWLINE# #UNINDENT# top = DisplayTop ( options . number ) #NEWLINE# top . filename_parts = options . filename_parts #NEWLINE# top . show_average = ( not top . hide_average ) #NEWLINE# top . show_count = ( not options . hide_count ) #NEWLINE# top . show_lineno = options . line_number #NEWLINE# top . show_size = ( not options . hide_size ) #NEWLINE# top . compare_with_previous = ( not options . first ) #NEWLINE# if options . color : #NEWLINE# #INDENT# top . color = True #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if options . no_color : #NEWLINE# #INDENT# top . color = False #NEWLINE# #UNINDENT# #UNINDENT# for snapshot in snapshots : #NEWLINE# #INDENT# snapshot . display ( top , show_pid = show_pid ) #NEWLINE# #UNINDENT# print ( ( '%s snapshots' % len ( snapshots ) ) )