提交 3b427da5 编写于 作者: J Jiri Simsa 提交者: TensorFlower Gardener

[tf.data] Collecting additional TraceMe metadata for `prefetch`.

PiperOrigin-RevId: 339906797
Change-Id: Ieff06a2d26a3b7bfc90987bba8457f1ff866f8af
上级 bf581d89
......@@ -805,6 +805,7 @@ tf_kernel_library(
"//tensorflow/core:core_cpu_internal",
"//tensorflow/core:dataset_ops_op_lib",
"//tensorflow/core:framework",
"//tensorflow/core:framework_internal",
"//tensorflow/core:lib",
"//tensorflow/core:lib_internal",
"//tensorflow/core:protos_all_cc",
......
......@@ -18,6 +18,7 @@ limitations under the License.
#include "tensorflow/core/common_runtime/metrics.h"
#include "tensorflow/core/framework/dataset.h"
#include "tensorflow/core/framework/model.h"
#include "tensorflow/core/framework/partial_tensor_shape.h"
#include "tensorflow/core/framework/stats_aggregator.h"
#include "tensorflow/core/framework/tensor.h"
......@@ -46,6 +47,8 @@ namespace data {
/* static */ constexpr const char* const PrefetchDatasetOp::kSlackPeriod;
/* static */ constexpr const char* const PrefetchDatasetOp::kLegacyAutotune;
namespace {
// Determines the fraction of slack time by which to delay prefetching of data.
constexpr double kSleepFactor = 0.2;
constexpr char kBuffer[] = "buffer";
......@@ -54,6 +57,8 @@ constexpr char kSizeSuffix[] = ".size";
constexpr char kCodeSuffix[] = ".code";
constexpr char kErrorMessageSuffix[] = ".error_message";
} // namespace
class PrefetchDatasetOp::Dataset : public DatasetBase {
public:
Dataset(OpKernelContext* ctx, const DatasetBase* input, int64 buffer_size,
......@@ -282,17 +287,26 @@ class PrefetchDatasetOp::Dataset : public DatasetBase {
}
data::TraceMeMetadata GetTraceMeMetadata() const override {
int64 limit = -1;
int64 limit = -1, size = -1;
// NOTE: We only set the parallelism value if the lock can be acquired
// right away to avoid introducing tracing overhead.
if (mu_->try_lock()) {
limit = buffer_limit();
size = buffer_.size();
mu_->unlock();
}
data::TraceMeMetadata result;
result.push_back(std::make_pair(
"buffer_limit",
strings::Printf("%lld", static_cast<long long>(limit))));
result.push_back(std::make_pair(
"buffer_size",
strings::Printf("%lld", static_cast<long long>(size))));
result.push_back(std::make_pair(
"autotune",
dataset()->buffer_size_ == model::kAutotune ? "true" : "false"));
result.push_back(std::make_pair(
"autotune_mode", legacy_autotune_ ? "legacy" : "performance"));
if (dataset()->slack_period_ > 0) {
result.push_back(std::make_pair(
"slack",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册