File size: 637 Bytes
c0dbd21
 
 
 
87aa1c0
c0dbd21
605dd3b
 
 
 
 
 
 
c0dbd21
 
 
 
 
 
 
 
 
605dd3b
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from contextlib import contextmanager
import time
import mlflow


@contextmanager
def profile_step(
    expr_name: str,
    prometheus_logger,
    camera_id,
    frame_count=None,
    experiment: bool = False,
):
    """With statement utility to time block of code"""
    start_time = time.time()

    try:
        # Code inside with statement
        yield
    finally:
        duration = round(time.time() - start_time, 4)
        prometheus_logger.labels(camera_id).observe(duration)
        if experiment:
            mlflow.log_metric(
                expr_name,
                duration,
                frame_count,
            )