Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR: Show time units in Profiler #3741

Merged
merged 16 commits into from
Dec 18, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was this doing and why did you remove it?


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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also this?


(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