Exemplo n.º 1
0
    def testHtmlOutputGenerationFormatsMultipleTraces(self):
        trace_results = []
        with trace_data_module.TraceDataBuilder() as trace_data_builder:
            with open(ATRACE_DATA) as fp:
                atrace_data = fp.read()
            trace_results.append(
                trace_result.TraceResult('systemTraceEvents', atrace_data))
            trace_data_builder.AddTraceFor(trace_data_module.ATRACE_PART,
                                           atrace_data,
                                           allow_unstructured=True)

            with open(ATRACE_PROCESS_DUMP_DATA) as fp:
                atrace_process_dump_data = fp.read()
            trace_results.append(
                trace_result.TraceResult('atraceProcessDump',
                                         atrace_process_dump_data))
            trace_data_builder.AddTraceFor(
                trace_data_module.ATRACE_PROCESS_DUMP_PART,
                atrace_process_dump_data,
                allow_unstructured=True)

            with open(CGROUP_DUMP_DATA) as fp:
                cgroup_dump_data = fp.read()
            trace_results.append(
                trace_result.TraceResult('cgroupDump', cgroup_dump_data))
            trace_data_builder.AddTraceFor(trace_data_module.CGROUP_TRACE_PART,
                                           cgroup_dump_data,
                                           allow_unstructured=True)

            with open(COMBINED_PROFILE_CHROME_DATA) as fp:
                chrome_data = json.load(fp)
            trace_results.append(
                trace_result.TraceResult('traceEvents', chrome_data))
            trace_data_builder.AddTraceFor(trace_data_module.CHROME_TRACE_PART,
                                           chrome_data)

            trace_results.append(
                trace_result.TraceResult('systraceController', str({})))
            trace_data_builder.AddTraceFor(trace_data_module.TELEMETRY_PART,
                                           {})

            with tempfile_ext.NamedTemporaryDirectory() as temp_dir:
                data_builder_out = os.path.join(temp_dir, 'data_builder.html')
                output_generator_out = os.path.join(temp_dir,
                                                    'output_generator.html')
                output_generator.GenerateHTMLOutput(trace_results,
                                                    output_generator_out)
                trace_data_builder.Serialize(data_builder_out, 'Systrace')

                output_generator_md5sum = hashlib.md5(
                    open(output_generator_out, 'rb').read()).hexdigest()
                data_builder_md5sum = hashlib.md5(
                    open(data_builder_out, 'rb').read()).hexdigest()

                self.assertEqual(output_generator_md5sum, data_builder_md5sum)
Exemplo n.º 2
0
    def testHtmlOutputGenerationFormatsMultipleTraces(self):
        trace_results = []
        trace_data_builder = trace_data_module.TraceDataBuilder()

        with open(BATTOR_DATA) as fp:
            battor_data = fp.read()
        trace_results.append(
            trace_result.TraceResult('powerTraceAsString', battor_data))
        trace_data_builder.AddTraceFor(trace_data_module.BATTOR_TRACE_PART,
                                       battor_data)

        with open(ATRACE_DATA) as fp:
            atrace_data = fp.read()
        trace_results.append(
            trace_result.TraceResult('systemTraceEvents', atrace_data))
        trace_data_builder.AddTraceFor(trace_data_module.ATRACE_PART,
                                       atrace_data)

        with open(COMBINED_PROFILE_CHROME_DATA) as fp:
            chrome_data = fp.read()
        trace_results.append(
            trace_result.TraceResult('traceEvents', json.loads(chrome_data)))
        trace_data_builder.AddTraceFor(trace_data_module.CHROME_TRACE_PART,
                                       json.loads(chrome_data))

        trace_results.append(
            trace_result.TraceResult('systraceController', str({})))
        trace_data_builder.AddTraceFor(trace_data_module.TELEMETRY_PART, {})

        try:
            data_builder_out = util.generate_random_filename_for_test()
            output_generator_out = util.generate_random_filename_for_test()
            output_generator.GenerateHTMLOutput(trace_results,
                                                output_generator_out)
            trace_data_builder.AsData().Serialize(data_builder_out, 'Systrace')

            output_generator_md5sum = hashlib.md5(
                open(output_generator_out, 'rb').read()).hexdigest()
            data_builder_md5sum = hashlib.md5(
                open(data_builder_out, 'rb').read()).hexdigest()

            self.assertEqual(output_generator_md5sum, data_builder_md5sum)
        finally:

            def del_if_exist(path):
                try:
                    os.remove(path)
                except IOError:
                    pass

            del_if_exist(output_generator_out)
            del_if_exist(data_builder_out)
