Chromium Code Reviews| Index: systrace/systrace/tracing_agents/ftrace_agent.py |
| diff --git a/systrace/systrace/agents/ftrace_agent.py b/systrace/systrace/tracing_agents/ftrace_agent.py |
| similarity index 74% |
| rename from systrace/systrace/agents/ftrace_agent.py |
| rename to systrace/systrace/tracing_agents/ftrace_agent.py |
| index 758fc617e5e10dea6140501b7a7d678e6dbf49ce..ecff8605750fb1f2f14ff42500accac4d239e362 100644 |
| --- a/systrace/systrace/agents/ftrace_agent.py |
| +++ b/systrace/systrace/tracing_agents/ftrace_agent.py |
| @@ -6,8 +6,8 @@ import os |
| import sys |
| import time |
| -from systrace import systrace_agent |
| - |
| +from systrace.tracing_agents import TracingAgent |
| +from systrace.tracing_agents import TraceResults |
| class FtraceAgentIo(object): |
| @@ -83,6 +83,9 @@ all_categories = { |
| } |
| } |
| +def list_categories(options): |
| + agent = FtraceAgent(options, [], FtraceAgentIo) |
| + agent._print_avail_categories() |
| def try_create_agent(options, categories): |
| if options.target != 'linux': |
| @@ -90,7 +93,7 @@ def try_create_agent(options, categories): |
| return FtraceAgent(options, categories, FtraceAgentIo) |
| -class FtraceAgent(systrace_agent.SystraceAgent): |
| +class FtraceAgent(TracingAgent): |
| def __init__(self, options, categories, fio=FtraceAgentIo): |
|
Zhen Wang
2016/03/29 18:53:40
Do not pass in options and categories. Pass them i
alexandermont
2016/03/30 01:04:25
Done
|
| """Initialize a systrace agent. |
| @@ -103,9 +106,9 @@ class FtraceAgent(systrace_agent.SystraceAgent): |
| if not self._categories: |
| self._categories = ["sched"] |
| self._fio = fio |
| + self._options = options |
| self._categories = [x for x in self._categories |
| if self._is_category_available(x)] |
| - self._expect_trace = False |
| def _get_trace_buffer_size(self): |
| buffer_size = 4096 |
| @@ -121,68 +124,53 @@ class FtraceAgent(systrace_agent.SystraceAgent): |
| wait_time = self._options.trace_time |
| return wait_time |
| - def start(self): |
| + def _StartAgentTracing_func(self): |
| """Start tracing. |
| """ |
|
Zhen Wang
2016/03/29 18:53:40
Run self._fio.haveWritePermissions before actually
alexandermont
2016/03/30 01:04:25
Done
|
| - if self._options.list_categories or len(self._categories) == 0: |
| - self._expect_trace = False |
| - else: |
| - self._expect_trace = True |
| - |
| - self._fio.writeFile(FT_BUFFER_SIZE, str(self._get_trace_buffer_size())) |
| + self._fio.writeFile(FT_BUFFER_SIZE, str(self._get_trace_buffer_size())) |
| - self._fio.writeFile(FT_CLOCK, 'global') |
| - self._fio.writeFile(FT_TRACER, 'nop') |
| - self._fio.writeFile(FT_OVERWRITE, "0") |
| + self._fio.writeFile(FT_CLOCK, 'global') |
| + self._fio.writeFile(FT_TRACER, 'nop') |
| + self._fio.writeFile(FT_OVERWRITE, "0") |
| - # TODO: riandrews to push necessary patches for TGID option to upstream |
| - # linux kernel |
| - # self._fio.writeFile(FT_PRINT_TGID, '1') |
| + # TODO: riandrews to push necessary patches for TGID option to upstream |
| + # linux kernel |
| + # self._fio.writeFile(FT_PRINT_TGID, '1') |
| - for category in self._categories: |
| - self._category_enable(category) |
| + for category in self._categories: |
| + self._category_enable(category) |
| - self._fio.writeFile(FT_TRACE, '') |
| + self._fio.writeFile(FT_TRACE, '') |
| - print "starting tracing." |
| - sys.stdout.flush() |
| + print "starting tracing." |
| + sys.stdout.flush() |
| - self._fio.writeFile(FT_TRACE_ON, '1') |
| + self._fio.writeFile(FT_TRACE_ON, '1') |
| + return True |
| - def collect_result(self): |
| + def _StopAgentTracing_func(self): |
| """Collect the result of tracing. |
| This function will block while collecting the result. For sync mode, it |
| reads the data, e.g., from stdout, until it finishes. For async mode, it |
| blocks until the agent is stopped and the data is ready. |
| """ |
| - if self._options.list_categories or len(self._categories) == 0: |
| - self._print_avail_categories() |
| - else: |
| - try: |
| - time.sleep(self._get_trace_time()) |
| - except KeyboardInterrupt: |
| - pass |
| - self._fio.writeFile(FT_TRACE_ON, '0') |
| - for category in self._categories: |
| - self._category_disable(category) |
| - if self._options.fix_threads: |
| - print "WARN: thread name fixing is not yet supported." |
| - if self._options.fix_tgids: |
| - print "WARN: tgid fixing is not yet supported." |
| - if self._options.fix_circular: |
| - print "WARN: circular buffer fixups are not yet supported." |
| - |
| - def expect_trace(self): |
| - """Check if the agent is returning a trace or not. |
| - |
| - This will be determined in collect_result(). |
| - Returns: |
| - Whether the agent is expecting a trace or not. |
| - """ |
| - return self._expect_trace |
| + try: |
| + time.sleep(self._get_trace_time()) |
| + except KeyboardInterrupt: |
| + pass |
| + self._fio.writeFile(FT_TRACE_ON, '0') |
| + for category in self._categories: |
| + self._category_disable(category) |
| + if self._options.fix_threads: |
| + print "WARN: thread name fixing is not yet supported." |
| + if self._options.fix_tgids: |
| + print "WARN: tgid fixing is not yet supported." |
| + if self._options.fix_circular: |
| + print "WARN: circular buffer fixups are not yet supported." |
| + return True |
| - def get_trace_data(self): |
| + def _GetResults_func(self): |
| """Get the trace data. |
| Returns: |
| @@ -190,10 +178,13 @@ class FtraceAgent(systrace_agent.SystraceAgent): |
| """ |
| d = self._fio.readFile(FT_TRACE) |
| self._fio.writeFile(FT_BUFFER_SIZE, "1") |
| - return d |
| + return TraceResults('systemTraceEvents', d) |
| + |
| + def SupportsExplicitClockSync(self): |
| + return False |
| - def get_class_name(self): |
| - return 'trace-data' |
| + def RecordClockSyncMarker(self, sync_id, callback): |
| + raise NotImplementedError |
| def _is_category_available(self, category): |
| if category not in all_categories: |