Skip to content

Commit 8342380

Browse files
authored
feat: Enhance request struct and add debug logging (#81)
* feat: Enhance request struct and add debug logging * doc: add doc about print-head-req
1 parent 2f60805 commit 8342380

File tree

10 files changed

+46
-22
lines changed

10 files changed

+46
-22
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ example/cacheSimulatorC/cmake-build-debug
1515
fig/
1616
# Chaos
1717
sftp-config.json
18+
# Clangd cache
19+
*.cache/

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ set(CMAKE_CXX_STANDARD 17)
1313
set(CMAKE_CXX_STANDARD_REQUIRED On)
1414
set(CMAKE_CXX_EXTENSIONS Off)
1515

16+
# export compile commands, useful for IDEs
17+
set(EXPORT_COMPILE_COMMANDS ON)
1618
########################################
1719
# define options #
1820
# options are cached variables https://stackoverflow.com/questions/35744647/disabling-cmake-option-has-no-effect

doc/quickstart_cachesim.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ You can use `-p` or `--prefetch` to set the prefetching algorithm.
185185
# Use TTL
186186
./cachesim ../data/trace.vscsi vscsi lru 1gb --use-ttl=true
187187

188+
# Disable the print of the first few requests
189+
./cachesim ../data/trace.vscsi vscsi lru 1gb --print-head-req=false
188190
```
189191

190192

example/cacheSimulator/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ int main(int argc, char **argv) {
2323

2424
/* read one request and print */
2525
read_one_req(reader, req);
26-
print_request(req);
26+
print_request(req, INFO_LEVEL);
2727

2828
/* setup a cache */
2929
common_cache_params_t cc_params = {

libCacheSim/bin/cachesim/cli_parser.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ enum argp_option_short {
4747

4848
OPTION_PREFETCH_ALGO = 'p',
4949
OPTION_PREFETCH_PARAMS = 0x109,
50+
OPTION_PRINT_HEAD_REQ = 0x10a,
5051
};
5152

5253
/*
@@ -93,6 +94,8 @@ static struct argp_option options[] = {
9394
{"consider-obj-metadata", OPTION_CONSIDER_OBJ_METADATA, "false", 0,
9495
"Whether consider per object metadata size in the simulated cache", 10},
9596
{"verbose", OPTION_VERBOSE, "1", 0, "Produce verbose output", 10},
97+
{"print-head-req", OPTION_PRINT_HEAD_REQ, "false", 0,
98+
"Print the first few requests", 10},
9699

97100
{0}};
98101

@@ -164,6 +167,9 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) {
164167
case OPTION_WARMUP_SEC:
165168
arguments->warmup_sec = atoi(arg);
166169
break;
170+
case OPTION_PRINT_HEAD_REQ:
171+
arguments->print_head_req = is_true(arg) ? true : false;
172+
break;
167173
case ARGP_KEY_ARG:
168174
if (state->arg_num >= N_ARGS) {
169175
printf("found too many arguments, current %s\n", arg);
@@ -198,7 +204,8 @@ static char doc[] =
198204
"trace can be zstd compressed\n"
199205
"cache_size is in byte, but also support KB/MB/GB\n"
200206
"supported trace_type: txt/csv/twr/vscsi/oracleGeneralBin\n"
201-
"supported eviction_algo: LRU/LFU/FIFO/ARC/LeCaR/Cacheus\n";
207+
"supported eviction_algo: LRU/LFU/FIFO/ARC/LeCaR/Cacheus\n"
208+
"print-head-req: Print the first few requests when simulating start\n";
202209

203210
/**
204211
* @brief initialize the arguments
@@ -226,6 +233,7 @@ static void init_arg(struct arguments *args) {
226233
memset(args->ofilepath, 0, OFILEPATH_LEN);
227234
args->n_req = -1;
228235
args->sample_ratio = 1.0;
236+
args->print_head_req = true;
229237

230238
for (int i = 0; i < N_MAX_ALGO; i++) {
231239
args->eviction_algo[i] = NULL;

libCacheSim/bin/cachesim/internal.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ struct arguments {
4646
bool ignore_obj_size;
4747
bool consider_obj_metadata;
4848
bool use_ttl;
49+
bool print_head_req;
4950

5051
/* arguments generated */
5152
reader_t *reader;
@@ -57,7 +58,8 @@ void parse_cmd(int argc, char *argv[], struct arguments *args);
5758
void free_arg(struct arguments *args);
5859

5960
void simulate(reader_t *reader, cache_t *cache, int report_interval,
60-
int warmup_sec, char *ofilepath, bool ignore_obj_size);
61+
int warmup_sec, char *ofilepath, bool ignore_obj_size,
62+
bool print_head_req);
6163

6264
void print_parsed_args(struct arguments *args);
6365

libCacheSim/bin/cachesim/main.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@ int main(int argc, char **argv) {
1919
if (args.n_cache_size == 0) {
2020
ERROR("no cache size found\n");
2121
}
22-
2322
if (args.n_cache_size * args.n_eviction_algo == 1) {
24-
simulate(args.reader, args.caches[0], args.report_interval, args.warmup_sec,
25-
args.ofilepath, args.ignore_obj_size);
23+
simulate(args.reader, args.caches[0], args.report_interval, args.warmup_sec, args.ofilepath, args.ignore_obj_size,
24+
args.print_head_req);
2625

2726
free_arg(&args);
2827
return 0;

libCacheSim/bin/cachesim/sim.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
#include "../../include/libCacheSim/cache.h"
42
#include "../../include/libCacheSim/reader.h"
53
#include "../../utils/include/mymath.h"
@@ -10,8 +8,16 @@
108
extern "C" {
119
#endif
1210

13-
void simulate(reader_t *reader, cache_t *cache, int report_interval,
14-
int warmup_sec, char *ofilepath, bool ignore_obj_size) {
11+
void print_head_requests(request_t *req, uint64_t req_cnt) {
12+
if (req_cnt < 2) {
13+
print_request(req, INFO_LEVEL);
14+
} else if (req_cnt < 10) {
15+
print_request(req, DEBUG_LEVEL);
16+
}
17+
}
18+
19+
void simulate(reader_t *reader, cache_t *cache, int report_interval, int warmup_sec, char *ofilepath,
20+
bool ignore_obj_size, bool print_head_req) {
1521
/* random seed */
1622
srand(time(NULL));
1723
set_rand_seed(rand());
@@ -27,6 +33,10 @@ void simulate(reader_t *reader, cache_t *cache, int report_interval,
2733

2834
double start_time = -1;
2935
while (req->valid) {
36+
if (print_head_req) {
37+
print_head_requests(req, req_cnt);
38+
}
39+
3040
req->clock_time -= start_ts;
3141
if (req->clock_time <= warmup_sec) {
3242
cache->get(cache, req);
@@ -72,15 +82,15 @@ void simulate(reader_t *reader, cache_t *cache, int report_interval,
7282
#pragma GCC diagnostic ignored "-Wformat-truncation"
7383
if (!ignore_obj_size) {
7484
snprintf(output_str, 1024,
75-
"%s %s cache size %8s, %16lu req, miss ratio %.4lf, throughput "
76-
"%.2lf MQPS\n",
85+
"%s %s cache size %8s, %16lu req, miss ratio %.4lf, throughput "
86+
"%.2lf MQPS\n",
7787
reader->trace_path, cache->cache_name, size_str,
7888
(unsigned long)req_cnt, (double)miss_cnt / (double)req_cnt,
7989
(double)req_cnt / 1000000.0 / runtime);
8090
} else {
8191
snprintf(output_str, 1024,
82-
"%s %s cache size %8ld, %16lu req, miss ratio %.4lf, throughput "
83-
"%.2lf MQPS\n",
92+
"%s %s cache size %8ld, %16lu req, miss ratio %.4lf, throughput "
93+
"%.2lf MQPS\n",
8494
reader->trace_path, cache->cache_name, cache->cache_size,
8595
(unsigned long)req_cnt, (double)miss_cnt / (double)req_cnt,
8696
(double)req_cnt / 1000000.0 / runtime);

libCacheSim/include/libCacheSim/request.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,14 @@ static inline request_t *clone_request(const request_t *req) {
108108
*/
109109
static inline void free_request(request_t *req) { my_free(request_t, req); }
110110

111-
static inline void print_request(request_t *req) {
111+
static inline void print_request(request_t *req, int log_level) {
112112
#ifdef SUPPORT_TTL
113-
INFO("req clcok_time %lu, id %llu, size %ld, ttl %ld, op %s, valid %d\n",
114-
(unsigned long)req->clock_time, (unsigned long long)req->obj_id,
115-
(long)req->obj_size, (long)req->ttl, req_op_str[req->op], req->valid);
113+
LOGGING(log_level, "req clcok_time %lu, id %llu, size %ld, ttl %ld, op %s, valid %d\n",
114+
(unsigned long)req->clock_time, (unsigned long long)req->obj_id, (long)req->obj_size, (long)req->ttl,
115+
req_op_str[req->op], req->valid);
116116
#else
117-
printf("req clcok_time %lu, id %llu, size %ld, op %s, valid %d\n",
118-
(unsigned long)req->clock_time, (unsigned long long)req->obj_id,
119-
(long)req->obj_size, req_op_str[req->op], req->valid);
117+
LOGGING(log_level, "req clcok_time %lu, id %llu, size %ld, op %s, valid %d\n", (unsigned long)req->clock_time,
118+
(unsigned long long)req->obj_id, (long)req->obj_size, req_op_str[req->op], req->valid);
120119
#endif
121120
}
122121

libCacheSim/traceReader/customizedReader/oracle/oracleTwrNSBin.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ static int oracleSysTwrNSBin_read_one_req(reader_t *reader, request_t *req) {
101101
if (req->val_size == 0 && reader->ignore_size_zero_req && (req->op == OP_GET || req->op == OP_GETS) &&
102102
reader->read_direction == READ_FORWARD) {
103103
ERROR("find size 0 request\n");
104-
print_request(req);
104+
print_request(req, WARN_LEVEL);
105105
return oracleSysTwrNSBin_read_one_req(reader, req);
106106
}
107107

0 commit comments

Comments
 (0)