Skip to content

Commit

Permalink
revise timemeasurement
Browse files Browse the repository at this point in the history
  • Loading branch information
dtrai2 committed Oct 18, 2023
1 parent f97471d commit df6890a
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions logprep/util/time_measurement.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""This module is used to measure the execution time of functions and add the results to events."""

from time import time


class TimeMeasurement:
"""Measures the execution time of functions and adds the results to events via a decorator."""
Expand All @@ -12,14 +10,11 @@ def measure_time():

def inner_decorator(func):
def inner(*args, **kwargs): # nosemgrep
begin = time()
result = func(*args, **kwargs)
end = time()
processing_time = end - begin
caller = args[0]
if func.__name__ in ("_process_rule_tree", "_process_rule"):
caller = args[-1]
caller.metrics.processing_time_per_event += processing_time
with caller.metrics.processing_time_per_event.time():
result = func(*args, **kwargs)
return result

return inner
Expand Down

0 comments on commit df6890a

Please sign in to comment.