Skip to content

Commit f491c0b

Browse files
committed
fix(cli): make sure to enable coredumpy when available.
1 parent 41a8b11 commit f491c0b

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/vectorcode/debugging.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1+
import atexit
2+
import cProfile
13
import logging
24
import os
3-
import cProfile
45
import pstats
56
from datetime import datetime
67

7-
import atexit
8-
98
__LOG_DIR = os.path.expanduser("~/.local/share/vectorcode/logs/")
109

1110
logger = logging.getLogger(name=__name__)
@@ -29,10 +28,10 @@ def finish():
2928
)
3029
__profiler.dump_stats(stats_file)
3130
print(f"cProfile stats saved to: {stats_file}")
32-
31+
3332
# Print summary stats
3433
stats = pstats.Stats(__profiler)
35-
stats.sort_stats('cumulative')
34+
stats.sort_stats("cumulative")
3635
stats.print_stats(20)
3736
except Exception as e:
3837
logger.warning(f"Failed to save cProfile output: {e}")
@@ -41,7 +40,7 @@ def finish():
4140
def enable():
4241
"""Enable cProfile-based profiling and crash debugging"""
4342
global __profiler
44-
43+
4544
try:
4645
_ensure_log_dir()
4746

@@ -50,12 +49,16 @@ def enable():
5049
__profiler.enable()
5150
atexit.register(finish)
5251
logger.info("cProfile profiling enabled successfully")
53-
52+
5453
try:
5554
import coredumpy # noqa: F401
55+
5656
logger.info("coredumpy crash debugging enabled successfully")
57+
coredumpy.patch_except(directory=__LOG_DIR)
5758
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+
)
5962

6063
except Exception as e:
6164
logger.error(f"Failed to initialize cProfile: {e}")

0 commit comments

Comments
 (0)