Exemplo n.º 3
0
    def testHtmlOutputGenerationFormatsSingleTrace(self):
        update_systrace_trace_viewer.update(force_update=True)
        self.assertTrue(
            os.path.exists(
                update_systrace_trace_viewer.SYSTRACE_TRACE_VIEWER_HTML_FILE))
        with open(ATRACE_DATA) as f:
            atrace_data = f.read().replace(" ", "").strip()
            trace_results = [
                trace_result.TraceResult('systemTraceEvents', atrace_data)
            ]
            output_file_name = util.generate_random_filename_for_test()
            final_path = output_generator.GenerateHTMLOutput(
                trace_results, output_file_name)
            with open(output_file_name, 'r') as f:
                output_generator.GenerateHTMLOutput(trace_results, f.name)
                html_output = f.read()
                trace_data = (html_output.split(
                    '<script class="trace-data" type="application/text">')
                              [1].split('</script>'))[0].replace(" ",
                                                                 "").strip()
            os.remove(final_path)

        # Ensure the trace data written in HTML is located within the
        # correct place in the HTML document and that the data is not
        # malformed.
        self.assertEquals(trace_data, atrace_data)
        os.remove(update_systrace_trace_viewer.SYSTRACE_TRACE_VIEWER_HTML_FILE)
Exemplo n.º 4
0
    def testHtmlOutputGenerationFormatsMultipleTraces(self):
        update_systrace_trace_viewer.update(force_update=True)
        self.assertTrue(
            os.path.exists(
                update_systrace_trace_viewer.SYSTRACE_TRACE_VIEWER_HTML_FILE))
        json_data = open(COMBINED_PROFILE_CHROME_DATA).read()
        combined_data = json.loads(json_data)
        trace_results = []
        trace_results_expected = []
        for (trace_name, data) in combined_data.iteritems():
            trace_results.append(
                trace_result.TraceResult(str(trace_name), str(data)))
            trace_results_expected.append(str(data).replace(" ", "").strip())
        output_file_name = util.generate_random_filename_for_test()
        final_path = output_generator.GenerateHTMLOutput(
            trace_results, output_file_name)
        with open(output_file_name, 'r') as f:
            html_output = f.read()
            for i in range(1, len(trace_results)):
                trace_data = (html_output.split(
                    '<script class="trace-data" type="application/text">')
                              [i].split('</script>'))[0].replace(" ",
                                                                 "").strip()

                # Ensure the trace data written in HTML is located within the
                # correct place in the HTML document and that the data is not
                # malformed.
                self.assertTrue(trace_data in trace_results_expected)
        os.remove(final_path)
        os.remove(update_systrace_trace_viewer.SYSTRACE_TRACE_VIEWER_HTML_FILE)
    def testHtmlOutputGenerationFormatsMultipleTraces(self):
        json_data = open(COMBINED_PROFILE_CHROME_DATA).read()
        combined_data = json.loads(json_data)
        trace_results = []
        trace_results_expected = []
        for (trace_name, data) in combined_data.iteritems():
            trace_results.append(
                trace_result.TraceResult(str(trace_name), str(data)))
            trace_results_expected.append(str(data).replace(" ", "").strip())
        output_file_name = ''.join(
            random.choice(string.ascii_uppercase + string.digits)
            for _ in range(10))
        output_generator.GenerateHTMLOutput(trace_results, output_file_name)
        with open(output_file_name, 'r') as f:
            html_output = f.read()
            for i in range(1, len(trace_results)):
                trace_data = (html_output.split(
                    '<script class="trace-data" type="application/text">')
                              [i].split('</script>'))[0].replace(" ",
                                                                 "").strip()

                # Ensure the trace data written in HTML is located within the
                # correct place in the HTML document and that the data is not
                # malformed.
                self.assertTrue(trace_data in trace_results_expected)
