Skip to content

Commit

Permalink
add helper class for fmt>8.1
Browse files Browse the repository at this point in the history
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
  • Loading branch information
agordon authored and facebook-github-bot committed Jan 31, 2022
1 parent 68351f4 commit 67cc11a
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions cachelib/cachebench/cache/ItemRecords.h
Expand Up @@ -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<DestructorContext> : formatter<string_view> {
// parse is inherited from formatter<string_view>.
template <typename FormatContext>
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<string_view>::format(name, ctx);
}
};

namespace facebook::cachelib::cachebench {
/*
* ItemRecord and ItemRecords are used for DestructorCheck in cachebench.
Expand Down

0 comments on commit 67cc11a

Please sign in to comment.