• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef TENSORFLOW_CORE_FRAMEWORK_METRICS_H_
17 #define TENSORFLOW_CORE_FRAMEWORK_METRICS_H_
18 
19 #include "tensorflow/core/lib/monitoring/counter.h"
20 #include "tensorflow/core/platform/types.h"
21 
22 namespace tensorflow {
23 namespace metrics {
24 
25 // Records that a tf.data.Dataset executed by the program used autotuning.
26 //
27 // The `name` argument identifies the Dataset type (e.g. "ParallelMap").
28 void RecordTFDataAutotune(const string& name);
29 
30 // Returns a counter that can be used to record the number of bytes produced by
31 // a tf.data.Dataset.
32 //
33 // The `name` argument identifies the Dataset type (e.g. "Batch" or "Map").
34 monitoring::CounterCell* GetTFDataBytesConsumedCounter(const string& name);
35 
36 // Returns a counter that can be used to record the number of bytes produced by
37 // a tf.data.Dataset.
38 //
39 // The `name` argument identifies the Dataset type (e.g. "Batch" or "Map").
40 monitoring::CounterCell* GetTFDataBytesProducedCounter(const string& name);
41 
42 // Returns a counter than can be used to record the number of bytes read from
43 // the filesystem by a tf.data.Dataset source.
44 //
45 // The `name` argument identifies the Dataset type (e.g. "TFRecordDataset").
46 //
47 // TODO(jsimsa): Remove this now that we have GetTFDataBytesConsumedCounter?
48 monitoring::CounterCell* GetTFDataBytesReadCounter(const string& name);
49 
50 // Returns a counter than can be used to record the number of elements produced
51 // by a tf.data.Dataset.
52 //
53 // The `name` argument identifies the Dataset type (e.g. "Batch" or "Map").
54 monitoring::CounterCell* GetTFDataElementsCounter(const string& name);
55 
56 // Records the number of bytes fetched from tf.data.Dataset iterator.
57 void RecordTFDataBytesFetched(int64 num_bytes);
58 
59 // Records the number of times tf.data experiment is applied to input pipelines.
60 void RecordTFDataExperiment(const string& name);
61 
62 // Records the time (in microseconds) spent in a single invocation of
63 // `ItertatorResource::GetNext()`.
64 void RecordTFDataGetNextDuration(uint64 duration_us);
65 
66 // Records the number of times each tf.data fingerprint is used
67 // to measure duplicate pre-processing.
68 //
69 // The `name` argument identifies the Dataset graph fingerprint,
70 // created using GraphHash().
71 void RecordTFDataFingerprint(const string& name);
72 
73 // Records the time (in microseconds) during which `IteratorResource` was busy
74 // processing at least one `GetNext()` request.
75 void RecordTFDataIteratorBusy(uint64 duration_us);
76 
77 // Records the time (in microseconds) between `IteratorResource` receiving the
78 // first `GetNext()` request and responding to the last `GetNext()` request.
79 void RecordTFDataIteratorLifetime(uint64 duration_us);
80 
81 // Records the number of independent graph changes resulting from the
82 // application of a tf.data optimization.
83 //
84 // The `name` argument identifies the optimization (e.g. "noop_elimination").
85 void RecordTFDataOptimization(const string& name, int64 num_changes);
86 
87 // Records the file name read by a tf.data Dataset.
88 //
89 // The `name` argument identifies the Dataset type (e.g. "TFRecordDataset").
90 void RecordTFDataFilename(const string& name, const string& filename);
91 
92 // Records parsing of dense tensor features.
93 void RecordParseDenseFeature(int64 num_features);
94 
95 // Records parsing of sparse tensor features.
96 void RecordParseSparseFeature(int64 num_features);
97 
98 // Records parsing of ragged tensor features.
99 void RecordParseRaggedFeature(int64 num_features);
100 
101 // Records the size of input/output tensors in bytes.
102 void RecordGraphInputTensors(const size_t size);
103 void RecordGraphOutputTensors(const size_t size);
104 
105 void UpdateGraphExecTime(const uint64 running_time_usecs);
106 void UpdateGraphPendingQueueLength(uint64 len);
107 
108 // Records that one output of an op of type `op_name` was unused.
109 void RecordUnusedOutput(const string& op_name);
110 
111 // Updates the metrics stored about time spent building graphs.
112 //
113 // By "GraphBuild", we refer to building a client graph, which is a sub-graph of
114 // the full graph, induced by a set of options. In particular, these options
115 // include the feeds and fetches requested.
116 //
117 // This includes time spent:
118 //   * optimizing the graphs with Grappler
119 //   * pruning the sub-graph (unless the place_pruned_graph option is set)
120 //
121 // When executing eagerly, this will not record any activity.
122 //
123 // TODO(jtkeeling): Should we record building/optimizing tf.functions?
124 void UpdateGraphBuildTime(const uint64 running_time_usecs);
125 
126 // Updates the metrics stored about graph optimizations.
127 void UpdateGraphOptimizationPassTime(const string& pass_name,
128                                      const uint64 running_time_usecs);
129 void UpdateGrapplerPassTime(const string& pass_name,
130                             const uint64 running_time_usecs);
131 
132 // Updates the metrics stored about time XLA spents compiling graphs.
133 void UpdateXlaCompilationTime(const uint64 compilation_time_usecs);
134 
135 // Updates the metrics stored about time BFC allocator spents during delay.
136 void UpdateBfcAllocatorDelayTime(const uint64 delay_usecs);
137 
138 // Increment the number of jobs that failed during import to mlir.
139 void IncrementMLIRImportFailureCount();
140 
141 }  // namespace metrics
142 }  // namespace tensorflow
143 
144 #endif  // TENSORFLOW_CORE_FRAMEWORK_METRICS_H_
145