mirror of
https://github.com/azaion/gps-denied-desktop.git
synced 2026-04-23 01:36:35 +00:00
initial structure implemented
docs -> _docs
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import time
|
||||
from typing import Optional
|
||||
from contextlib import contextmanager
|
||||
|
||||
|
||||
class PerformanceMonitor:
|
||||
def __init__(self):
|
||||
self._timings: dict[str, list[float]] = {}
|
||||
self._counters: dict[str, int] = {}
|
||||
|
||||
@contextmanager
|
||||
def measure(self, operation: str):
|
||||
start = time.perf_counter()
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
elapsed = time.perf_counter() - start
|
||||
if operation not in self._timings:
|
||||
self._timings[operation] = []
|
||||
self._timings[operation].append(elapsed)
|
||||
|
||||
def increment(self, counter: str, value: int = 1) -> None:
|
||||
if counter not in self._counters:
|
||||
self._counters[counter] = 0
|
||||
self._counters[counter] += value
|
||||
|
||||
def get_average(self, operation: str) -> Optional[float]:
|
||||
if operation not in self._timings or not self._timings[operation]:
|
||||
return None
|
||||
return sum(self._timings[operation]) / len(self._timings[operation])
|
||||
|
||||
def get_statistics(self, operation: str) -> Optional[dict]:
|
||||
raise NotImplementedError
|
||||
|
||||
def get_counter(self, counter: str) -> int:
|
||||
return self._counters.get(counter, 0)
|
||||
|
||||
def reset(self) -> None:
|
||||
self._timings.clear()
|
||||
self._counters.clear()
|
||||
|
||||
def get_report(self) -> dict:
|
||||
raise NotImplementedError
|
||||
|
||||
Reference in New Issue
Block a user