From 67cc11ad6f5fb7b1e1948513292ef00edee34f5e Mon Sep 17 00:00:00 2001 From: Assaf Gordon Date: Mon, 31 Jan 2022 15:35:29 -0800 Subject: [PATCH] add helper class for fmt>8.1 Summary: This is a long-term solution instead of the 'quick fix' of D33661759 . fmt version >=8.1 changed internal structures and does not automatically format the 'DestructorContext' enum. Add a helper class to format the enum to strings, based on the example in https://fmt.dev/latest/api.html#udt . NOTE: This changes the debug output of the ItemRecords::validate() function (the last two parameters in the two XLOGF calls). Reviewed By: therealgymmy Differential Revision: D33662085 fbshipit-source-id: 608b498c762ca95cc71cb1597831a5c2a5f2c575 --- cachelib/cachebench/cache/ItemRecords.h | 26 +++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/cachelib/cachebench/cache/ItemRecords.h b/cachelib/cachebench/cache/ItemRecords.h index 651972722..cc1cfe100 100644 --- a/cachelib/cachebench/cache/ItemRecords.h +++ b/cachelib/cachebench/cache/ItemRecords.h @@ -22,6 +22,32 @@ #include "cachelib/allocator/Cache.h" #include "cachelib/cachebench/cache/CacheValue.h" +using DestructorContext = facebook::cachelib::DestructorContext; +/* From: https://fmt.dev/latest/api.html#udt */ +template <> +struct fmt::formatter : formatter { + // parse is inherited from formatter. + template + auto format(DestructorContext c, FormatContext& ctx) { + string_view name = "unknown"; + switch (c) { + case DestructorContext::kEvictedFromRAM: + name = "kEvictedFromRAM"; + break; + case DestructorContext::kEvictedFromNVM: + name = "kEvictedFromNVM"; + break; + case DestructorContext::kRemovedFromRAM: + name = "kRemovedFromRAM"; + break; + case DestructorContext::kRemovedFromNVM: + name = "kRemovedFromNVM"; + break; + } + return formatter::format(name, ctx); + } +}; + namespace facebook::cachelib::cachebench { /* * ItemRecord and ItemRecords are used for DestructorCheck in cachebench.