4444
4545
4646MULTIPLICATION_SIGN = chr (0xd7 )
47+ timeFormat = "%.7g"
4748
4849
4950def times (x ):
@@ -52,6 +53,9 @@ def times(x):
5253def percentage (p ):
5354 return "%.02f%%" % (p * 100.0 ,)
5455
56+ def fmttime (t ):
57+ return timeFormat % t
58+
5559def add (a , b ):
5660 return a + b
5761
@@ -112,7 +116,7 @@ def __str__(self):
112116 return 'unspecified event %s' % self .event .name
113117
114118
115- class Event ( object ) :
119+ class Event :
116120 """Describe a kind of event, and its basic operations."""
117121
118122 def __init__ (self , name , null , aggregator , formatter = str ):
@@ -124,12 +128,6 @@ def __init__(self, name, null, aggregator, formatter = str):
124128 def __repr__ (self ):
125129 return self .name
126130
127- def __eq__ (self , other ):
128- return self is other
129-
130- def __hash__ (self ):
131- return id (self )
132-
133131 def null (self ):
134132 return self ._null
135133
@@ -159,9 +157,9 @@ def format(self, val):
159157# Used only when totalMethod == callstacks
160158TOTAL_SAMPLES = Event ("Samples" , 0 , add , times )
161159
162- TIME = Event ("Time" , 0.0 , add , lambda x : '(' + str (x ) + ')' )
160+ TIME = Event ("Time" , 0.0 , add , lambda x : '(' + fmttime (x ) + ')' )
163161TIME_RATIO = Event ("Time ratio" , 0.0 , add , lambda x : '(' + percentage (x ) + ')' )
164- TOTAL_TIME = Event ("Total time" , 0.0 , fail )
162+ TOTAL_TIME = Event ("Total time" , 0.0 , fail , fmttime )
165163TOTAL_TIME_RATIO = Event ("Total time ratio" , 0.0 , fail , percentage )
166164
167165labels = {
@@ -175,7 +173,7 @@ def format(self, val):
175173totalMethod = 'callratios'
176174
177175
178- class Object ( object ) :
176+ class Object :
179177 """Base class for all objects in profile which can store events."""
180178
181179 def __init__ (self , events = None ):
@@ -184,12 +182,6 @@ def __init__(self, events=None):
184182 else :
185183 self .events = events
186184
187- def __hash__ (self ):
188- return id (self )
189-
190- def __eq__ (self , other ):
191- return self is other
192-
193185 def __lt__ (self , other ):
194186 return id (self ) < id (other )
195187
@@ -3632,7 +3624,7 @@ def naturalJoin(values):
36323624def main (argv = sys .argv [1 :]):
36333625 """Main program."""
36343626
3635- global totalMethod
3627+ global totalMethod , timeFormat
36363628
36373629 formatNames = list (formats .keys ())
36383630 formatNames .sort ()
@@ -3697,6 +3689,10 @@ def main(argv=sys.argv[1:]):
36973689 action = "store_true" ,
36983690 dest = "show_samples" , default = False ,
36993691 help = "show function samples" )
3692+ optparser .add_option (
3693+ '--time-format' ,
3694+ default = timeFormat ,
3695+ help = "format to use for showing time values [default: %default]" )
37003696 optparser .add_option (
37013697 '--node-label' , metavar = 'MEASURE' ,
37023698 type = 'choice' , choices = labelNames ,
@@ -3785,6 +3781,7 @@ def main(argv=sys.argv[1:]):
37853781 theme .skew = options .theme_skew
37863782
37873783 totalMethod = options .totalMethod
3784+ timeFormat = options .time_format
37883785
37893786 try :
37903787 Format = formats [options .format ]
0 commit comments