mirror of
https://github.com/linyqh/NarratoAI.git
synced 2025-12-11 18:42:49 +00:00
24 lines
642 B
Python
24 lines
642 B
Python
import time
|
|
from loguru import logger
|
|
|
|
try:
|
|
import psutil
|
|
ENABLE_PERFORMANCE_MONITORING = True
|
|
except ImportError:
|
|
ENABLE_PERFORMANCE_MONITORING = False
|
|
logger.warning("psutil not installed. Performance monitoring is disabled.")
|
|
|
|
def monitor_performance():
|
|
if not ENABLE_PERFORMANCE_MONITORING:
|
|
return {'execution_time': 0, 'memory_usage': 0}
|
|
|
|
start_time = time.time()
|
|
try:
|
|
memory_usage = psutil.Process().memory_info().rss / 1024 / 1024 # MB
|
|
except:
|
|
memory_usage = 0
|
|
|
|
return {
|
|
'execution_time': time.time() - start_time,
|
|
'memory_usage': memory_usage
|
|
} |