Browse Source

feat(performance_stats): improve function identification in execution time logging

- Enhance the logging of execution times by adding more detailed function identification
- Implement class name and module name inclusion for better traceability
myhloli 7 months ago
parent
commit
978ef41cdd
1 changed files with 12 additions and 1 deletions
  1. 12 1
      magic_pdf/libs/performance_stats.py

+ 12 - 1
magic_pdf/libs/performance_stats.py

@@ -48,7 +48,18 @@ def measure_time(func):
         start_time = time.time()
         result = func(*args, **kwargs)
         execution_time = time.time() - start_time
-        PerformanceStats.add_execution_time(func.__name__, execution_time)
+
+        # 获取更详细的函数标识
+        if hasattr(func, "__self__"):  # 实例方法
+            class_name = func.__self__.__class__.__name__
+            full_name = f"{class_name}.{func.__name__}"
+        elif hasattr(func, "__qualname__"):  # 类方法或静态方法
+            full_name = func.__qualname__
+        else:
+            module_name = func.__module__
+            full_name = f"{module_name}.{func.__name__}"
+
+        PerformanceStats.add_execution_time(full_name, execution_time)
         return result
 
     return wrapper