示例#1
0
def dump_data(logdir):
    """Dumps plugin data to the log directory."""
    plugin_logdir = plugin_asset_util.PluginDirectory(
        logdir, profile_plugin.ProfilePlugin.plugin_name)
    _maybe_create_directory(plugin_logdir)

    for run in profile_demo_data.RUNS:
        run_dir = os.path.join(plugin_logdir, run)
        _maybe_create_directory(run_dir)
        if run in profile_demo_data.TRACES:
            with open(os.path.join(run_dir, 'trace'), 'w') as f:
                proto = trace_events_pb2.Trace()
                text_format.Merge(profile_demo_data.TRACES[run], proto)
                f.write(proto.SerializeToString())
        shutil.copyfile(
            'tensorboard/plugins/profile/profile_demo.op_profile.json',
            os.path.join(run_dir, 'op_profile.json'))
        shutil.copyfile(
            'tensorboard/plugins/profile/profile_demo.memory_viewer.json',
            os.path.join(run_dir, 'memory_viewer.json'))

    # Unsupported tool data should not be displayed.
    run_dir = os.path.join(plugin_logdir, 'empty')
    _maybe_create_directory(run_dir)
    with open(os.path.join(run_dir, 'unsupported'), 'w') as f:
        f.write('unsupported data')
示例#2
0
def dump_data(logdir):
    """Dumps plugin data to the log directory."""
    # Create a tfevents file in the logdir so it is detected as a run.
    write_empty_event_file(logdir)

    plugin_logdir = plugin_asset_util.PluginDirectory(
        logdir, profile_plugin.ProfilePlugin.plugin_name)
    _maybe_create_directory(plugin_logdir)

    for run in profile_demo_data.RUNS:
        run_dir = os.path.join(plugin_logdir, run)
        _maybe_create_directory(run_dir)
        if run in profile_demo_data.TRACES:
            with open(os.path.join(run_dir, "trace"), "w") as f:
                proto = trace_events_pb2.Trace()
                text_format.Merge(profile_demo_data.TRACES[run], proto)
                f.write(proto.SerializeToString())

        if run not in profile_demo_data.TRACE_ONLY:
            shutil.copyfile(
                "tensorboard/plugins/profile/profile_demo.op_profile.json",
                os.path.join(run_dir, "op_profile.json"),
            )
            shutil.copyfile(
                "tensorboard/plugins/profile/profile_demo.memory_viewer.json",
                os.path.join(run_dir, "memory_viewer.json"),
            )
            shutil.copyfile(
                "tensorboard/plugins/profile/profile_demo.pod_viewer.json",
                os.path.join(run_dir, "pod_viewer.json"),
            )
            shutil.copyfile(
                "tensorboard/plugins/profile/profile_demo.google_chart_demo.json",
                os.path.join(run_dir, "google_chart_demo.json"),
            )
            shutil.copyfile(
                "tensorboard/plugins/profile/profile_demo.input_pipeline.json",
                os.path.join(run_dir, "input_pipeline.json"),
            )
            shutil.copyfile(
                "tensorboard/plugins/profile/profile_demo.overview_page.json",
                os.path.join(run_dir, "overview_page.json"),
            )

    # Unsupported tool data should not be displayed.
    run_dir = os.path.join(plugin_logdir, "empty")
    _maybe_create_directory(run_dir)
    with open(os.path.join(run_dir, "unsupported"), "w") as f:
        f.write("unsupported data")
示例#3
0
    def setUp(self):
        # Populate the log directory with runs and traces.
        self.logdir = self.get_temp_dir()
        plugin_logdir = plugin_asset_util.PluginDirectory(
            self.logdir, profile_plugin.ProfilePlugin.plugin_name)
        os.makedirs(plugin_logdir)
        self.run_to_tools = {
            'foo': ['trace_viewer'],
            'bar': ['unsupported'],
            'baz': ['trace_viewer'],
            'empty': [],
        }
        self.run_to_hosts = {
            'foo': ['host0', 'host1'],
            'bar': ['host1'],
            'baz': ['host2'],
            'empty': [],
        }
        for run in self.run_to_tools:
            run_dir = os.path.join(plugin_logdir, run)
            os.mkdir(run_dir)
            for tool in self.run_to_tools[run]:
                if tool not in profile_plugin.TOOLS:
                    continue
                for host in self.run_to_hosts[run]:
                    file_name = host + profile_plugin.TOOLS[tool]
                    tool_file = os.path.join(run_dir, file_name)
                    if tool == 'trace_viewer':
                        trace = trace_events_pb2.Trace()
                        trace.devices[0].name = run
                        data = trace.SerializeToString()
                    else:
                        data = tool
                    with open(tool_file, 'wb') as f:
                        f.write(data)
        with open(os.path.join(plugin_logdir, 'noise'), 'w') as f:
            f.write('Not a dir, not a run.')

        # The profiler plugin does not use the multiplexer, so we do not bother to
        # construct a meaningful one right now. In fact, the profiler plugin does
        # not use this context object in general. Its constructor has to accept it
        # though, and it may use the context in the future.
        context = base_plugin.TBContext(logdir=self.logdir,
                                        multiplexer=None,
                                        flags=FakeFlags(self.logdir))
        self.plugin = profile_plugin.ProfilePlugin(context)
        self.apps = self.plugin.get_plugin_apps()
def generate_testdata(logdir):
    plugin_logdir = plugin_asset_util.PluginDirectory(
        logdir, profile_plugin.ProfilePlugin.plugin_name)
    os.makedirs(plugin_logdir)
    for run in RUN_TO_TOOLS:
        run_dir = os.path.join(plugin_logdir, run)
        os.mkdir(run_dir)
        for tool in RUN_TO_TOOLS[run]:
            if tool not in profile_plugin.TOOLS:
                continue
            for host in RUN_TO_HOSTS[run]:
                file_name = host + profile_plugin.TOOLS[tool]
                tool_file = os.path.join(run_dir, file_name)
                if tool == 'trace_viewer':
                    trace = trace_events_pb2.Trace()
                    trace.devices[0].name = run
                    data = trace.SerializeToString()
                else:
                    data = tool
                with open(tool_file, 'wb') as f:
                    f.write(data)
    with open(os.path.join(plugin_logdir, 'noise'), 'w') as f:
        f.write('Not a dir, not a run.')
示例#5
0
def process_raw_trace(raw_trace):
    """Processes raw trace data and returns the UI data."""
    trace = trace_events_pb2.Trace()
    trace.ParseFromString(raw_trace)
    return ''.join(trace_events_json.TraceEventsJsonStream(trace))
示例#6
0
 def convert(self, proto_text):
     proto = trace_events_pb2.Trace()
     text_format.Merge(proto_text, proto)
     return json.loads(''.join(
         trace_events_json.TraceEventsJsonStream(proto)))