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"""StatsOptions to configure stats aggregation options for `tf.data` pipelines.
16
17"""
18from __future__ import absolute_import
19from __future__ import division
20from __future__ import print_function
21
22from tensorflow.python.data.experimental.ops import stats_aggregator
23from tensorflow.python.data.util import options
24from tensorflow.python.util.tf_export import tf_export
25
26
27@tf_export("data.experimental.StatsOptions")
28class StatsOptions(options.OptionsBase):
29  """Represents options for collecting dataset stats using `StatsAggregator`.
30
31  You can set the stats options of a dataset through the `experimental_stats`
32  property of `tf.data.Options`; the property is an instance of
33  `tf.data.experimental.StatsOptions`. For example, to collect latency stats
34  on all dataset edges, use the following pattern:
35
36  ```python
37  aggregator = tf.data.experimental.StatsAggregator()
38
39  options = tf.data.Options()
40  options.experimental_stats.aggregator = aggregator
41  options.experimental_stats.latency_all_edges = True
42  dataset = dataset.with_options(options)
43  ```
44  """
45
46  aggregator = options.create_option(
47      name="aggregator",
48      ty=(stats_aggregator.StatsAggregatorV2,
49          stats_aggregator.StatsAggregatorV1),
50      docstring=
51      "Associates the given statistics aggregator with the dataset pipeline.")
52
53  prefix = options.create_option(
54      name="prefix",
55      ty=str,
56      docstring=
57      "Prefix to prepend all statistics recorded for the input `dataset` with.",
58      default_factory=lambda: "")
59
60  counter_prefix = options.create_option(
61      name="counter_prefix",
62      ty=str,
63      docstring="Prefix for the statistics recorded as counter.",
64      default_factory=lambda: "")
65
66  latency_all_edges = options.create_option(
67      name="latency_all_edges",
68      ty=bool,
69      docstring=
70      "Whether to add latency measurements on all edges. Defaults to False.")
71