def start_profiler_server(port): """Start a profiler grpc server that listens to given port. The profiler server will keep the program running even the training finishes. Please shutdown the server with CTRL-C. It can be used in both eager mode and graph mode. The service defined in tensorflow/core/profiler/profiler_service.proto. Please use tensorflow/contrib/tpu/profiler/capture_tpu_profile to capture tracable file following https://cloud.google.com/tpu/docs/cloud-tpu-tools#capture_trace Args: port: port profiler server listens to. """ profiler_context = pywrap_tensorflow.TFE_NewProfilerContext() if context.default_execution_mode == context.EAGER_MODE: pywrap_tensorflow.TFE_ProfilerContextSetEagerContext( profiler_context, context.context()._handle) # pylint: disable=protected-access pywrap_tensorflow.TFE_StartProfilerServer(profiler_context, port) pywrap_tensorflow.TFE_DeleteProfilerContext(profiler_context)
def start(): """Start profiling. Raises: ProfilerAlreadyRunningError: If another profiling session is running. """ global _profiler with _profiler_lock: if _profiler is not None: raise ProfilerAlreadyRunningError('Another profiler is running.') profiler_context = pywrap_tensorflow.TFE_NewProfilerContext() if context.default_execution_mode == context.EAGER_MODE: pywrap_tensorflow.TFE_ProfilerContextSetEagerContext( profiler_context, context.context()._handle) # pylint: disable=protected-access _profiler = pywrap_tensorflow.TFE_NewProfiler(profiler_context) pywrap_tensorflow.TFE_DeleteProfilerContext(profiler_context) if not pywrap_tensorflow.TFE_ProfilerIsOk(_profiler): logging.warning('Another profiler session is running which is probably ' 'created by profiler server. Please avoid using profiler ' 'server and profiler APIs at the same time.')