def stopwatch()

in machine_learning/ml_infrastructure/inference-server-performance/client/locust/trtis_grpc_client.py [0:0]


def stopwatch(func):
    def wrapper(*args, **kwargs):
        previous_frame = inspect.currentframe().f_back
        _, _, name, _, _ = inspect.getframeinfo(previous_frame)

        start = time.time()
        result = None

        try:
            result = func(*args, **kwargs)
        except Exception as e:
            total = int((time.time() - start) * 1000)
            events.request_failure.fire(
                request_type="grpc", name=name, response_time=total,
                exception=e)
        else:
            total = int((time.time() - start) * 1000)
            events.request_success.fire(
                request_type="grpc", name=name, response_time=total,
                response_length=0)
        return result
    return wrapper