public inbox for gentoo-catalyst@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-catalyst] [PATCH 1/2] main: add a --trace option
@ 2015-11-23 12:07 Mike Frysinger
  2015-11-23 12:07 ` [gentoo-catalyst] [PATCH 2/2] main: add a --profile option Mike Frysinger
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Mike Frysinger @ 2015-11-23 12:07 UTC (permalink / raw
  To: gentoo-catalyst

This helps a lot with debugging as you can quickly get a transcript
of the python code paths that are taken by catalyst.
---
 catalyst/main.py | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)

diff --git a/catalyst/main.py b/catalyst/main.py
index f48293e..3550809 100644
--- a/catalyst/main.py
+++ b/catalyst/main.py
@@ -170,6 +170,11 @@ $ catalyst -f stage1-specfile.spec"""
 		dest='color', action='store_false',
 		help='never colorize output all the time (default: detect)')
 
+	group = parser.add_argument_group('Developer options')
+	group.add_argument('--trace',
+		default=False, action='store_true',
+		help='trace program output (akin to `sh -x`)')
+
 	group = parser.add_argument_group('Temporary file management')
 	group.add_argument('-a', '--clear-autoresume',
 		default=False, action='store_true',
@@ -203,10 +208,54 @@ $ catalyst -f stage1-specfile.spec"""
 	return parser
 
 
+def trace(func, *args, **kwargs):
+	"""Run |func| through the trace module (akin to `sh -x`)"""
+	import trace
+
+	# Ignore common system modules we use.
+	ignoremods = set((
+		'argparse',
+		'genericpath', 'gettext',
+		'locale',
+		'os',
+		'posixpath',
+		're',
+		'sre_compile', 'sre_parse', 'sys',
+		'tempfile', 'threading',
+		'UserDict',
+	))
+
+	# Ignore all the system modules.
+	ignoredirs = set(sys.path)
+	# But try to strip out the catalyst paths.
+	try:
+		ignoredirs.remove(os.path.dirname(os.path.dirname(
+			os.path.realpath(__file__))))
+	except KeyError:
+		pass
+
+	tracer = trace.Trace(
+		count=False,
+		trace=True,
+		timing=True,
+		ignoremods=ignoremods,
+		ignoredirs=ignoredirs)
+	return tracer.runfunc(func, *args, **kwargs)
+
+
 def main(argv):
+	"""The main entry point for frontends to use"""
 	parser = get_parser()
 	opts = parser.parse_args(argv)
 
+	if opts.trace:
+		return trace(_main, parser, opts)
+	else:
+		return _main(parser, opts)
+
+
+def _main(parser, opts):
+	"""The "main" main function so we can trace/profile."""
 	# Initialize the logger before anything else.
 	log_level = opts.log_level
 	if log_level is None:
-- 
2.6.2



^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-12-15 17:27 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-23 12:07 [gentoo-catalyst] [PATCH 1/2] main: add a --trace option Mike Frysinger
2015-11-23 12:07 ` [gentoo-catalyst] [PATCH 2/2] main: add a --profile option Mike Frysinger
2015-11-23 12:15   ` Mike Frysinger
2015-12-15 17:26   ` Brian Dolbec
2015-11-23 12:13 ` [gentoo-catalyst] [PATCH 1/2] main: add a --trace option Mike Frysinger
2015-12-15 17:26 ` Brian Dolbec

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox