Skip to content

Commit 8478fda

Browse files
igchorvinser52
authored andcommitted
Add option to print memory stats in bytes only
1 parent cd2b3ad commit 8478fda

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

cachelib/cachebench/cache/Cache.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ DEFINE_bool(report_api_latency,
2222
false,
2323
"Enable reporting cache API latency tracking");
2424

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

2930
namespace facebook {
3031
namespace cachelib {

cachelib/cachebench/cache/Cache.h

+1-1
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

+7-3
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 {
@@ -135,12 +135,16 @@ struct Stats {
135135
<< std::endl;
136136
}
137137

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

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

0 commit comments

Comments
 (0)