Skip to content

Commit 2d89aa7

Browse files
igchorbyrnedj
authored andcommitted
Add option to print memory stats in bytes only
1 parent b3621d1 commit 2d89aa7

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

cachelib/cachebench/cache/Cache.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ DEFINE_bool(report_api_latency,
2020
false,
2121
"Enable reporting cache API latency tracking");
2222

23-
DEFINE_bool(report_memory_usage_stats,
24-
false,
25-
"Enable reporting statistics for each allocation class");
23+
DEFINE_string(report_memory_usage_stats,
24+
"",
25+
"Enable reporting statistics for each allocation class. Set to"
26+
"'human_readable' to print KB/MB/GB or to 'raw' to print in bytes.");
2627

2728
namespace facebook {
2829
namespace cachelib {

cachelib/cachebench/cache/Cache.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
#include "cachelib/cachebench/util/NandWrites.h"
4545

4646
DECLARE_bool(report_api_latency);
47-
DECLARE_bool(report_memory_usage_stats);
47+
DECLARE_string(report_memory_usage_stats);
4848

4949
namespace facebook {
5050
namespace cachelib {

cachelib/cachebench/cache/CacheStats.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include "cachelib/common/PercentileStats.h"
2222

2323
DECLARE_bool(report_api_latency);
24-
DECLARE_bool(report_memory_usage_stats);
24+
DECLARE_string(report_memory_usage_stats);
2525

2626
namespace facebook {
2727
namespace cachelib {
@@ -136,12 +136,16 @@ struct Stats {
136136
<< std::endl;
137137
}
138138

139-
if (FLAGS_report_memory_usage_stats) {
139+
if (FLAGS_report_memory_usage_stats != "") {
140140
for (TierId tid = 0; tid < slabsApproxFreePercentages.size(); tid++) {
141141
out << folly::sformat("tid{:2} free slabs : {:.2f}%", tid, slabsApproxFreePercentages[tid]) << std::endl;
142142
}
143143

144-
auto formatMemory = [](size_t bytes) -> std::tuple<std::string, double> {
144+
auto formatMemory = [&](size_t bytes) -> std::tuple<std::string, double> {
145+
if (FLAGS_report_memory_usage_stats == "raw") {
146+
return {"B", bytes};
147+
}
148+
145149
constexpr double KB = 1024.0;
146150
constexpr double MB = 1024.0 * 1024;
147151
constexpr double GB = 1024.0 * 1024 * 1024;

0 commit comments

Comments
 (0)