44
44
45
45
46
46
MULTIPLICATION_SIGN = chr (0xd7 )
47
+ timeFormat = "%.7g"
47
48
48
49
49
50
def times (x ):
@@ -52,6 +53,9 @@ def times(x):
52
53
def percentage (p ):
53
54
return "%.02f%%" % (p * 100.0 ,)
54
55
56
+ def fmttime (t ):
57
+ return timeFormat % t
58
+
55
59
def add (a , b ):
56
60
return a + b
57
61
@@ -112,7 +116,7 @@ def __str__(self):
112
116
return 'unspecified event %s' % self .event .name
113
117
114
118
115
- class Event ( object ) :
119
+ class Event :
116
120
"""Describe a kind of event, and its basic operations."""
117
121
118
122
def __init__ (self , name , null , aggregator , formatter = str ):
@@ -124,12 +128,6 @@ def __init__(self, name, null, aggregator, formatter = str):
124
128
def __repr__ (self ):
125
129
return self .name
126
130
127
- def __eq__ (self , other ):
128
- return self is other
129
-
130
- def __hash__ (self ):
131
- return id (self )
132
-
133
131
def null (self ):
134
132
return self ._null
135
133
@@ -159,9 +157,9 @@ def format(self, val):
159
157
# Used only when totalMethod == callstacks
160
158
TOTAL_SAMPLES = Event ("Samples" , 0 , add , times )
161
159
162
- TIME = Event ("Time" , 0.0 , add , lambda x : '(' + str (x ) + ')' )
160
+ TIME = Event ("Time" , 0.0 , add , lambda x : '(' + fmttime (x ) + ')' )
163
161
TIME_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 )
165
163
TOTAL_TIME_RATIO = Event ("Total time ratio" , 0.0 , fail , percentage )
166
164
167
165
labels = {
@@ -175,7 +173,7 @@ def format(self, val):
175
173
totalMethod = 'callratios'
176
174
177
175
178
- class Object ( object ) :
176
+ class Object :
179
177
"""Base class for all objects in profile which can store events."""
180
178
181
179
def __init__ (self , events = None ):
@@ -184,12 +182,6 @@ def __init__(self, events=None):
184
182
else :
185
183
self .events = events
186
184
187
- def __hash__ (self ):
188
- return id (self )
189
-
190
- def __eq__ (self , other ):
191
- return self is other
192
-
193
185
def __lt__ (self , other ):
194
186
return id (self ) < id (other )
195
187
@@ -3632,7 +3624,7 @@ def naturalJoin(values):
3632
3624
def main (argv = sys .argv [1 :]):
3633
3625
"""Main program."""
3634
3626
3635
- global totalMethod
3627
+ global totalMethod , timeFormat
3636
3628
3637
3629
formatNames = list (formats .keys ())
3638
3630
formatNames .sort ()
@@ -3697,6 +3689,10 @@ def main(argv=sys.argv[1:]):
3697
3689
action = "store_true" ,
3698
3690
dest = "show_samples" , default = False ,
3699
3691
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]" )
3700
3696
optparser .add_option (
3701
3697
'--node-label' , metavar = 'MEASURE' ,
3702
3698
type = 'choice' , choices = labelNames ,
@@ -3785,6 +3781,7 @@ def main(argv=sys.argv[1:]):
3785
3781
theme .skew = options .theme_skew
3786
3782
3787
3783
totalMethod = options .totalMethod
3784
+ timeFormat = options .time_format
3788
3785
3789
3786
try :
3790
3787
Format = formats [options .format ]
0 commit comments