aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Derek Murray <mrry@google.com>2018-09-05 22:20:40 -0700
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2018-09-05 22:24:53 -0700
commit5393c8f0dc57857c93482bff67f1134aae9af594 (patch)
tree328238d0953ecee9e4fa3341189857846985dd1d
parentf4ae136265d3d3116a008b98ccf21d0791b878fd (diff)
Add `TraceCollector::IsEnabled(bool)` method in order to test when tracing is enabled.
Some builds install a `TraceCollector` at process startup, but it is mostly not enabled. This inhibits the recent optimization to avoid accessing `OpKernel::name()` and `OpKernel::type_string()` every time a kernel is launched. By caching the `TraceCollector` in the `TracingDevice` and adding a method to enquire about its state, we increase the applicability of the optimization. PiperOrigin-RevId: 211752728
-rw-r--r--tensorflow/core/common_runtime/tracing_device.h5
-rw-r--r--tensorflow/core/platform/default/device_tracer.cc5
-rw-r--r--tensorflow/core/platform/tracing.h4
3 files changed, 13 insertions, 1 deletions
diff --git a/tensorflow/core/common_runtime/tracing_device.h b/tensorflow/core/common_runtime/tracing_device.h
index 39215efa35..e1b163074f 100644
--- a/tensorflow/core/common_runtime/tracing_device.h
+++ b/tensorflow/core/common_runtime/tracing_device.h
@@ -35,8 +35,11 @@ class TracingDevice : public Device {
: Device(env, attributes) {}
void Compute(OpKernel* op_kernel, OpKernelContext* context) override {
+ const tracing::TraceCollector* trace_collector =
+ tracing::GetTraceCollector();
if (TF_PREDICT_FALSE(
- tracing::GetTraceCollector() ||
+ (trace_collector &&
+ trace_collector->IsEnabled(op_kernel->IsExpensive())) ||
tracing::GetEventCollector(tracing::EventCategory::kCompute))) {
const string& op_name = op_kernel->name();
tracing::ScopedActivity activity(op_name, op_kernel->type_string(),
diff --git a/tensorflow/core/platform/default/device_tracer.cc b/tensorflow/core/platform/default/device_tracer.cc
index ccddf1eafc..0389149469 100644
--- a/tensorflow/core/platform/default/device_tracer.cc
+++ b/tensorflow/core/platform/default/device_tracer.cc
@@ -321,6 +321,11 @@ class DeviceTracerImpl : public DeviceTracer,
return nullptr;
}
+ bool IsEnabled(bool is_expensive) const override {
+ // We don't do anything with 'Activities' so we are never 'enabled'.
+ return false;
+ }
+
protected:
// This callback is used exclusively by CUPTIManager.
friend class CUPTIManager;
diff --git a/tensorflow/core/platform/tracing.h b/tensorflow/core/platform/tracing.h
index e5851f1dfe..9974bbbb4e 100644
--- a/tensorflow/core/platform/tracing.h
+++ b/tensorflow/core/platform/tracing.h
@@ -155,6 +155,10 @@ class TraceCollector {
StringPiece name_part1, StringPiece name_part2,
bool is_expensive) const = 0;
+ // Returns true if this activity handle tracking is enabled for an op of the
+ // given expensiveness.
+ virtual bool IsEnabled(bool is_expensive) const = 0;
+
protected:
static string ConcatenateNames(StringPiece first, StringPiece second);