Skip to content

Commit

Permalink
feat: Add storage statistics in IoStatistics
Browse files Browse the repository at this point in the history
  • Loading branch information
kewang1024 committed Jan 30, 2025
1 parent 3fd46c7 commit d1714b7
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
35 changes: 32 additions & 3 deletions velox/common/io/IoStatistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,24 @@ IoStatistics::operationStats() const {
return operationStats_;
}

std::unordered_map<std::string, RuntimeMetric> IoStatistics::storageStats()
const {
std::lock_guard<std::mutex> lock{storageStatsMutex_};
return storageStats_;
}

void IoStatistics::addStorageStats(
const std::string& name,
const RuntimeCounter& counter) {
std::lock_guard<std::mutex> lock{storageStatsMutex_};
if (storageStats_.count(name) == 0) {
storageStats_.emplace(name, RuntimeMetric(counter.unit));
} else {
VELOX_CHECK_EQ(storageStats_.at(name).unit, counter.unit);
}
storageStats_.at(name).addValue(counter.value);
}

void IoStatistics::merge(const IoStatistics& other) {
rawBytesRead_ += other.rawBytesRead_;
rawBytesWritten_ += other.rawBytesWritten_;
Expand All @@ -119,9 +137,20 @@ void IoStatistics::merge(const IoStatistics& other) {
ramHit_.merge(other.ramHit_);
ssdRead_.merge(other.ssdRead_);
queryThreadIoLatency_.merge(other.queryThreadIoLatency_);
std::lock_guard<std::mutex> l(operationStatsMutex_);
for (auto& item : other.operationStats_) {
operationStats_[item.first].merge(item.second);
{
const auto& otherOperationStats = other.operationStats();
std::lock_guard<std::mutex> l(operationStatsMutex_);
for (auto& item : otherOperationStats) {
operationStats_[item.first].merge(item.second);
}
}

{
const auto& otherStorageStats = other.storageStats();
std::lock_guard<std::mutex> storageStatsLock(storageStatsMutex_);
for (auto& item : otherStorageStats) {
storageStats_[item.first].merge(item.second);
}
}
}

Expand Down
7 changes: 7 additions & 0 deletions velox/common/io/IoStatistics.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include <unordered_map>

#include <folly/dynamic.h>
#include "velox/common/base/Exceptions.h"
#include "velox/common/base/RuntimeMetrics.h"

namespace facebook::velox::io {

Expand Down Expand Up @@ -140,6 +142,9 @@ class IoStatistics {
const uint64_t partialThrottleCount = 0);

std::unordered_map<std::string, OperationCounters> operationStats() const;
std::unordered_map<std::string, RuntimeMetric> storageStats() const;

void addStorageStats(const std::string& name, const RuntimeCounter& counter);

void merge(const IoStatistics& other);

Expand Down Expand Up @@ -172,7 +177,9 @@ class IoStatistics {
IoCounter queryThreadIoLatency_;

std::unordered_map<std::string, OperationCounters> operationStats_;
std::unordered_map<std::string, RuntimeMetric> storageStats_;
mutable std::mutex operationStatsMutex_;
mutable std::mutex storageStatsMutex_;
};

} // namespace facebook::velox::io

0 comments on commit d1714b7

Please sign in to comment.