From 62acd0bf195ea47463716d294bed916e2eec3343 Mon Sep 17 00:00:00 2001 From: Andrew Audibert Date: Tue, 12 Jan 2021 10:16:18 -0800 Subject: [PATCH] [tf.data] Add vlogging for time spent restoring each stage of a dataset iterator. PiperOrigin-RevId: 351396158 Change-Id: I71ff55afa330ec01006cdb2d0b09de1dfba7454f --- tensorflow/core/framework/dataset.h | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/tensorflow/core/framework/dataset.h b/tensorflow/core/framework/dataset.h index fd3004a371f..d485be68fd7 100644 --- a/tensorflow/core/framework/dataset.h +++ b/tensorflow/core/framework/dataset.h @@ -665,7 +665,11 @@ class IteratorBase { // Saves the state of this iterator. virtual Status Save(SerializationContext* ctx, IteratorStateWriter* writer) { - return SaveInternal(ctx, writer); + int64 start_us = EnvTime::NowMicros(); + TF_RETURN_IF_ERROR(SaveInternal(ctx, writer)); + VLOG(1) << "Saved " << prefix() << " in " + << (EnvTime::NowMicros() - start_us) << "us"; + return Status::OK(); } protected: @@ -675,21 +679,33 @@ class IteratorBase { // Restores the state of this iterator. Status Restore(IteratorContext* ctx, IteratorStateReader* reader) { - return RestoreInternal(ctx, reader); + int64 start_us = EnvTime::NowMicros(); + TF_RETURN_IF_ERROR(RestoreInternal(ctx, reader)); + VLOG(1) << "Restored " << prefix() << " in " + << (EnvTime::NowMicros() - start_us) << "us"; + return Status::OK(); } // This is needed so that sub-classes of IteratorBase can call // `SaveInternal` on their input iterators. Status SaveInput(SerializationContext* ctx, IteratorStateWriter* writer, const std::unique_ptr& input) { - return input->SaveInternal(ctx, writer); + int64 start_us = EnvTime::NowMicros(); + TF_RETURN_IF_ERROR(input->SaveInternal(ctx, writer)); + VLOG(2) << "Saved " << input->prefix() << " in " + << (EnvTime::NowMicros() - start_us) << "us"; + return Status::OK(); } // This is needed so that sub-classes of IteratorBase can call // `RestoreInternal` on their input iterators. Status RestoreInput(IteratorContext* ctx, IteratorStateReader* reader, const std::unique_ptr& input) { - return input->RestoreInternal(ctx, reader); + int64 start_us = EnvTime::NowMicros(); + TF_RETURN_IF_ERROR(input->RestoreInternal(ctx, reader)); + VLOG(2) << "Restored " << input->prefix() << " in " + << (EnvTime::NowMicros() - start_us) << "us"; + return Status::OK(); } // Saves the state of this iterator.