Skip to content

Commit

Permalink
Merge pull request #3741 from malliwi88/fix/profilerUnits
Browse files Browse the repository at this point in the history
PR: Show time units in Profiler
  • Loading branch information
ccordoba12 authored Dec 18, 2016
2 parents e654501 + 5ead5b5 commit 7756b78
Showing 1 changed file with 39 additions and 11 deletions.
50 changes: 39 additions & 11 deletions spyder_profiler/widgets/profilergui.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,27 +495,57 @@ def function_info(self, functionKey):
node_type = 'constructor'
file_and_line = '%s : %d' % (filename, line_number)
return filename, line_number, function_name, file_and_line, node_type


def format_measure(self, measure):
"""Get format and units for data coming from profiler task."""
# For number of calls
if isinstance(measure, int):
return to_text_string(measure)

# For time measurements
if 1.e-9 < measure <= 1.e-6:
measure = u"{0:.2f} ns".format(measure / 1.e-9)
elif 1.e-6 < measure <= 1.e-3:
measure = u"{0:.2f} us".format(measure / 1.e-6)
elif 1.e-3 < measure <= 1:
measure = u"{0:.2f} ms".format(measure / 1.e-3)
elif 1 < measure <= 60:
measure = u"{0:.2f} sec".format(measure)
elif 60 < measure <= 3600:
m, s = divmod(measure, 3600)
if s > 60:
m, s = divmod(measure, 60)
s = to_text_string(s).split(".")[-1]
measure = u"{0:.0f}.{1:.2s} min".format(m, s)
else:
h, m = divmod(measure, 3600)
if m > 60:
m /= 60
measure = u"{0:.0f}h:{1:.0f}min".format(h, m)
return measure

def color_string(self, args):
x, format = args
x, fmt = args
diff_str = ""
color = "black"

if len(x) == 2 and self.compare_file is not None:
difference = x[0] - x[1]
if difference < 0:
diff_str = "".join(['',format[1] % difference])
diff_str = "".join(['', fmt[1] % self.format_measure(difference)])
color = "green"
elif difference > 0:
diff_str = "".join(['+',format[1] % difference])
diff_str = "".join(['+', fmt[1] % self.format_measure(difference)])
color = "red"
return [format[0] % x[0], [diff_str, color]]

return [fmt[0] % self.format_measure(x[0]), [diff_str, color]]

def format_output(self,child_key):
def format_output(self, child_key):
""" Formats the data"""
if True:
data = [x.stats.get(child_key,[0,0,0,0,0]) for x in self.stats1]
return map(self.color_string,zip(list(zip(*data))[1:4], [["%i"]*2, ["%.3f","%.3f"], ["%.3f","%.3f"]]))
data = [x.stats.get(child_key, [0,0,0,0,0]) for x in self.stats1]
format_data = zip(list(zip(*data))[1:4],
[["%s"]*2, ["%s", "%s"], ["%s", "%s"]])
return (map(self.color_string, format_data))

def populate_tree(self, parentItem, children_list):
"""Recursive method to create each item (and associated data) in the tree."""
Expand All @@ -527,8 +557,6 @@ def populate_tree(self, parentItem, children_list):
((total_calls, total_calls_dif), (loc_time, loc_time_dif), (cum_time,
cum_time_dif)) = self.format_output(child_key)

(primcalls, total_calls, loc_time, cum_time, callers
) = self.stats[child_key]
child_item = TreeWidgetItem(parentItem)
self.item_list.append(child_item)
self.set_item_data(child_item, filename, line_number)
Expand Down

0 comments on commit 7756b78

Please sign in to comment.