From 49d23307d54b9bd1e3e8bae5a56edc0db5622914 Mon Sep 17 00:00:00 2001 From: "A. Unique TensorFlower" Date: Mon, 5 Aug 2019 11:08:50 -0700 Subject: [PATCH] Add tfstreamz for context and session creation in python. PiperOrigin-RevId: 261724525 --- tensorflow/python/client/session.py | 5 +++++ tensorflow/python/eager/context.py | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/tensorflow/python/client/session.py b/tensorflow/python/client/session.py index 96646f563b8..8d1be4b26ed 100644 --- a/tensorflow/python/client/session.py +++ b/tensorflow/python/client/session.py @@ -29,6 +29,7 @@ from tensorflow.core.protobuf import config_pb2 from tensorflow.core.protobuf import rewriter_config_pb2 from tensorflow.python import pywrap_tensorflow as tf_session from tensorflow.python.eager import context +from tensorflow.python.eager import monitoring from tensorflow.python.framework import device from tensorflow.python.framework import error_interpolation from tensorflow.python.framework import errors @@ -43,6 +44,9 @@ from tensorflow.python.util import object_identity from tensorflow.python.util.tf_export import tf_export from tensorflow.python.util.compat import collections_abc +_python_session_create_counter = monitoring.Counter( + '/tensorflow/api/python/session_create_counter', + 'Counter for number of sessions created in Python.') class SessionInterface(object): """Base class for implementations of TensorFlow client sessions.""" @@ -641,6 +645,7 @@ class BaseSession(SessionInterface): creating the TensorFlow session. TypeError: If one of the arguments has the wrong type. """ + _python_session_create_counter.get_cell().increase_by(1) if graph is None: self._graph = ops.get_default_graph() else: diff --git a/tensorflow/python/eager/context.py b/tensorflow/python/eager/context.py index beb0d75c214..f1e3f3e2bcc 100644 --- a/tensorflow/python/eager/context.py +++ b/tensorflow/python/eager/context.py @@ -68,6 +68,10 @@ MIRRORING_ALL = pywrap_tensorflow.TFE_MIRRORING_ALL _tf2_gauge = monitoring.BoolGauge("/tensorflow/api/tf2_enable", "Whether tf2.enable() is called.") +_python_eager_context_create_counter = monitoring.Counter( + "/tensorflow/api/python/eager_context_create_counter", + "Counter for number of eager contexts created in Python.") + _tf2_gauge.get_cell().set(tf2.enabled()) @@ -414,6 +418,8 @@ class Context(object): self._log_device_placement = None self._optimizer_experimental_options = {} + _python_eager_context_create_counter.get_cell().increase_by(1) + # pylint: enable=redefined-outer-name def _set_global_seed(self, seed):