class_docstr: A Context that captures RunMetadata and performs profiling.
  
  ```python
    # Trace steps 100~200, profile at [150, 200] and dump profile at 200.
    with profile_context.ProfileContext('/tmp/train_dir',
                                        trace_steps=range(100, 200, 3),
                                        dump_steps=[200]) as pctx:
      opts = tf.profiler.ProfileOptionBuilder.time_and_memory()
      pctx.add_auto_profiling('op', opts, [150, 200])
      train_loop().
  
    # Tracing only.
    with profile_context.tfprof.ProfileContext('/tmp/train_dir') as pctx:
      # Run train/eval loop for at least few hundred steps. Profiles will be
      # dumped to train_dir. Use web UI or command line to do profiling.
      train_loop().
  
    # When session object is available, do explicit trace, profile and dump.
    with profile_context.ProfileContext('/tmp/train_dir',
                                        trace_steps=[],
                                        dump_steps=[]) as pctx:
      opts = tf.profiler.ProfileOptionBuilder.time_and_memory()
      pctx.trace_next_step()
      _ = session.run(train_op)
      pctx.profiler.profile_operations(options=opts)
  ```
  
  Args:
    profile_dir: Directory to store profiles.
    trace_steps: A list of session run steps to trace. If None, use
        pre-defined steps.
    dump_steps: A list of steps to dump the profile to `profile_dir`. If None,
        use pre-defined steps.
    enabled: If false, everything is disabled with minimal overhead. It allows
        user to only enable profiling when needed.
    debug: If true, also dumps the raw trace RunMetadata text file to
        profile_dir. And print debugging message. Useful for bug report.
class_docstr_tok: ["A","Context","that","captures","RunMetadata","and","performs","profiling",".","``","`","python","#","Trace","steps","100~200",",","profile","at","[","150",",","200","]","and","dump","profile","at","200.","with","profile_context.ProfileContext","(","'\/tmp\/train_dir","'",",","trace_steps=range","(","100",",","200",",","3",")",",","dump_steps=","[","200","]",")","as","pctx",":","opts","=","tf.profiler.ProfileOptionBuilder.time_and_memory","(",")","pctx.add_auto_profiling","(","'op","'",",","opts",",","[","150",",","200","]",")","train_loop","(",")",".","#","Tracing","only",".","with","profile_context.tfprof.ProfileContext","(","'\/tmp\/train_dir","'",")","as","pctx",":","#","Run","train\/eval","loop","for","at","least","few","hundred","steps",".","Profiles","will","be","#","dumped","to","train_dir",".","Use","web","UI","or","command","line","to","do","profiling",".","train_loop","(",")",".","#","When","session","object","is","available",",","do","explicit","trace",",","profile","and","dump",".","with","profile_context.ProfileContext","(","'\/tmp\/train_dir","'",",","trace_steps=","[","]",",","dump_steps=","[","]",")","as","pctx",":","opts","=","tf.profiler.ProfileOptionBuilder.time_and_memory","(",")","pctx.trace_next_step","(",")","_","=","session.run","(","train_op",")","pctx.profiler.profile_operations","(","options=opts",")","``","`","Args",":","profile_dir",":","Directory","to","store","profiles",".","trace_steps",":","A","list","of","session","run","steps","to","trace",".","If","None",",","use","pre-defined","steps",".","dump_steps",":","A","list","of","steps","to","dump","the","profile","to","`","profile_dir","`",".","If","None",",","use","pre-defined","steps",".","enabled",":","If","false",",","everything","is","disabled","with","minimal","overhead",".","It","allows","user","to","only","enable","profiling","when","needed",".","debug",":","If","true",",","also","dumps","the","raw","trace","RunMetadata","text","file","to","profile_dir",".","And","print","debugging","message",".","Useful","for","bug","report","."]
code: def _dump_file(self, pb, basename):
      gfile.MakeDirs(self._profiler_dir)
      with gfile.Open(
          os.path.join(self._profiler_dir, basename), "w"
      ) as f:
          f.write("%s" % pb)
  
imports: import contextlib
  import os
  import random
  import sys
  import threading
  from tensorflow.core.protobuf import config_pb2
  from tensorflow.python.client import session
  from tensorflow.python.framework import errors
  from tensorflow.python.framework import ops
  from tensorflow.python.platform import gfile
  from tensorflow.python.profiler import model_analyzer
  from tensorflow.python.util import _pywrap_tfprof
  from tensorflow.python.util import compat
label_desc: Use image node_id 10 for calling the ProfileContext obj's underlying member method code with example usage: obj._dump_file(pb, basename) without return types