Skip to content

Commit 8d3dbc6

Browse files
authored
Handle possible division by zero in _calc_p (#15)
This fixes ZeroDivisionError raised by _calc_timeline when the last rendered template is measured to take 0.0 seconds (i.e. its 'start' is equal to its 'end'). In this case, we get self.t_max == start == end, and we divide by zero when calculating rel_duration_p.
1 parent b39dc11 commit 8d3dbc6

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

template_profiler_panel/panels/template.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ def disable_instrumentation(self):
129129
self.is_enabled = False
130130

131131
def _calc_p(self, part, whole):
132-
return (part / whole) * 100.0
132+
# return the percentage of part or 100% if whole is zero
133+
return (part / whole) * 100.0 if whole else 100.0
133134

134135
def _calc_timeline(self, start, end):
135136
result = {}

0 commit comments

Comments
 (0)