def _plugin_assets(logdir, runs, plugin_name): result = {} for run in runs: run_path = os.path.join(logdir, run) assets = plugin_asset_util.ListAssets(run_path, plugin_name) result[run] = assets return result
def PluginAssets(self, plugin_name): """Return a list of all plugin assets for the given plugin. Args: plugin_name: The string name of a plugin to retrieve assets for. Returns: A list of string plugin asset names, or empty list if none are available. If the plugin was not registered, an empty list is returned. """ return plugin_asset_util.ListAssets(self.path, plugin_name)
def _append_plugin_asset_directories(self, run_path_pairs): extra = [] plugin_assets_name = metadata.PLUGIN_ASSETS_NAME for (run, logdir) in run_path_pairs: assets = plugin_asset_util.ListAssets(logdir, plugin_assets_name) if metadata.PROJECTOR_FILENAME not in assets: continue assets_dir = os.path.join( self._run_paths[run], metadata.PLUGINS_DIR, plugin_assets_name ) assets_path_pair = (run, os.path.abspath(assets_dir)) extra.append(assets_path_pair) run_path_pairs.extend(extra)
def generate_run_to_tools(self): """Generator for pairs of "run name" and a list of tools for that run. The "run name" here is a "frontend run name" - see _run_dir() for the definition of a "frontend run name" and how it maps to a directory of profile data for a specific profile "run". The profile plugin concept of "run" is different from the normal TensorBoard run; each run in this case represents a single instance of profile data collection, more similar to a "step" of data in typical TensorBoard semantics. These runs reside in subdirectories of the plugins/profile directory within any regular TensorBoard run directory (defined as a subdirectory of the logdir that contains at least one tfevents file) or within the logdir root directory itself (even if it contains no tfevents file and would thus not be considered a normal TensorBoard run, for backwards compatibility). Within those "profile run directories", there are files in the directory that correspond to different profiling tools. The file that contains profile for a specific tool "x" will have a suffix name TOOLS["x"]. Example: logs/ plugins/ profile/ run1/ hostA.trace train/ events.out.tfevents.foo plugins/ profile/ run1/ hostA.trace hostB.trace run2/ hostA.trace validation/ events.out.tfevents.foo plugins/ profile/ run1/ hostA.trace Yields: A sequence of tuples mapping "frontend run names" to lists of tool names available for those runs. For the above example, this would be: ("run1", ["trace_viewer"]) ("train/run1", ["trace_viewer"]) ("train/run2", ["trace_viewer"]) ("validation/run1", ["trace_viewer"]) """ self.start_grpc_stub_if_necessary() plugin_assets = self.multiplexer.PluginAssets(PLUGIN_NAME) tb_run_names_to_dirs = self.multiplexer.RunPaths() # Ensure that we also check the root logdir, even if it isn't a recognized # TensorBoard run (i.e. has no tfevents file directly under it), to remain # backwards compatible with previously profile plugin behavior. Note that we # check if logdir is a directory to handle case where it's actually a # multipart directory spec, which this plugin does not support. if '.' not in plugin_assets and tf.io.gfile.isdir(self.logdir): tb_run_names_to_dirs['.'] = self.logdir plugin_assets['.'] = plugin_asset_util.ListAssets( self.logdir, PLUGIN_NAME) for tb_run_name, profile_runs in six.iteritems(plugin_assets): tb_run_dir = tb_run_names_to_dirs[tb_run_name] tb_plugin_dir = plugin_asset_util.PluginDirectory( tb_run_dir, PLUGIN_NAME) for profile_run in profile_runs: # Remove trailing separator; some filesystem implementations emit this. profile_run = profile_run.rstrip(os.sep) if tb_run_name == '.': frontend_run = profile_run else: frontend_run = os.path.join(tb_run_name, profile_run) profile_run_dir = os.path.join(tb_plugin_dir, profile_run) if tf.io.gfile.isdir(profile_run_dir): yield frontend_run, self._get_active_tools(profile_run_dir)