Skip to content

Commit

Permalink
Add fmt::format_as for SpillStats and MemoryArbitrator::Stats (facebo…
Browse files Browse the repository at this point in the history
…okincubator#8608)

Summary: Pull Request resolved: facebookincubator#8608

Reviewed By: xiaoxmeng, bikramSingh91

Differential Revision: D53245177

Pulled By: kgpai

fbshipit-source-id: 1ccb4d27b0abe947a3b59ca220092e5e17ce21ac
  • Loading branch information
majetideepak authored and facebook-github-bot committed Jan 31, 2024
1 parent a65afdb commit 280fc86
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
10 changes: 10 additions & 0 deletions velox/common/base/SpillStats.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,13 @@ void updateGlobalMaxSpillLevelExceededCount(
/// Gets the cumulative global spill stats.
SpillStats globalSpillStats();
} // namespace facebook::velox::common

template <>
struct fmt::formatter<facebook::velox::common::SpillStats>
: fmt::formatter<std::string> {
auto format(
const facebook::velox::common::SpillStats& s,
format_context& ctx) {
return formatter<std::string>::format(s.toString(), ctx);
}
};
3 changes: 3 additions & 0 deletions velox/common/base/tests/SpillStatsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,7 @@ TEST(SpillTest, spillStats) {
ASSERT_EQ(
stats2.toString(),
"spillRuns[100] spilledInputBytes[2.00KB] spilledBytes[1.00KB] spilledRows[1031] spilledPartitions[1025] spilledFiles[1026] spillFillTimeUs[1.03ms] spillSortTime[1.03ms] spillSerializationTime[1.03ms] spillWrites[1028] spillFlushTime[1.03ms] spillWriteTime[1.03ms] maxSpillExceededLimitCount[4]");
ASSERT_EQ(
fmt::format("{}", stats2),
"spillRuns[100] spilledInputBytes[2.00KB] spilledBytes[1.00KB] spilledRows[1031] spilledPartitions[1025] spilledFiles[1026] spillFillTimeUs[1.03ms] spillSortTime[1.03ms] spillSerializationTime[1.03ms] spillWrites[1028] spillFlushTime[1.03ms] spillWriteTime[1.03ms] maxSpillExceededLimitCount[4]");
}
5 changes: 5 additions & 0 deletions velox/common/memory/MemoryArbitrator.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@ class MemoryArbitrator {
const bool checkUsageLeak_;
};

/// Formatter for fmt.
FOLLY_ALWAYS_INLINE std::string format_as(MemoryArbitrator::Stats stats) {
return stats.toString();
}

FOLLY_ALWAYS_INLINE std::ostream& operator<<(
std::ostream& o,
const MemoryArbitrator::Stats& stats) {
Expand Down
7 changes: 7 additions & 0 deletions velox/common/memory/tests/MemoryArbitratorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ TEST_F(MemoryArbitrationTest, stats) {
"queueTime 230.00ms arbitrationTime 1.02ms reclaimTime 1.00ms "
"shrunkMemory 95.37MB reclaimedMemory 9.77KB "
"maxCapacity 0B freeCapacity 0B]");
ASSERT_EQ(
fmt::format("{}", stats),
"STATS[numRequests 2 numSucceeded 0 numAborted 3 numFailures 100 "
"numNonReclaimableAttempts 5 numReserves 0 numReleases 0 "
"queueTime 230.00ms arbitrationTime 1.02ms reclaimTime 1.00ms "
"shrunkMemory 95.37MB reclaimedMemory 9.77KB "
"maxCapacity 0B freeCapacity 0B]");
}

TEST_F(MemoryArbitrationTest, create) {
Expand Down

0 comments on commit 280fc86

Please sign in to comment.