Skip to content

Commit

Permalink
Add tracing feature
Browse files Browse the repository at this point in the history
  • Loading branch information
joezuntz committed Sep 13, 2024
1 parent a3f65f8 commit c5d17f3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
10 changes: 10 additions & 0 deletions ceci/stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from . import errors
from .monitor import MemoryMonitor
from .config import StageParameter, StageConfig, cast_to_streamable
from .utils import activate_tracing

SERIAL = "serial"
MPI_PARALLEL = "mpi"
Expand Down Expand Up @@ -610,6 +611,12 @@ def parse_command_line(cls, cmd=None):
help="Report memory use. Argument gives interval in seconds between reports",
)

parser.add_argument(
"--trace",
action="store_true",
help="Enable sending a signal to the process that prints a trace wherever it is",
)

# Error message we will return if --mpi used on a non-supported
# stage.
mpi_err = (
Expand Down Expand Up @@ -668,6 +675,9 @@ def execute(cls, args, comm=None):
if args.memmon: # pragma: no cover
monitor = MemoryMonitor.start_in_thread(interval=args.memmon)

if args.trace:
activate_tracing(stage._rank)

# Now we try to see if the validation step has been changed,
# if it has then we will run the validation step, and raise any errors
try:
Expand Down
8 changes: 8 additions & 0 deletions ceci/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from contextlib import contextmanager
import sys
import os
import signal
import faulthandler


def add_python_path(path, start):
Expand Down Expand Up @@ -107,3 +109,9 @@ def embolden(text):
Emboldened text
"""
return "\033[1m" + text + "\033[0m"


def activate_tracing(rank):
pid = os.getpid()
print(f"Activating trace mode for process {rank}. Trigger trace using command: kill -s {signal.SIGUSR1} {pid}")
faulthandler.register(signal.SIGUSR1)

0 comments on commit c5d17f3

Please sign in to comment.