-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add stats tracking using CVal for starboard storage and file writes f…
…rom cobalt. b/277761317 Change-Id: Iabc8bf97772cfa42d9f0f0425eeef91376e4044d
- Loading branch information
1 parent
d0684de
commit 65ef806
Showing
10 changed files
with
205 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Copyright 2023 The Cobalt Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#ifndef COBALT_BASE_STARBOARD_STATS_TRACKER_H_ | ||
#define COBALT_BASE_STARBOARD_STATS_TRACKER_H_ | ||
|
||
#include "cobalt/base/c_val.h" | ||
#include "starboard/common/metrics/stats_tracker.h" | ||
|
||
class StarboardStatsTracker : public starboard::StatsTracker { | ||
public: | ||
StarboardStatsTracker() | ||
: file_write_success_("Starboard.FileWrite.Success", 0, | ||
"SbFileWrite() success count from cobalt."), | ||
file_write_fail_("Starboard.FileWrite.Fail", 0, | ||
"SbFileWrite() fail count from cobalt."), | ||
file_write_bytes_written_("Starboard.FileWrite.BytesWritten", 0, | ||
"SbFileWrite() bytes written from cobalt."), | ||
storage_write_record_success_( | ||
"Starboard.StorageWriteRecord.Success", 0, | ||
"SbStorageWriteRecord() success count from cobalt."), | ||
storage_write_record_fail_( | ||
"Starboard.StorageWriteRecord.Fail", 0, | ||
"SbStorageWriteRecord() fail count from cobalt."), | ||
storage_write_record_bytes_written_( | ||
"Starboard.StorageWriteRecord.BytesWritten", 0, | ||
"SbStorageWriteRecord() bytes written from cobalt.") {} | ||
|
||
void FileWriteSuccess() override { ++file_write_success_; } | ||
|
||
void FileWriteFail() override { ++file_write_fail_; } | ||
|
||
void FileWriteBytesWritten(int bytes_written) override { | ||
file_write_bytes_written_ += bytes_written; | ||
} | ||
|
||
void StorageWriteRecordSuccess() override { ++storage_write_record_success_; } | ||
|
||
void StorageWriteRecordFail() override { ++storage_write_record_fail_; } | ||
|
||
void StorageWriteRecordBytesWritten(int bytes_written) override { | ||
storage_write_record_bytes_written_ += bytes_written; | ||
} | ||
|
||
private: | ||
base::CVal<int, base::CValPublic> file_write_success_; | ||
base::CVal<int, base::CValPublic> file_write_fail_; | ||
base::CVal<base::cval::SizeInBytes, base::CValPublic> | ||
file_write_bytes_written_; | ||
base::CVal<int, base::CValPublic> storage_write_record_success_; | ||
base::CVal<int, base::CValPublic> storage_write_record_fail_; | ||
base::CVal<base::cval::SizeInBytes, base::CValPublic> | ||
storage_write_record_bytes_written_; | ||
}; | ||
|
||
#endif // COBALT_BASE_STARBOARD_STATS_TRACKER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright 2023 The Cobalt Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "starboard/common/metrics/stats_tracker.h" | ||
|
||
#include "starboard/once.h" | ||
|
||
namespace starboard { | ||
|
||
SB_ONCE_INITIALIZE_FUNCTION(StatsTrackerContainer, | ||
StatsTrackerContainer::GetInstance); | ||
|
||
} // namespace starboard |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// Copyright 2023 The Cobalt Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#ifndef STARBOARD_COMMON_METRICS_STATS_TRACKER_H_ | ||
#define STARBOARD_COMMON_METRICS_STATS_TRACKER_H_ | ||
|
||
#include <memory> | ||
#include <utility> | ||
|
||
#include "starboard/common/log.h" | ||
|
||
namespace starboard { | ||
|
||
class StatsTracker { | ||
public: | ||
virtual ~StatsTracker() = default; | ||
|
||
virtual void FileWriteSuccess() = 0; | ||
virtual void FileWriteFail() = 0; | ||
virtual void FileWriteBytesWritten(int bytes_written) = 0; | ||
|
||
virtual void StorageWriteRecordSuccess() = 0; | ||
virtual void StorageWriteRecordFail() = 0; | ||
virtual void StorageWriteRecordBytesWritten(int bytes_written) = 0; | ||
}; | ||
|
||
class StatsTrackerUndefined : public StatsTracker { | ||
public: | ||
void FileWriteSuccess() override {} | ||
void FileWriteFail() override {} | ||
void FileWriteBytesWritten(int bytes_written) override {} | ||
|
||
void StorageWriteRecordSuccess() override {} | ||
void StorageWriteRecordFail() override {} | ||
void StorageWriteRecordBytesWritten(int bytes_written) override {} | ||
}; | ||
|
||
class StatsTrackerContainer { | ||
public: | ||
static StatsTrackerContainer* GetInstance(); | ||
|
||
StatsTracker& stats_tracker() { | ||
if (!stats_tracker_) { | ||
SB_DLOG_IF(ERROR, !undefined_logged_) | ||
<< "[once] StatsTracker is not defined."; | ||
undefined_logged_ = true; | ||
return undefined_stats_tracker_; | ||
} | ||
return *(stats_tracker_.get()); | ||
} | ||
|
||
void set_stats_tracker(std::unique_ptr<StatsTracker> stats_tracker) { | ||
stats_tracker_ = std::move(stats_tracker); | ||
} | ||
|
||
private: | ||
StatsTrackerUndefined undefined_stats_tracker_; | ||
std::unique_ptr<StatsTracker> stats_tracker_; | ||
bool undefined_logged_ = false; | ||
}; | ||
|
||
} // namespace starboard | ||
|
||
#endif // STARBOARD_COMMON_METRICS_STATS_TRACKER_H_ |