def WriteWebComponentToFile(self, f):
        project = web_components_project.WebComponentsProject()
        load_sequence = project.CalcLoadSequenceForModuleNames(
            self.GetDependentModuleNames())

        with open(
                os.path.join(os.path.dirname(__file__),
                             'web_component_bootstrap.js')) as bfile:
            bootstrap_js_template = string.Template(bfile.read())
        bootstrap_js = bootstrap_js_template.substitute(
            js_class_name=self._js_class_name,
            data_binding_property=self._data_binding_property)

        bootstrap_script = generate.ExtraScript(text_content=bootstrap_js)

        class WebComponentDataScript(generate.ExtraScript):
            def __init__(self, results_component):
                # pylint: disable=bad-super-call
                super(WebComponentDataScript, self).__init__()
                self._results_component = results_component

            def WriteToFile(self, output_file):
                output_file.write(
                    '<script id="telemetry-web-component-data" ' +
                    'type="application/json">\n')
                self._results_component.WriteDataToFileAsJson(output_file)
                output_file.write('</script>\n')

        generate.GenerateStandaloneHTMLToFile(
            f,
            load_sequence,
            title='Telemetry results',
            extra_scripts=[bootstrap_script,
                           WebComponentDataScript(self)])
示例#2
0
def WriteTraceViewer(output_file,
                     config_name=None,
                     minify=False,
                     report_sizes=False,
                     report_deps=False,
                     output_html_head_and_body=True,
                     extra_search_paths=None,
                     extra_module_names_to_load=None):
    project = trace_viewer_project.TraceViewerProject()
    if extra_search_paths:
        for p in extra_search_paths:
            project.source_paths.append(p)
    if config_name == None:
        config_name = project.GetDefaultConfigName()

    module_names = [
        'trace_viewer',
        project.GetModuleNameForConfigName(config_name)
    ]
    if extra_module_names_to_load:
        module_names += extra_module_names_to_load
    load_sequence = project.CalcLoadSequenceForModuleNames(module_names)

    if report_deps:
        sys.stdout.write(project.GetDepsGraphFromModuleNames(module_names))

    generate.GenerateStandaloneHTMLToFile(
        output_file,
        load_sequence,
        minify=minify,
        report_sizes=report_sizes,
        output_html_head_and_body=output_html_head_and_body)
示例#3
0
def WriteHTMLForTraceDataToFile(trace_data_list,
                                title, output_file,
                                config_name=None):
  project = tracing_project.TracingProject()

  if config_name is None:
    config_name = project.GetDefaultConfigName()

  modules = [
      'tracing.trace2html',
      'tracing.extras.importer.gzip_importer',  # Must have for all configs.
      project.GetModuleNameForConfigName(config_name)
  ]

  vulcanizer = project.CreateVulcanizer()
  load_sequence = vulcanizer.CalcLoadSequenceForModuleNames(modules)

  scripts = []
  for trace_data in trace_data_list:
    # If the object was previously decoded from valid JSON data (e.g., in
    # WriteHTMLForTracesToFile), it will be a JSON object at this point and we
    # should re-serialize it into a string. Other types of data will be already
    # be strings.
    if not isinstance(trace_data, basestring):
      trace_data = json.dumps(trace_data)
      mime_type = 'application/json'
    else:
      mime_type = 'text/plain'
    scripts.append(ViewerDataScript(trace_data, mime_type))
  generate.GenerateStandaloneHTMLToFile(
      output_file, load_sequence, title, extra_scripts=scripts)
示例#4
0
def WriteHTMLForTracesToFile(trace_filenames, output_file):
  project = trace_viewer_project.TraceViewerProject()
  load_sequence = project.CalcLoadSequenceForModuleNames(
      ['build.trace2html'])

  scripts = [ViewerDataScript(x) for x in trace_filenames]

  title = "Trace from %s" % ','.join(trace_filenames)
  generate.GenerateStandaloneHTMLToFile(
      output_file, load_sequence, title, extra_scripts=scripts)
示例#5
0
def WriteHTMLForTraceDataToFile(trace_data_list, title, output_file):
    project = trace_viewer_project.TraceViewerProject()
    load_sequence = project.CalcLoadSequenceForModuleNames(
        ['build.trace2html'])
    scripts = [
        ViewerDataScript(json.dumps(trace_data))
        for trace_data in trace_data_list
    ]
    generate.GenerateStandaloneHTMLToFile(output_file,
                                          load_sequence,
                                          title,
                                          extra_scripts=scripts)
示例#6
0
def WriteResultsToFile(ofile, project, results):
    modules = ['perf_insights.wr.wr_cmdline']

    vulcanizer = project.CreateVulcanizer()
    load_sequence = vulcanizer.CalcLoadSequenceForModuleNames(modules)

    results_string = json.dumps(results.AsDict())

    scripts = [DataScript(results_string)]
    generate.GenerateStandaloneHTMLToFile(ofile,
                                          load_sequence,
                                          'Weather Report',
                                          extra_scripts=scripts)
def GenerateHTML(ofile):
    project = spy_project.SpyProject()
    load_sequence = project.CalcLoadSequenceForModuleNames(['ui.spy_shell'])
    bootstrap_js = """

  document.addEventListener('DOMContentLoaded', function() {
    document.body.appendChild(new ui.SpyShell('ws://127.0.0.1:42424'));

  });
"""
    bootstrap_script = generate.ExtraScript(text_content=bootstrap_js)
    generate.GenerateStandaloneHTMLToFile(ofile,
                                          load_sequence,
                                          title='Mojo spy',
                                          extra_scripts=[bootstrap_script])
示例#8
0
def WriteHTMLForTraceDataToFile(trace_data_list, title, output_file):
    project = trace_viewer_project.TraceViewerProject()
    load_sequence = project.CalcLoadSequenceForModuleNames(
        ['build.trace2html'])
    scripts = []
    for trace_data in trace_data_list:
        # If the object was previously decoded from valid JSON data (e.g., in
        # WriteHTMLForTracesToFile), it will be a JSON object at this point and we
        # should re-serialize it into a string. Other types of data will be already
        # be strings.
        if not isinstance(trace_data, basestring):
            trace_data = json.dumps(trace_data)
            mime_type = 'application/json'
        else:
            mime_type = 'text/plain'
        scripts.append(ViewerDataScript(trace_data, mime_type))
    generate.GenerateStandaloneHTMLToFile(output_file,
                                          load_sequence,
                                          title,
                                          extra_scripts=scripts)
示例#9
0
def WriteResultsToFile(ofile, project, pi_report_file, pi_report_element_name,
                       results):

    vulcanizer = project.CreateVulcanizer()
    modules = []
    modules.append(
        vulcanizer.LoadModule(module_filename=os.path.join(
            project.perf_insights_root_path,
            'perf_insights_build/pi_report_to_html.html')))
    modules.append(vulcanizer.LoadModule(module_filename=pi_report_file))

    load_sequence = vulcanizer.CalcLoadSequenceForModules(modules)

    results_string = json.dumps(results.AsDict())

    bootstrap_script = generate.ExtraScript(text_content="""
    document.addEventListener('DOMContentLoaded', function() {
      pib.initPiReportNamed('%s');
    });""" % pi_report_element_name)
    scripts = [bootstrap_script, DataScript(results_string)]
    generate.GenerateStandaloneHTMLToFile(ofile,
                                          load_sequence,
                                          'Perf Insights Report',
                                          extra_scripts=scripts)