File tree Expand file tree Collapse file tree 1 file changed +11
-8
lines changed Expand file tree Collapse file tree 1 file changed +11
-8
lines changed Original file line number Diff line number Diff line change
1
+ import atexit
2
+ import cProfile
1
3
import logging
2
4
import os
3
- import cProfile
4
5
import pstats
5
6
from datetime import datetime
6
7
7
- import atexit
8
-
9
8
__LOG_DIR = os .path .expanduser ("~/.local/share/vectorcode/logs/" )
10
9
11
10
logger = logging .getLogger (name = __name__ )
@@ -29,10 +28,10 @@ def finish():
29
28
)
30
29
__profiler .dump_stats (stats_file )
31
30
print (f"cProfile stats saved to: { stats_file } " )
32
-
31
+
33
32
# Print summary stats
34
33
stats = pstats .Stats (__profiler )
35
- stats .sort_stats (' cumulative' )
34
+ stats .sort_stats (" cumulative" )
36
35
stats .print_stats (20 )
37
36
except Exception as e :
38
37
logger .warning (f"Failed to save cProfile output: { e } " )
@@ -41,7 +40,7 @@ def finish():
41
40
def enable ():
42
41
"""Enable cProfile-based profiling and crash debugging"""
43
42
global __profiler
44
-
43
+
45
44
try :
46
45
_ensure_log_dir ()
47
46
@@ -50,12 +49,16 @@ def enable():
50
49
__profiler .enable ()
51
50
atexit .register (finish )
52
51
logger .info ("cProfile profiling enabled successfully" )
53
-
52
+
54
53
try :
55
54
import coredumpy # noqa: F401
55
+
56
56
logger .info ("coredumpy crash debugging enabled successfully" )
57
+ coredumpy .patch_except (directory = __LOG_DIR )
57
58
except Exception as e :
58
- logger .warning (f"Crash debugging will not be available. Failed to import coredumpy: { e } " )
59
+ logger .warning (
60
+ f"Crash debugging will not be available. Failed to import coredumpy: { e } "
61
+ )
59
62
60
63
except Exception as e :
61
64
logger .error (f"Failed to initialize cProfile: { e } " )
You can’t perform that action at this time.
0 commit comments