Skip to content

Commit

Permalink
Automated Code Change
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 627311608
  • Loading branch information
tensorflower-gardener committed Apr 23, 2024
1 parent 810b672 commit 9a275cf
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 42 deletions.
Expand Up @@ -29,24 +29,25 @@ ProfilerCollection::ProfilerCollection(
std::vector<std::unique_ptr<ProfilerInterface>> profilers)
: profilers_(std::move(profilers)) {}

Status ProfilerCollection::Start() {
Status status;
absl::Status ProfilerCollection::Start() {
absl::Status status;
for (auto& profiler : profilers_) {
status.Update(profiler->Start());
}
return status;
}

Status ProfilerCollection::Stop() {
Status status;
absl::Status ProfilerCollection::Stop() {
absl::Status status;
for (auto& profiler : profilers_) {
status.Update(profiler->Stop());
}
return status;
}

Status ProfilerCollection::CollectData(tensorflow::profiler::XSpace* space) {
Status status;
absl::Status ProfilerCollection::CollectData(
tensorflow::profiler::XSpace* space) {
absl::Status status;
for (auto& profiler : profilers_) {
status.Update(profiler->CollectData(space));
}
Expand Down
Expand Up @@ -32,11 +32,11 @@ class ProfilerCollection : public ProfilerInterface {
explicit ProfilerCollection(
std::vector<std::unique_ptr<ProfilerInterface>> profilers);

Status Start() override;
absl::Status Start() override;

Status Stop() override;
absl::Status Stop() override;

Status CollectData(tensorflow::profiler::XSpace* space) override;
absl::Status CollectData(tensorflow::profiler::XSpace* space) override;

private:
std::vector<std::unique_ptr<ProfilerInterface>> profilers_;
Expand Down
Expand Up @@ -37,8 +37,8 @@ ProfilerController::~ProfilerController() {
}
}

Status ProfilerController::Start() {
Status status;
absl::Status ProfilerController::Start() {
absl::Status status;
if (state_ == ProfilerState::kInit) {
state_ = ProfilerState::kStart;
if (status_.ok()) {
Expand All @@ -53,8 +53,8 @@ Status ProfilerController::Start() {
return status;
}

Status ProfilerController::Stop() {
Status status;
absl::Status ProfilerController::Stop() {
absl::Status status;
if (state_ == ProfilerState::kStart) {
state_ = ProfilerState::kStop;
if (status_.ok()) {
Expand All @@ -69,8 +69,9 @@ Status ProfilerController::Stop() {
return status;
}

Status ProfilerController::CollectData(tensorflow::profiler::XSpace* space) {
Status status;
absl::Status ProfilerController::CollectData(
tensorflow::profiler::XSpace* space) {
absl::Status status;
if (state_ == ProfilerState::kStop) {
state_ = ProfilerState::kCollectData;
if (status_.ok()) {
Expand Down
Expand Up @@ -38,11 +38,11 @@ class ProfilerController : public ProfilerInterface {
explicit ProfilerController(std::unique_ptr<ProfilerInterface> profiler);
~ProfilerController() override;

Status Start() override;
absl::Status Start() override;

Status Stop() override;
absl::Status Stop() override;

Status CollectData(tensorflow::profiler::XSpace* space) override;
absl::Status CollectData(tensorflow::profiler::XSpace* space) override;

private:
enum class ProfilerState {
Expand All @@ -54,7 +54,7 @@ class ProfilerController : public ProfilerInterface {

ProfilerState state_ = ProfilerState::kInit;
std::unique_ptr<ProfilerInterface> profiler_;
Status status_; // result of calls to profiler_
absl::Status status_; // result of calls to profiler_
};

} // namespace profiler
Expand Down
Expand Up @@ -31,10 +31,10 @@ namespace {

class TestProfiler : public ProfilerInterface {
public:
Status Start() override { return OkStatus(); }
Status Stop() override { return OkStatus(); }
Status CollectData(tensorflow::profiler::XSpace*) override {
return OkStatus();
absl::Status Start() override { return absl::OkStatus(); }
absl::Status Stop() override { return absl::OkStatus(); }
absl::Status CollectData(tensorflow::profiler::XSpace*) override {
return absl::OkStatus();
}
};

Expand Down
Expand Up @@ -34,13 +34,13 @@ class ProfilerInterface {
virtual ~ProfilerInterface() = default;

// Starts profiling.
virtual Status Start() = 0;
virtual absl::Status Start() = 0;

// Stops profiling.
virtual Status Stop() = 0;
virtual absl::Status Stop() = 0;

// Saves collected profile data into XSpace.
virtual Status CollectData(tensorflow::profiler::XSpace* space) = 0;
virtual absl::Status CollectData(tensorflow::profiler::XSpace* space) = 0;
};

} // namespace profiler
Expand Down
Expand Up @@ -39,7 +39,7 @@ static_assert(ATOMIC_INT_LOCK_FREE == 2, "Assumed atomic<int> was lock free");
return g_session_active.load(std::memory_order_relaxed) != 0;
}

/*static*/ StatusOr<ProfilerLock> ProfilerLock::Acquire() {
/*static*/ absl::StatusOr<ProfilerLock> ProfilerLock::Acquire() {
// Use environment variable to permanently lock the profiler.
// This allows running TensorFlow under an external profiling tool with all
// built-in profiling disabled.
Expand Down
Expand Up @@ -35,7 +35,7 @@ class ProfilerLock {

// Acquires the profiler lock if no other profiler session is currently
// active.
static StatusOr<ProfilerLock> Acquire();
static absl::StatusOr<ProfilerLock> Acquire();

// Default constructor creates an inactive instance.
ProfilerLock() = default;
Expand Down
Expand Up @@ -29,22 +29,22 @@ TEST(ProfilerLockTest, DefaultConstructorCreatesInactiveInstance) {
}

TEST(ProfilerLockTest, AcquireAndReleaseExplicitly) {
StatusOr<ProfilerLock> profiler_lock = ProfilerLock::Acquire();
absl::StatusOr<ProfilerLock> profiler_lock = ProfilerLock::Acquire();
ASSERT_TRUE(profiler_lock.ok());
EXPECT_TRUE(profiler_lock->Active());
profiler_lock->ReleaseIfActive();
EXPECT_FALSE(profiler_lock->Active());
}

TEST(ProfilerLockTest, AcquireAndReleaseOnDestruction) {
StatusOr<ProfilerLock> profiler_lock = ProfilerLock::Acquire();
absl::StatusOr<ProfilerLock> profiler_lock = ProfilerLock::Acquire();
ASSERT_TRUE(profiler_lock.ok());
EXPECT_TRUE(profiler_lock->Active());
}

TEST(ProfilerLockTest, ReacquireWithoutReleaseFails) {
StatusOr<ProfilerLock> profiler_lock_1 = ProfilerLock::Acquire();
StatusOr<ProfilerLock> profiler_lock_2 = ProfilerLock::Acquire();
absl::StatusOr<ProfilerLock> profiler_lock_1 = ProfilerLock::Acquire();
absl::StatusOr<ProfilerLock> profiler_lock_2 = ProfilerLock::Acquire();
ASSERT_TRUE(profiler_lock_1.ok());
EXPECT_TRUE(profiler_lock_1->Active());
EXPECT_FALSE(profiler_lock_2.ok());
Expand All @@ -62,7 +62,7 @@ TEST(ProfilerLockTest, ReacquireAfterReleaseSucceeds) {
}

TEST(ProfilerLockTest, InactiveAfterMove) {
StatusOr<ProfilerLock> profiler_lock_1 = ProfilerLock::Acquire();
absl::StatusOr<ProfilerLock> profiler_lock_1 = ProfilerLock::Acquire();
ASSERT_TRUE(profiler_lock_1.ok());
ASSERT_TRUE(profiler_lock_1->Active());
ProfilerLock profiler_lock_2 = std::move(*profiler_lock_1);
Expand Down
Expand Up @@ -56,13 +56,13 @@ ProfileOptions GetOptions(const ProfileOptions& opts) {
return absl::WrapUnique(new ProfilerSession(options));
}

Status ProfilerSession::Status() {
absl::Status ProfilerSession::Status() {
mutex_lock l(mutex_);
return status_;
}

#if !defined(IS_MOBILE_PLATFORM)
Status ProfilerSession::CollectDataInternal(XSpace* space) {
absl::Status ProfilerSession::CollectDataInternal(XSpace* space) {
mutex_lock l(mutex_);
TF_RETURN_IF_ERROR(status_);
LOG(INFO) << "Profiler session collecting data.";
Expand All @@ -74,17 +74,17 @@ Status ProfilerSession::CollectDataInternal(XSpace* space) {
}
// Allow another session to start.
profiler_lock_.ReleaseIfActive();
return OkStatus();
return absl::OkStatus();
}
#endif

Status ProfilerSession::CollectData(XSpace* space) {
absl::Status ProfilerSession::CollectData(XSpace* space) {
#if !defined(IS_MOBILE_PLATFORM)
space->add_hostnames(port::Hostname());
TF_RETURN_IF_ERROR(CollectDataInternal(space));
profiler::PostProcessSingleHostXSpace(space, start_time_ns_, stop_time_ns_);
#endif
return OkStatus();
return absl::OkStatus();
}

ProfilerSession::ProfilerSession(const ProfileOptions& options)
Expand Down
Expand Up @@ -60,10 +60,10 @@ class ProfilerSession {
// Deletes an existing Profiler and enables starting a new one.
~ProfilerSession();

tsl::Status Status() TF_LOCKS_EXCLUDED(mutex_);
absl::Status Status() TF_LOCKS_EXCLUDED(mutex_);

// Collects profile data into XSpace.
tsl::Status CollectData(tensorflow::profiler::XSpace* space)
absl::Status CollectData(tensorflow::profiler::XSpace* space)
TF_LOCKS_EXCLUDED(mutex_);

private:
Expand All @@ -76,7 +76,7 @@ class ProfilerSession {

#if !defined(IS_MOBILE_PLATFORM)
// Collects profile data into XSpace without post-processsing.
tsl::Status CollectDataInternal(tensorflow::profiler::XSpace* space);
absl::Status CollectDataInternal(tensorflow::profiler::XSpace* space);

profiler::ProfilerLock profiler_lock_ TF_GUARDED_BY(mutex_);

Expand All @@ -86,7 +86,7 @@ class ProfilerSession {
uint64 stop_time_ns_;
tensorflow::ProfileOptions options_;
#endif
tsl::Status status_ TF_GUARDED_BY(mutex_);
absl::Status status_ TF_GUARDED_BY(mutex_);
mutex mutex_;
};

Expand Down

0 comments on commit 9a275cf

Please sign in to comment.