Example #1
0
def _SerializeAndProcessTrace(trace_data, process_trace_func_code):
    temp_dir = tempfile.mkdtemp()
    try:
        trace_file_path = os.path.join(temp_dir, 'temp_trace')
        trace_data.Serialize(trace_file_path)
        return map_single_trace.ExecuteTraceMappingCode(
            trace_file_path, process_trace_func_code)
    finally:
        shutil.rmtree(temp_dir)
 def testExecuteTraceMappingCodeWithError(self):
     test_trace_path = os.path.join(os.path.dirname(__file__),
                                    'test_trace.json')
     with self.assertRaises(RuntimeError):
         map_single_trace.ExecuteTraceMappingCode(
             test_trace_path, """
       function processTrace(results, model) {
           throw new Error('Expected error');
       };
       """)
 def testExecuteTraceMappingCode(self):
     test_trace_path = os.path.join(os.path.dirname(__file__),
                                    'test_trace.json')
     results = map_single_trace.ExecuteTraceMappingCode(
         test_trace_path, """
     function processTrace(results, model) {
       var canonicalUrl = model.canonicalUrl;
       results.addPair('numProcesses', model.getAllProcesses().length);
     };
     """)
     self.assertEquals(results['numProcesses'], 2)
Example #4
0
def ExecuteMappingCodeOnTraceData(trace_data,
                                  process_trace_func_code,
                                  extra_import_options=None,
                                  trace_canonical_url=None):
    temp_dir = tempfile.mkdtemp()
    trace_file_path = os.path.join(temp_dir, 'temp_trace')
    trace_data.Serialize(trace_file_path)
    try:
        return map_single_trace.ExecuteTraceMappingCode(
            trace_file_path, process_trace_func_code, extra_import_options,
            trace_canonical_url)
    finally:
        shutil.rmtree(temp_dir)
Example #5
0
def _SerializeAndProcessTrace(trace_builder, process_trace_func_code):
    """Load data into a trace model and run a query on it.

  The current implementation works by loading the trace data into the TBMv2,
  i.e. JavaScript based, timeline model. But this is an implementation detail,
  clients for the public methods of this module should remain agnostic about
  the model being used for trace processing.
  """
    with tempfile_ext.TemporaryFileName() as trace_file:
        try:
            trace_builder.Serialize(trace_file)
            return map_single_trace.ExecuteTraceMappingCode(
                trace_file, process_trace_func_code)
        finally:
            trace_builder.CleanUpTraceData()
Example #6
0
def ExtractTimelineMarkers(trace_data):
    """Get a list with the titles of 'blink.console' events found in a trace.

  This will include any events that were inserted using tab.AddTimelineMarker
  while a trace was being recorded.

  The current implementation works by loading the trace data into the TBMv2,
  i.e. JavaScript based, timeline model. But this is an implementation detail,
  clients remain agnostic about the model used for trace processing.
  """
    temp_dir = tempfile.mkdtemp()
    try:
        trace_file_path = os.path.join(temp_dir, 'temp_trace')
        trace_data.Serialize(trace_file_path)
        return map_single_trace.ExecuteTraceMappingCode(
            trace_file_path, _GET_TIMELINE_MARKERS)['markers']
    finally:
        shutil.rmtree(temp_dir)