diff --git a/velox/common/base/SpillStats.h b/velox/common/base/SpillStats.h index 61f0efd592ef..ff276853a4c4 100644 --- a/velox/common/base/SpillStats.h +++ b/velox/common/base/SpillStats.h @@ -141,3 +141,13 @@ void updateGlobalMaxSpillLevelExceededCount( /// Gets the cumulative global spill stats. SpillStats globalSpillStats(); } // namespace facebook::velox::common + +template <> +struct fmt::formatter + : fmt::formatter { + auto format( + const facebook::velox::common::SpillStats& s, + format_context& ctx) { + return formatter::format(s.toString(), ctx); + } +}; diff --git a/velox/common/base/tests/SpillStatsTest.cpp b/velox/common/base/tests/SpillStatsTest.cpp index 7a74c1e09a7d..376ae6b6c8ab 100644 --- a/velox/common/base/tests/SpillStatsTest.cpp +++ b/velox/common/base/tests/SpillStatsTest.cpp @@ -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]"); } diff --git a/velox/common/memory/MemoryArbitrator.h b/velox/common/memory/MemoryArbitrator.h index 4791e1a6cc93..e0ee291927b9 100644 --- a/velox/common/memory/MemoryArbitrator.h +++ b/velox/common/memory/MemoryArbitrator.h @@ -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) { diff --git a/velox/common/memory/tests/MemoryArbitratorTest.cpp b/velox/common/memory/tests/MemoryArbitratorTest.cpp index cc9851e8a95d..316a6e90d92c 100644 --- a/velox/common/memory/tests/MemoryArbitratorTest.cpp +++ b/velox/common/memory/tests/MemoryArbitratorTest.cpp @@ -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) {