예제 #1
0
def stop():
  """Stop current profiling session and return its result.

  Returns:
    A binary string of tensorflow.tpu.Trace. User can write the string
    to file for offline analysis by tensorboard.

  Raises:
    AssertionError: If there is no active profiling session.
  """
  global _profiler
  global _run_num
  if _profiler is None:
    raise AssertionError('Cannot stop profiling. No profiler is running.')
  with c_api_util.tf_buffer() as buffer_:
    pywrap_tensorflow.TFE_ProfilerSerializeToString(
        context.context()._handle,  # pylint: disable=protected-access
        _profiler,
        buffer_)
    result = pywrap_tensorflow.TF_GetBuffer(buffer_)
  with _profiler_lock:
    pywrap_tensorflow.TFE_DeleteProfiler(_profiler)
    _profiler = None
    _run_num += 1
  return result
def stop():
    """Stop current profiling session and return its result.

  Returns:
    A binary string of tensorflow.tpu.Trace. User can write the string
    to file for offline analysis by tensorboard.

  Raises:
    ProfilerNotRunningError: If there is no active profiling session.
  """
    global _profiler
    global _run_num
    with _profiler_lock:
        if _profiler is None:
            raise ProfilerNotRunningError(
                'Cannot stop profiling. No profiler is running.')
        if context.default_execution_mode == context.EAGER_MODE:
            context.context().executor.wait()
        with c_api_util.tf_buffer() as buffer_:
            pywrap_tensorflow.TFE_ProfilerSerializeToString(_profiler, buffer_)
            result = pywrap_tensorflow.TF_GetBuffer(buffer_)
        pywrap_tensorflow.TFE_DeleteProfiler(_profiler)
        _profiler = None
        _run_num += 1
    return result