Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(818)

Unified Diff: systrace/systrace/tracing_agents/ftrace_agent.py

Issue 2276263003: Pass in custom options to Systrace agents (Closed) Base URL: https://chromium.googlesource.com/external/github.com/catapult-project/catapult.git@master
Patch Set: Rebase Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: systrace/systrace/tracing_agents/ftrace_agent.py
diff --git a/systrace/systrace/tracing_agents/ftrace_agent.py b/systrace/systrace/tracing_agents/ftrace_agent.py
index da814916ac8614f8c97a6d3b640dbb9a5ac71fdb..bddeae5467d3cfbc73a1617f17cb14e0545a1adf 100644
--- a/systrace/systrace/tracing_agents/ftrace_agent.py
+++ b/systrace/systrace/tracing_agents/ftrace_agent.py
@@ -2,6 +2,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+import optparse
import os
import py_utils
@@ -87,8 +88,8 @@ all_categories = {
}
-def try_create_agent(options):
- if options.target != 'linux':
+def try_create_agent(config):
+ if config.target != 'linux':
return False
return FtraceAgent(FtraceAgentIo)
@@ -98,25 +99,51 @@ def list_categories(_):
agent._print_avail_categories()
+class FtraceConfig(tracing_agents.TracingConfig):
+ def __init__(self, ftrace_categories, target, trace_buf_size, fix_threads,
+ fix_tgids, fix_circular):
+ tracing_agents.TracingConfig.__init__(self)
+ self.ftrace_categories = ftrace_categories
+ self.target = target
+ self.trace_buf_size = trace_buf_size
+ self.fix_threads = fix_threads
+ self.fix_tgids = fix_tgids
+ self.fix_circular = fix_circular
+
+
+def add_options(parser):
+ options = optparse.OptionGroup(parser, 'Ftrace options')
+ options.add_option('--ftrace-categories', dest='ftrace_categories',
+ help='Select ftrace categories with a comma-delimited '
+ 'list, e.g. --ftrace-categories=cat1,cat2,cat3')
+ return options
+
+
+def get_config(options):
+ return FtraceConfig(options.ftrace_categories, options.target,
+ options.trace_buf_size, options.fix_threads,
+ options.fix_tgids, options.fix_circular)
+
+
class FtraceAgent(tracing_agents.TracingAgent):
def __init__(self, fio=FtraceAgentIo):
"""Initialize a systrace agent.
Args:
- options: The command-line options.
+ config: The command-line config.
categories: The trace categories to capture.
"""
super(FtraceAgent, self).__init__()
self._fio = fio
- self._options = None
+ self._config = None
self._categories = None
def _get_trace_buffer_size(self):
buffer_size = 4096
- if ((self._options.trace_buf_size is not None)
- and (self._options.trace_buf_size > 0)):
- buffer_size = self._options.trace_buf_size
+ if ((self._config.trace_buf_size is not None)
+ and (self._config.trace_buf_size > 0)):
+ buffer_size = self._config.trace_buf_size
return buffer_size
def _fix_categories(self, categories):
@@ -132,11 +159,11 @@ class FtraceAgent(tracing_agents.TracingAgent):
if self._is_category_available(x)]
@py_utils.Timeout(tracing_agents.START_STOP_TIMEOUT)
- def StartAgentTracing(self, options, categories, timeout=None):
+ def StartAgentTracing(self, config, timeout=None):
"""Start tracing.
"""
- self._options = options
- categories = self._fix_categories(categories)
+ self._config = config
+ categories = self._fix_categories(config.ftrace_categories)
self._fio.writeFile(FT_BUFFER_SIZE,
str(self._get_trace_buffer_size()))
self._fio.writeFile(FT_CLOCK, 'global')
@@ -168,11 +195,11 @@ class FtraceAgent(tracing_agents.TracingAgent):
self._fio.writeFile(FT_TRACE_ON, '0')
for category in self._categories:
self._category_disable(category)
- if self._options.fix_threads:
+ if self._config.fix_threads:
print "WARN: thread name fixing is not yet supported."
- if self._options.fix_tgids:
+ if self._config.fix_tgids:
print "WARN: tgid fixing is not yet supported."
- if self._options.fix_circular:
+ if self._config.fix_circular:
print "WARN: circular buffer fixups are not yet supported."
return True
@@ -212,7 +239,7 @@ class FtraceAgent(tracing_agents.TracingAgent):
def _print_avail_categories(self):
avail = self._avail_categories()
if len(avail):
- print "tracing options:"
+ print "tracing config:"
for category in self._avail_categories():
desc = all_categories[category]["desc"]
print "{0: <16}".format(category), ": ", desc

Powered by Google App Engine
This is Rietveld 408576698