9 __doc__ =
"""py-module to hold a few tools and utilities to help debugging
10 configurables and/or Athena application.
16 """Class to hold the stage at which the user asked to hook the debugger
19 allowed_values = (
"conf",
"init",
"exec",
"fini" )
23 """debugging helper, hooks debugger to running interpreter process
26 pid = os.spawnvp(os.P_NOWAIT,
27 debugger, [debugger,
'-q',
'python',
str(os.getpid())])
34 os.waitpid( pid, os.WNOHANG )
39 """Same than for hookDebugger: spawn strace and attach to the running
43 if out
is None: out =
'athena.strace.log.%i' % os.getpid()
44 if isinstance(out, io.IOBase):
46 elif not isinstance(out,str):
47 raise TypeError(
'argument 0 needs to be either a file or a filename')
49 pid = os.spawnvp(os.P_NOWAIT,
52 '-p',
str(os.getpid()),
60 os.waitpid( pid, os.WNOHANG )
66 """On kernels with Yama enabled, ptrace may not work by default on processes
67 which are not decendants of the tracing process. Among other things, that
68 causes the way we attach the debugger to fail. However, we can disable this
69 on a per-process basis. Do that here.
71 See https://www.kernel.org/doc/Documentation/security/Yama.txt and prctl(2).
77 if not os.path.exists (
'/proc/sys/kernel/yama/ptrace_scope'):
return
80 with open(
'/proc/sys/kernel/yama/ptrace_scope')
as f:
81 if f.readline().strip() ==
'0':
85 from ctypes
import CDLL
86 libc = CDLL(
"libc.so.6")
89 libc.prctl (0x59616d61, 0xffffffffffffffff)
95 """Save python profile data of the default athena profiler instance
96 into filename (.txt or .pkl format).
98 from AthenaCommon.Logging
import log
102 profiler = cProfile._athena_python_profiler
104 if filename.endswith(
".txt"):
105 stats = pstats.Stats(profiler, stream=
open(filename,
'w'))
106 stats.strip_dirs().sort_stats(
"time").print_stats()
107 log.info(
"Python profile summary stored in %s", filename)
109 profiler.dump_stats(filename)
110 log.info(
"Python profile stored in %s", filename)
114 """Run script with the given trace level"""
122 ignore_dirs = [x
for x
in sys.path
if x.find(
"ROOT")!=-1]
123 ignore_dirs.append(sys.prefix)
125 ignore_mods += [
'_db',
'__init__',
'_configurables',
'GaudiHandles',
'six']
129 'Configurable',
'Configurables',
'PropertyProxy',
'DataHandle',
'ConfigurableDb',
130 'ConfigurableMeta',
'CfgMgr',
132 'ComponentAccumulator',
'Logging',
'AthConfigFlags',
'AllConfigFlags',
'Deduplication',
133 'semantics',
'AccumulatorCache',
'DebuggingContext',
'AtlasSemantics',
'ComponentFactory',
134 'LegacySupport',
'ItemListSemantics'
138 tracer = trace.Trace(ignoredirs=ignore_dirs, ignoremods=ignore_mods)
140 with io.open_code(script)
as f:
141 code = compile(f.read(), script,
'exec')