• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2
3# Copyright 2016 The Chromium Authors. All rights reserved.
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6
7'''Implementation of tracing controller for systrace. This class creates the
8necessary tracing agents for systrace, runs them, and outputs the results
9as an HTML or JSON file.'''
10
11from systrace import output_generator
12from systrace import tracing_controller
13from systrace.tracing_agents import android_process_data_agent
14from systrace.tracing_agents import android_cgroup_agent
15from systrace.tracing_agents import atrace_agent
16from systrace.tracing_agents import atrace_from_file_agent
17from systrace.tracing_agents import atrace_process_dump
18from systrace.tracing_agents import ftrace_agent
19from systrace.tracing_agents import walt_agent
20
21AGENT_MODULES = [android_process_data_agent, android_cgroup_agent,
22                 atrace_agent, atrace_from_file_agent, atrace_process_dump,
23                 ftrace_agent, walt_agent]
24
25class SystraceRunner(object):
26  def __init__(self, script_dir, options):
27    """Constructor.
28
29    Args:
30        script_dir: Directory containing the trace viewer script
31                    (systrace_trace_viewer.html)
32        options: Object containing command line options.
33    """
34    # Parse command line arguments and create agents.
35    self._script_dir = script_dir
36    self._out_filename = options.output_file
37    agents_with_config = tracing_controller.CreateAgentsWithConfig(
38        options, AGENT_MODULES)
39    controller_config = tracing_controller.GetControllerConfig(options)
40
41    # Set up tracing controller.
42    self._tracing_controller = tracing_controller.TracingController(
43        agents_with_config, controller_config)
44
45  def StartTracing(self):
46    self._tracing_controller.StartTracing()
47
48  def StopTracing(self):
49    self._tracing_controller.StopTracing()
50
51  def OutputSystraceResults(self, write_json=False):
52    """Output the results of systrace to a file.
53
54    If output is necessary, then write the results of systrace to either (a)
55    a standalone HTML file, or (b) a json file which can be read by the
56    trace viewer.
57
58    Args:
59       write_json: Whether to output to a json file (if false, use HTML file)
60    """
61    print 'Tracing complete, writing results'
62    if write_json:
63      result = output_generator.GenerateJSONOutput(
64                  self._tracing_controller.all_results,
65                  self._out_filename)
66    else:
67      result = output_generator.GenerateHTMLOutput(
68                  self._tracing_controller.all_results,
69                  self._out_filename)
70    print '\nWrote trace %s file: file://%s\n' % (('JSON' if write_json
71                                                   else 'HTML'), result)
72