Exemplo n.º 6
0
  def testJsonTraceMerging(self):
    update_systrace_trace_viewer.update(force_update=True)
    self.assertTrue(os.path.exists(
        update_systrace_trace_viewer.SYSTRACE_TRACE_VIEWER_HTML_FILE))
    t1 = "{'traceEvents': [{'ts': 123, 'ph': 'b'}]}"
    t2 = "{'traceEvents': [], 'stackFrames': ['blah']}"
    results = [trace_result.TraceResult('a', t1),
               trace_result.TraceResult('b', t2)]

    merged_results = output_generator.MergeTraceResultsIfNeeded(results)
    for r in merged_results:
      if r.source_name == 'a':
        self.assertEquals(r.raw_data, t1)
      elif r.source_name == 'b':
        self.assertEquals(r.raw_data, t2)
    self.assertEquals(len(merged_results), len(results))
    os.remove(update_systrace_trace_viewer.SYSTRACE_TRACE_VIEWER_HTML_FILE)
    def GetResults(self, timeout=None):
        """Gets the log output from the controller tracing agent.

    This output only contains the "controller side" of the clock sync records.
    """
        with open(self._log_path, 'r') as outfile:
            result = outfile.read() + ']'
        return trace_result.TraceResult(TRACE_DATA_CONTROLLER_NAME,
                                        ast.literal_eval(result))
Exemplo n.º 8
0
def _PrepareTracesForOutput(trace_files):
    trace_results = []
    for trace_file in trace_files:
        trace_name = trace_file.split('-')[0]
        with open(trace_file, 'r') as f:
            trace_data = f.read()
            trace_results.append(
                trace_result.TraceResult(trace_name, trace_data))
    return trace_results
Exemplo n.º 9
0
def MergeTraceResultsIfNeeded(trace_results):
    """Merge a list of trace data, if possible. This function can take any list
     of trace data, but it will only merge the JSON data (since that's all
     we can merge).

     Args:
        trace_results: A list of TraceResults containing trace data.
  """
    if len(trace_results) <= 1:
        return trace_results
    merge_candidates = []
    for result in trace_results:
        # Try to detect a JSON file cheaply since that's all we can merge.
        if result.raw_data[0] != '{':
            continue
        try:
            json_data = json.loads(result.raw_data)
        except ValueError:
            continue
        merge_candidates.append(
            trace_result.TraceResult(result.source_name, json_data))

    if len(merge_candidates) <= 1:
        return trace_results

    other_results = [
        r for r in trace_results
        if not r.source_name in [c.source_name for c in merge_candidates]
    ]

    merged_data = merge_candidates[0].raw_data

    for candidate in merge_candidates[1:]:
        json_data = candidate.raw_data
        for key, value in json_data.items():
            if not str(key) in merged_data or not merged_data[str(key)]:
                merged_data[str(key)] = value

    return (
        [trace_result.TraceResult('merged-data', json.dumps(merged_data))] +
        other_results)
Exemplo n.º 10
0
  def GetResults(self, timeout=None):
    """Gets the log output from the controller tracing agent.

    This output only contains the "controller side" of the clock sync records.
    """
    with open(self._log_path, 'r') as outfile:
      data = ast.literal_eval(outfile.read() + ']')
    # Explicitly set its own clock domain. This will stop the Systrace clock
    # domain from incorrectly being collapsed into the on device clock domain.
    formatted_data = {
        'traceEvents': data,
        'metadata': {
            'clock-domain': 'SYSTRACE',
        }
    }
    return trace_result.TraceResult(TRACE_DATA_CONTROLLER_NAME,
                                    json.dumps(formatted_data))
