Skip to content

Commit 4313fb0

Browse files
committed
Format changed code
1 parent c12adcd commit 4313fb0

3 files changed

Lines changed: 53 additions & 48 deletions

File tree

libCacheSim-python/src/cache_init.hpp

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,13 @@ static inline cache_t *create_sim_cache(const char *eviction_algo,
7070
const char *window_size = strstr(eviction_params, "window-size=");
7171
if (window_size == NULL) {
7272
char dest[30];
73-
strncpy(dest, eviction_params, 30);
74-
dest[29] = '\0';
73+
strncpy(dest, eviction_params, sizeof(dest) - 1);
74+
dest[sizeof(dest) - 1] = '\0';
7575
size_t param_len = strlen(dest);
7676
char *new_params = (char *)malloc(param_len + 20);
7777
if (param_len > 0) {
78-
snprintf(new_params, param_len + 20, "%s,window-size=0.01", eviction_params);
78+
snprintf(new_params, param_len + 20, "%s,window-size=0.01",
79+
eviction_params);
7980
} else { // if eviction_params is "", no comma is needed
8081
snprintf(new_params, 20, "window-size=0.01");
8182
}
@@ -87,30 +88,31 @@ static inline cache_t *create_sim_cache(const char *eviction_algo,
8788
}
8889
} else if (strcasecmp(eviction_algo, "wtinyLFU") == 0) {
8990
cache = WTinyLFU_init(cc_params, eviction_params);
90-
/* TODO(haocheng): add belady support, since we remove the trace path, format info needs to be passed in through another parameter */
91-
// } else if (strcasecmp(eviction_algo, "belady") == 0 &&
92-
// strcasestr(trace_path, "lcs") == NULL) {
93-
// if (strcasestr(trace_path, "oracleGeneral") == NULL) {
94-
// WARN("belady is only supported for oracleGeneral and lcs trace\n");
95-
// WARN("to convert a trace to lcs format\n");
96-
// WARN("./bin/traceConv input_trace trace_format output_trace\n");
97-
// WARN("./bin/traceConv ../data/cloudPhysicsIO.txt txt\n");
98-
// exit(1);
99-
// }
100-
// cache = Belady_init(cc_params, eviction_params);
91+
/* TODO(haocheng): add belady support, since we remove the trace path,
92+
* format info needs to be passed in through another parameter */
93+
// } else if (strcasecmp(eviction_algo, "belady") == 0 &&
94+
// strcasestr(trace_path, "lcs") == NULL) {
95+
// if (strcasestr(trace_path, "oracleGeneral") == NULL) {
96+
// WARN("belady is only supported for oracleGeneral and lcs trace\n");
97+
// WARN("to convert a trace to lcs format\n");
98+
// WARN("./bin/traceConv input_trace trace_format output_trace\n");
99+
// WARN("./bin/traceConv ../data/cloudPhysicsIO.txt txt\n");
100+
// exit(1);
101+
// }
102+
// cache = Belady_init(cc_params, eviction_params);
101103
} else if (strcasecmp(eviction_algo, "nop") == 0) {
102104
cache = nop_init(cc_params, eviction_params);
103-
// } else if (strcasecmp(eviction_algo, "beladySize") == 0) {
104-
// if (strcasestr(trace_path, "oracleGeneral") == NULL &&
105-
// strcasestr(trace_path, "lcs") == NULL) {
106-
// WARN("beladySize is only supported for oracleGeneral and lcs trace\n");
107-
// WARN("to convert a trace to lcs format\n");
108-
// WARN("./bin/traceConv input_trace trace_format output_trace\n");
109-
// WARN("./bin/traceConv ../data/cloudPhysicsIO.txt txt\n");
110-
// exit(1);
111-
// }
112-
// cc_params.hashpower = MAX(cc_params.hashpower - 8, 16);
113-
// cache = BeladySize_init(cc_params, eviction_params);
105+
// } else if (strcasecmp(eviction_algo, "beladySize") == 0) {
106+
// if (strcasestr(trace_path, "oracleGeneral") == NULL &&
107+
// strcasestr(trace_path, "lcs") == NULL) {
108+
// WARN("beladySize is only supported for oracleGeneral and lcs
109+
// trace\n"); WARN("to convert a trace to lcs format\n");
110+
// WARN("./bin/traceConv input_trace trace_format output_trace\n");
111+
// WARN("./bin/traceConv ../data/cloudPhysicsIO.txt txt\n");
112+
// exit(1);
113+
// }
114+
// cc_params.hashpower = MAX(cc_params.hashpower - 8, 16);
115+
// cache = BeladySize_init(cc_params, eviction_params);
114116
} else if (strcasecmp(eviction_algo, "fifo-reinsertion") == 0 ||
115117
strcasecmp(eviction_algo, "clock") == 0 ||
116118
strcasecmp(eviction_algo, "second-chance") == 0) {

libCacheSim-python/src/pylibcachesim.cpp

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
#include <iostream>
44

55
#include "cache_init.hpp"
6-
#include "utils.hpp"
76
#include "libCacheSim.h"
7+
#include "utils.hpp"
88

99
#define STRINGIFY(x) #x
1010
#define MACRO_STRINGIFY(x) STRINGIFY(x)
@@ -66,10 +66,9 @@ PYBIND11_MODULE(_libcachesim, m) {
6666
/**
6767
* @brief Request structure
6868
*/
69-
py::class_<request_t, std::unique_ptr<request_t, RequestDeleter>>(m, "Request")
70-
.def(py::init([]() {
71-
return new_request();
72-
}))
69+
py::class_<request_t, std::unique_ptr<request_t, RequestDeleter>>(m,
70+
"Request")
71+
.def(py::init([]() { return new_request(); }))
7372
.def_readwrite("clock_time", &request_t::clock_time)
7473
.def_readwrite("hv", &request_t::hv)
7574
.def_readwrite("obj_id", &request_t::obj_id)
@@ -85,13 +84,15 @@ PYBIND11_MODULE(_libcachesim, m) {
8584
.def_readwrite("trace_path", &reader_t::trace_path)
8685
.def_readwrite("file_size", &reader_t::file_size)
8786
// methods
88-
.def("get_wss", [](reader_t& self, bool ignore_obj_size) {
89-
90-
int64_t wss_obj = 0, wss_byte = 0;
91-
cal_working_set_size(&self, &wss_obj, &wss_byte);
92-
return ignore_obj_size ? wss_obj : wss_byte;
93-
}, py::arg("ignore_obj_size") = false,
94-
R"pbdoc(
87+
.def(
88+
"get_wss",
89+
[](reader_t& self, bool ignore_obj_size) {
90+
int64_t wss_obj = 0, wss_byte = 0;
91+
cal_working_set_size(&self, &wss_obj, &wss_byte);
92+
return ignore_obj_size ? wss_obj : wss_byte;
93+
},
94+
py::arg("ignore_obj_size") = false,
95+
R"pbdoc(
9596
Get the working set size of the trace.
9697
9798
Args:
@@ -170,12 +171,11 @@ PYBIND11_MODULE(_libcachesim, m) {
170171
*/
171172
m.def(
172173
"create_cache",
173-
[](const std::string& eviction_algo,
174-
const uint64_t cache_size, const std::string& eviction_params,
175-
bool consider_obj_metadata) {
176-
cache_t* ptr = create_sim_cache(
177-
eviction_algo.c_str(), cache_size,
178-
eviction_params.c_str(), consider_obj_metadata);
174+
[](const std::string& eviction_algo, const uint64_t cache_size,
175+
const std::string& eviction_params, bool consider_obj_metadata) {
176+
cache_t* ptr =
177+
create_sim_cache(eviction_algo.c_str(), cache_size,
178+
eviction_params.c_str(), consider_obj_metadata);
179179
return std::unique_ptr<cache_t, CacheDeleter>(ptr);
180180
},
181181
py::arg("eviction_algo"), py::arg("cache_size"),
@@ -193,8 +193,9 @@ PYBIND11_MODULE(_libcachesim, m) {
193193
Cache: A new cache instance.
194194
)pbdoc");
195195

196-
/* TODO(haocheng): should we support all parameters in the common_cache_params_t? (hash_power, etc.) */
197-
196+
/* TODO(haocheng): should we support all parameters in the
197+
* common_cache_params_t? (hash_power, etc.) */
198+
198199
// Currently supported eviction algorithms with direct initialization:
199200
// - "ARC"
200201
// - "Clock"
@@ -300,7 +301,8 @@ PYBIND11_MODULE(_libcachesim, m) {
300301
Cache: A new LRB cache instance.
301302
)pbdoc");
302303
#else
303-
// TODO(haocheng): add a dummy function to avoid the error when LRB is not enabled
304+
// TODO(haocheng): add a dummy function to avoid the error when LRB is not
305+
// enabled
304306
m.def(
305307
"LRB_init",
306308
[](uint64_t cache_size, std::string objective) {
@@ -406,7 +408,8 @@ PYBIND11_MODULE(_libcachesim, m) {
406408
Cache: A new ThreeL cache instance.
407409
)pbdoc");
408410
#else
409-
// TODO(haocheng): add a dummy function to avoid the error when ThreeLCache is not enabled
411+
// TODO(haocheng): add a dummy function to avoid the error when ThreeLCache is
412+
// not enabled
410413
m.def(
411414
"ThreeLCache_init",
412415
[](uint64_t cache_size, std::string objective) {

libCacheSim-python/src/utils.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include "libCacheSim/reader.h"
55

66
static inline void cal_working_set_size(reader_t *reader, int64_t *wss_obj,
7-
int64_t *wss_byte) {
7+
int64_t *wss_byte) {
88
reset_reader(reader);
99
request_t *req = new_request();
1010
GHashTable *obj_table = g_hash_table_new(g_direct_hash, g_direct_equal);

0 commit comments

Comments
 (0)