1 /* Copyright 2018 The TensorFlow Authors. All Rights Reserved.
2
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6
7 http://www.apache.org/licenses/LICENSE-2.0
8
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15
16 #include "tensorflow/core/common_runtime/metrics.h"
17 #include "tensorflow/core/lib/monitoring/counter.h"
18
19 namespace tensorflow {
20 namespace metrics {
21 namespace {
22
23 auto* graph_runs = monitoring::Counter<0>::New(
24 "/tensorflow/core/graph_runs",
25 "The number of graph executions used to collect "
26 "/tensorflow/core/graph_run_time_usecs");
27
28 auto* graph_run_time_usecs = monitoring::Counter<0>::New(
29 "/tensorflow/core/graph_run_time_usecs",
30 "The total time spent on executing graphs in microseconds.");
31
32 auto* tf_data_autotune_counter = monitoring::Counter<1>::New(
33 "/tensorflow/data/autotune", "tf.data autotuning", "name");
34
35 auto* tf_data_bytes_read_counter = monitoring::Counter<1>::New(
36 "/tensorflow/data/bytes_read",
37 "The number of bytes read by tf.data Dataset sources.", "name");
38
39 auto* tf_data_elements_counter = monitoring::Counter<1>::New(
40 "/tensorflow/data/elements", "tf.data elements", "name");
41
42 auto* tf_data_optimization_counter = monitoring::Counter<1>::New(
43 "/tensorflow/data/optimization", "tf.data optimization", "name");
44
45 auto* build_graph_calls = monitoring::Counter<0>::New(
46 "/tensorflow/core/graph_build_calls",
47 "The number of times TensorFlow has created a new client graph. "
48 "A client graph is a sub-graph of the full graph, induced by a set of "
49 "options, including the requested feeds and fetches. It includes time "
50 "spent optimizing the graph with Grappler, and time spent pruning the "
51 "sub-graph.");
52
53 auto* build_graph_time_usecs = monitoring::Counter<0>::New(
54 "/tensorflow/core/graph_build_time_usecs",
55 "The amount of time TensorFlow has spent creating new client graphs in "
56 "microseconds. "
57 "A client graph is a sub-graph of the full graph, induced by a set of "
58 "options, including the requested feeds and fetches. It includes time "
59 "spent optimizing the graph with Grappler, and time spent pruning the "
60 "sub-graph.");
61
62 } // namespace
63
RecordTFDataAutotune(const string & name)64 void RecordTFDataAutotune(const string& name) {
65 tf_data_autotune_counter->GetCell(name)->IncrementBy(1);
66 }
67
RecordTFDataBytesRead(const string & name,int64 num_bytes)68 void RecordTFDataBytesRead(const string& name, int64 num_bytes) {
69 tf_data_bytes_read_counter->GetCell(name)->IncrementBy(num_bytes);
70 }
71
RecordTFDataElements(const string & name,int64 num_elements)72 void RecordTFDataElements(const string& name, int64 num_elements) {
73 tf_data_elements_counter->GetCell(name)->IncrementBy(num_elements);
74 }
75
RecordTFDataOptimization(const string & name,int64 num_changes)76 void RecordTFDataOptimization(const string& name, int64 num_changes) {
77 tf_data_optimization_counter->GetCell(name)->IncrementBy(num_changes);
78 }
79
UpdateGraphExecTime(const uint64 running_time_usecs)80 void UpdateGraphExecTime(const uint64 running_time_usecs) {
81 if (running_time_usecs > 0) {
82 graph_runs->GetCell()->IncrementBy(1);
83 graph_run_time_usecs->GetCell()->IncrementBy(running_time_usecs);
84 }
85 }
86
UpdateGraphBuildTime(const uint64 running_time_usecs)87 void UpdateGraphBuildTime(const uint64 running_time_usecs) {
88 if (running_time_usecs > 0) {
89 build_graph_calls->GetCell()->IncrementBy(1);
90 build_graph_time_usecs->GetCell()->IncrementBy(running_time_usecs);
91 }
92 }
93
94 } // namespace metrics
95 } // namespace tensorflow
96