Spaces:
Paused
Paused
File size: 1,275 Bytes
188ec8d |
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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
import time
import os
import sys
# Ensure src is in path
current_dir = os.path.dirname(os.path.abspath(__file__))
project_root = os.path.dirname(current_dir)
sys.path.insert(0, os.path.join(project_root, "services", "ai-service", "src"))
from ai_med_extract.utils.benchmark import BenchmarkContext, BenchmarkLogger, benchmark_activity
@benchmark_activity("test_sleep_activity")
def test_sleep():
print("Testing sleep for 1 second...")
time.sleep(1.0)
print("Done sleeping.")
def main():
print(f"Running benchmark test in {os.getcwd()}")
# Test context manager directly
print("Testing Context Manager...")
with BenchmarkContext("test_context_block", meta={"type": "test"}) as bm:
time.sleep(0.5)
bm.meta["extra_info"] = "worked"
# Test decorator
print("Testing Decorator...")
test_sleep()
print("Test complete. Checking logs...")
log_file = "logs/benchmark.jsonl"
if os.path.exists(log_file):
print(f"Log file exists: {log_file}")
with open(log_file, "r") as f:
print("--- Log Content ---")
print(f.read())
print("-------------------")
else:
print(f"Log file NOT found at {log_file}")
if __name__ == "__main__":
main()
|