class_docstr: Enable profiling by installing session hooks,
  and write tracing files / events / metadata to ``logger.get_logger_dir()``.
  
  The tracing files can be loaded from ``chrome://tracing``.
  The metadata files can be processed by
  `tfprof command line utils
  <https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/profiler/README.md>`_.
  The event is viewable from tensorboard.
  
  Tips:
  
  Note that the profiling is by default enabled for every step and is expensive.
  You probably want to schedule it less frequently, e.g.:
  
  .. code-block:: none
  
      EnableCallbackIf(
          GraphProfiler(dump_tracing=True, dump_event=True),
          lambda self: self.trainer.global_step > 20 and self.trainer.global_step < 30)
class_docstr_tok: ["Enable","profiling","by","installing","session","hooks",",","and","write","tracing","files","\/","events","\/","metadata","to","``","logger.get_logger_dir","(",")","``",".","The","tracing","files","can","be","loaded","from","``","chrome",":","\/\/tracing","``",".","The","metadata","files","can","be","processed","by","`","tfprof","command","line","utils","<","https",":","\/\/github.com\/tensorflow\/tensorflow\/blob\/master\/tensorflow\/core\/profiler\/README.md",">","`","_",".","The","event","is","viewable","from","tensorboard",".","Tips",":","Note","that","the","profiling","is","by","default","enabled","for","every","step","and","is","expensive",".","You","probably","want","to","schedule","it","less","frequently",",","e.g",".",":","..","code-block",":",":","none","EnableCallbackIf","(","GraphProfiler","(","dump_tracing=True",",","dump_event=True",")",",","lambda","self",":","self.trainer.global_step",">","20","and","self.trainer.global_step","<","30",")"]
code: def _write_tracing(self, metadata):
      from tensorflow.python.client import timeline
  
      tl = timeline.Timeline(step_stats=metadata.step_stats)
      fname = os.path.join(
          self._dir, "chrome-trace-{}.json".format(self.global_step)
      )
      with open(fname, "w") as f:
          f.write(
              tl.generate_chrome_trace_format(
                  show_dataflow=True, show_memory=True
              )
          )
  
imports: import multiprocessing
  import numpy
  import os
  import time
  import tensorflow
  from six.moves import map, queue
  import psutil
  from ..tfutils.common import gpu_available_in_session
  from ..utils import logger
  from ..utils.timer import Timer
  from ..utils.concurrency import ensure_proc_terminate, start_proc_mask_signal
  from ..utils.gpu import get_num_gpu
  from ..utils.nvml import NVMLContext
  from .base import Callback
label_desc: Use image node_id 5 for calling the GraphProfiler obj's underlying member method code with example usage: obj._write_tracing(metadata) without return types