Skip to content

Commit

Permalink
profiler - protection against divide by zero on zero time sections
Browse files Browse the repository at this point in the history
Signed-off-by: davidoh <[email protected]>
  • Loading branch information
davidohana committed Jul 17, 2022
1 parent 7e340cd commit de2e206
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions drain3/simple_profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def end_section(self, name=""):
raise ValueError(f"Section {section_name} was not started")

took_sec = now - section.start_time_sec
if self.reset_after_sample_count > 0 and section.sample_count == self.reset_after_sample_count:
if 0 < self.reset_after_sample_count == section.sample_count:
section.sample_count_batch = 0
section.total_time_sec_batch = 0

Expand Down Expand Up @@ -132,11 +132,18 @@ def to_string(self, enclosing_time_sec: int, include_batch_rates: bool):
took_sec_text += f" ({100 * self.total_time_sec / enclosing_time_sec:>6.2f}%)"

ms_per_k_samples = f"{1000000 * self.total_time_sec / self.sample_count: 7.2f}"
samples_per_sec = f"{self.sample_count / self.total_time_sec: 15,.2f}"

if self.total_time_sec > 0:
samples_per_sec = f"{self.sample_count / self.total_time_sec: 15,.2f}"
else:
samples_per_sec = "N/A"

if include_batch_rates:
ms_per_k_samples += f" ({1000000 * self.total_time_sec_batch / self.sample_count_batch: 7.2f})"
samples_per_sec += f" ({self.sample_count_batch / self.total_time_sec_batch: 15,.2f})"
if self.total_time_sec_batch > 0:
samples_per_sec += f" ({self.sample_count_batch / self.total_time_sec_batch: 15,.2f})"
else:
samples_per_sec += " (N/A)"

return f"{self.section_name: <15}: took {took_sec_text}, " \
f"{self.sample_count: >10,} samples, " \
Expand Down

0 comments on commit de2e206

Please sign in to comment.