Skip to content

Commit

Permalink
Add dont_delete param for sample zero
Browse files Browse the repository at this point in the history
Record single metric sample value zero when dont_delete=True.
Default behavior is to consider the single sample metric value
zero as non-existing (dont_delete=False).
This should not be a problem for throughput metric class but it
might incorrectly generate post-processing metric files for other
classes like 'count' type, e.g. latency.
  • Loading branch information
rafaelfolco committed Nov 12, 2024
1 parent 57e7310 commit 818d364
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions python/toolbox/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def log_sample(this_file_id: str, desc: object, names: object, sample: object):
metric_data_fh[file_id] = lzma.open(metric_data_file, "wt")
stored_sample[idx] = sample.copy()

def finish_samples():
def finish_samples(dont_delete=False):
"""
Write the final metric data to disk and reset the global variables.
Expand All @@ -174,7 +174,8 @@ def finish_samples():
# All of the stored samples need to be written
for idx in range(0, len(stored_sample)):
if file_id in metric_data_fh.keys():
if stored_sample[idx]['value'] == 0 and idx not in num_written_samples.keys():
if (stored_sample[idx]['value'] == 0 and idx not in num_written_samples.keys() and
and dont_delete is False):
# This metric has only 1 sample and the value is 0, so it "did not do any work". Therefore, we can just
# not create this metric at all.
# TODO: This optimization might be better if the metric source/type could opt in/out of this.
Expand Down

0 comments on commit 818d364

Please sign in to comment.