File size: 545 Bytes
c0dbd21
 
 
 
87aa1c0
c0dbd21
 
 
 
 
 
 
 
 
 
 
 
87aa1c0
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from contextlib import contextmanager
import time
import mlflow


@contextmanager
def profile_step(expr_name: str, prometheus_logger, camera_id, frame_count=None):
    """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)
        mlflow.log_metric(
            expr_name,
            duration,
            frame_count,
        )