Skip to content

Commit 67cc11a

Browse files
agordonfacebook-github-bot
authored andcommitted
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
1 parent 68351f4 commit 67cc11a

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

cachelib/cachebench/cache/ItemRecords.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,32 @@
2222
#include "cachelib/allocator/Cache.h"
2323
#include "cachelib/cachebench/cache/CacheValue.h"
2424

25+
using DestructorContext = facebook::cachelib::DestructorContext;
26+
/* From: https://fmt.dev/latest/api.html#udt */
27+
template <>
28+
struct fmt::formatter<DestructorContext> : formatter<string_view> {
29+
// parse is inherited from formatter<string_view>.
30+
template <typename FormatContext>
31+
auto format(DestructorContext c, FormatContext& ctx) {
32+
string_view name = "unknown";
33+
switch (c) {
34+
case DestructorContext::kEvictedFromRAM:
35+
name = "kEvictedFromRAM";
36+
break;
37+
case DestructorContext::kEvictedFromNVM:
38+
name = "kEvictedFromNVM";
39+
break;
40+
case DestructorContext::kRemovedFromRAM:
41+
name = "kRemovedFromRAM";
42+
break;
43+
case DestructorContext::kRemovedFromNVM:
44+
name = "kRemovedFromNVM";
45+
break;
46+
}
47+
return formatter<string_view>::format(name, ctx);
48+
}
49+
};
50+
2551
namespace facebook::cachelib::cachebench {
2652
/*
2753
* ItemRecord and ItemRecords are used for DestructorCheck in cachebench.

0 commit comments

Comments
 (0)