예제 #1
0
def GraphTimelines(trace):
    """Creates a figure of Network and CPU activity for a trace.

  Args:
    trace: (LoadingTrace)

  Returns:
    A matplotlib.pylab.figure.
  """
    cpu_lens = activity_lens.ActivityLens(trace)
    network_lens = network_activity_lens.NetworkActivityLens(trace)
    matplotlib.rc('font', size=14)
    figure, (network, cpu) = plt.subplots(2, sharex=True, figsize=(14, 10))
    figure.suptitle('Network and CPU Activity - %s' % trace.url)
    upload_timeline = network_lens.uploaded_bytes_timeline
    download_timeline = network_lens.downloaded_bytes_timeline
    start_time = upload_timeline[0][0]
    end_time = upload_timeline[0][-1]
    times = np.array(upload_timeline[0]) - start_time
    network.step(times,
                 np.cumsum(download_timeline[1]) / 1e6,
                 label='Download')
    network.step(times, np.cumsum(upload_timeline[1]) / 1e6, label='Upload')
    network.legend(loc='lower right')
    network.set_xlabel('Time (ms)')
    network.set_ylabel('Total Data Transferred (MB)')

    (cpu_timestamps,
     cpu_busyness) = _CpuActivityTimeline(cpu_lens, start_time, end_time, 100)
    cpu.step(cpu_timestamps - start_time, cpu_busyness)
    cpu.set_ylim(ymin=0, ymax=100)
    cpu.set_xlabel('Time (ms)')
    cpu.set_ylabel('Main Renderer Thread Busyness (%)')
    return figure
예제 #2
0
def get_network_dependency_graph(json_dict):
  trace = loading_trace.LoadingTrace.FromJsonDict(json_dict)
  content_lens = (
      content_classification_lens.ContentClassificationLens.WithRulesFiles(
          trace, '', ''))
  frame_lens = frame_load_lens.FrameLoadLens(trace)
  activity = activity_lens.ActivityLens(trace)
  deps_lens = request_dependencies_lens.RequestDependencyLens(trace)
  graph_view = loading_graph_view.LoadingGraphView(
      trace, deps_lens, content_lens, frame_lens, activity)
  return graph_view
예제 #3
0
def _ProcessJsonTrace(json_dict):
    trace = loading_trace.LoadingTrace.FromJsonDict(json_dict)
    content_lens = (
        content_classification_lens.ContentClassificationLens.WithRulesFiles(
            trace, OPTIONS.ad_rules, OPTIONS.tracking_rules))
    frame_lens = frame_load_lens.FrameLoadLens(trace)
    activity = activity_lens.ActivityLens(trace)
    deps_lens = request_dependencies_lens.RequestDependencyLens(trace)
    graph_view = loading_graph_view.LoadingGraphView(
        trace, deps_lens, content_lens, frame_lens, activity)
    if OPTIONS.noads:
      graph_view.RemoveAds()
    return graph_view
def _ProcessRequests(filename):
    with open(filename) as f:
        trace = loading_trace.LoadingTrace.FromJsonDict(json.load(f))
        content_lens = (content_classification_lens.ContentClassificationLens.
                        WithRulesFiles(trace, OPTIONS.ad_rules,
                                       OPTIONS.tracking_rules))
        frame_lens = frame_load_lens.FrameLoadLens(trace)
        activity = activity_lens.ActivityLens(trace)
        graph = loading_model.ResourceGraph(trace, content_lens, frame_lens,
                                            activity)
        if OPTIONS.noads:
            graph.Set(node_filter=graph.FilterAds)
        return graph
예제 #5
0
def main(trace_file):
  import subprocess

  import loading_graph_view
  import loading_trace
  import request_dependencies_lens

  trace = loading_trace.LoadingTrace.FromJsonFile(trace_file)
  dependencies_lens = request_dependencies_lens.RequestDependencyLens(trace)
  activity = activity_lens.ActivityLens(trace)
  graph_view = loading_graph_view.LoadingGraphView(trace, dependencies_lens,
                                                   activity=activity)
  visualization = LoadingGraphViewVisualization(graph_view)

  dotfile = trace_file + '.dot'
  pngfile = trace_file + '.png'
  with file(dotfile, 'w') as output:
    visualization.OutputDot(output)
  subprocess.check_call(['dot', '-Tpng', dotfile, '-o', pngfile])