Exemplo n.º 11
0
    def GetResults(self, timeout=None):
        """Waits until data collection is completed and get the trace data.

    The trace data is the data that comes out of the BattOr, and is in the
    format with the following lines:

    time current voltage <sync_id>

    where the sync_id is only there if a clock sync marker was recorded
    during that sample.

    time = time since start of trace (ms)
    current = current through battery (mA) - this can be negative if the
        battery is charging
    voltage = voltage of battery (mV)

    Returns:
      The trace data.
    """
        return trace_result.TraceResult(
            'powerTraceAsString', self._battor_wrapper.CollectTraceData())
    def testHtmlOutputGenerationFormatsSingleTrace(self):
        with open(ATRACE_DATA) as f:
            atrace_data = f.read().replace(" ", "").strip()
            trace_results = [
                trace_result.TraceResult('systemTraceEvents', atrace_data)
            ]
            output_file_name = ''.join(
                random.choice(string.ascii_uppercase + string.digits)
                for _ in range(10))
            output_generator.GenerateHTMLOutput(trace_results,
                                                output_file_name)
            with open(output_file_name, 'r') as f:
                output_generator.GenerateHTMLOutput(trace_results, f.name)
                html_output = f.read()
                trace_data = (html_output.split(
                    '<script class="trace-data" type="application/text">')
                              [1].split('</script>'))[0].replace(" ",
                                                                 "").strip()

        # Ensure the trace data written in HTML is located within the
        # correct place in the HTML document and that the data is not
        # malformed.
        self.assertEquals(trace_data, atrace_data)
Exemplo n.º 13
0
 def GetResults(self, timeout=None):
     self._thread.join()
     self._thread = None
     return trace_result.TraceResult('systemTraceEvents', self._trace_data)
Exemplo n.º 14
0
 def GetResults(self, timeout=None):
     result = TRACE_HEADER + '\n' + self._dump
     return trace_result.TraceResult(TRACE_RESULT_NAME, result)
 def GetResults(self, timeout=None):
     with open(self._PullTrace(), 'r') as f:
         trace_data = f.read()
     return trace_result.TraceResult('perf', trace_data)
Exemplo n.º 16
0
 def GetResults(self, timeout=None):
     del timeout  # unused
     self._collection_thread.join()
     self._collection_thread = None
     return trace_result.TraceResult('waltTrace', self._get_trace_result())
Exemplo n.º 17
0
 def GetResults(self, timeout=None):
     # get the output
     d = self._fio.readFile(FT_TRACE)
     self._fio.writeFile(FT_BUFFER_SIZE, "1")
     return trace_result.TraceResult('trace-data', d)
Exemplo n.º 18
0
 def GetResults(self, timeout=None):
     result = TRACE_HEADER + self._trace_data
     return trace_result.TraceResult('cgroupDump', result)
Exemplo n.º 19
0
 def GetResults(self, timeout=None):
     return trace_result.TraceResult('trace-data', self._trace_data)
Exemplo n.º 20
0
 def GetResults(self, timeout=None):
   result = TRACE_HEADER + '\n' + self._dump
   cs = json.dumps(self._clock_sync_markers)
   result = TRACE_HEADER + \
       '\n{\"clock_sync_markers\":' + cs + ',\n\"dump\":' + self._dump + '}'
   return trace_result.TraceResult(TRACE_RESULT_NAME, result)
 def GetResults(self, timeout=None):
     result = TRACE_HEADER + self._trace_data
     return trace_result.TraceResult('androidProcessDump', result)
Exemplo n.º 22
0
 def GetResults(self, timeout=None):
     """Waits for collection thread to finish and returns trace results."""
     self._collection_thread.join()
     self._collection_thread = None
     return trace_result.TraceResult('systemTraceEvents', self._trace_data)
Exemplo n.º 23
0
 def GetResults(self, timeout=None):
     trace_data = open(self._PullTrace()).read()
     return trace_result.TraceResult('fakeData', trace_data)