Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Enhance request struct and add debug logging #81

Merged
merged 2 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: Enhance request struct and add debug logging
  • Loading branch information
xiaguan committed Aug 8, 2024
commit df9407894f08e62bea59fe35c64f8cafee897b24
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ example/cacheSimulatorC/cmake-build-debug
fig/
# Chaos
sftp-config.json
# Clangd cache
*.cache/
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED On)
set(CMAKE_CXX_EXTENSIONS Off)

# export compile commands, useful for IDEs
set(EXPORT_COMPILE_COMMANDS ON)
########################################
# define options #
# options are cached variables https://stackoverflow.com/questions/35744647/disabling-cmake-option-has-no-effect
Expand Down
7 changes: 7 additions & 0 deletions libCacheSim/bin/cachesim/cli_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ enum argp_option_short {

OPTION_PREFETCH_ALGO = 'p',
OPTION_PREFETCH_PARAMS = 0x109,
OPTION_PRINT_HEAD_REQ = 0x10a,
};

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

{0}};

Expand Down Expand Up @@ -164,6 +167,9 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) {
case OPTION_WARMUP_SEC:
arguments->warmup_sec = atoi(arg);
break;
case OPTION_PRINT_HEAD_REQ:
arguments->print_head_req = is_true(arg) ? true : false;
break;
case ARGP_KEY_ARG:
if (state->arg_num >= N_ARGS) {
printf("found too many arguments, current %s\n", arg);
Expand Down Expand Up @@ -226,6 +232,7 @@ static void init_arg(struct arguments *args) {
memset(args->ofilepath, 0, OFILEPATH_LEN);
args->n_req = -1;
args->sample_ratio = 1.0;
args->print_head_req = true;

for (int i = 0; i < N_MAX_ALGO; i++) {
args->eviction_algo[i] = NULL;
Expand Down
4 changes: 3 additions & 1 deletion libCacheSim/bin/cachesim/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ struct arguments {
bool ignore_obj_size;
bool consider_obj_metadata;
bool use_ttl;
bool print_head_req;

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

void simulate(reader_t *reader, cache_t *cache, int report_interval,
int warmup_sec, char *ofilepath, bool ignore_obj_size);
int warmup_sec, char *ofilepath, bool ignore_obj_size,
bool print_head_req);

void print_parsed_args(struct arguments *args);

Expand Down
5 changes: 2 additions & 3 deletions libCacheSim/bin/cachesim/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ int main(int argc, char **argv) {
if (args.n_cache_size == 0) {
ERROR("no cache size found\n");
}

if (args.n_cache_size * args.n_eviction_algo == 1) {
simulate(args.reader, args.caches[0], args.report_interval, args.warmup_sec,
args.ofilepath, args.ignore_obj_size);
simulate(args.reader, args.caches[0], args.report_interval, args.warmup_sec, args.ofilepath, args.ignore_obj_size,
args.print_head_req);

free_arg(&args);
return 0;
Expand Down
26 changes: 18 additions & 8 deletions libCacheSim/bin/cachesim/sim.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


#include "../../include/libCacheSim/cache.h"
#include "../../include/libCacheSim/reader.h"
#include "../../utils/include/mymath.h"
Expand All @@ -10,8 +8,16 @@
extern "C" {
#endif

void simulate(reader_t *reader, cache_t *cache, int report_interval,
int warmup_sec, char *ofilepath, bool ignore_obj_size) {
void print_head_requests(request_t *req, uint64_t req_cnt) {
if (req_cnt < 2) {
print_request(req, INFO_LEVEL);
} else if (req_cnt < 10) {
print_request(req, DEBUG_LEVEL);
}
}

void simulate(reader_t *reader, cache_t *cache, int report_interval, int warmup_sec, char *ofilepath,
bool ignore_obj_size, bool print_head_req) {
/* random seed */
srand(time(NULL));
set_rand_seed(rand());
Expand All @@ -27,6 +33,10 @@ void simulate(reader_t *reader, cache_t *cache, int report_interval,

double start_time = -1;
while (req->valid) {
if (print_head_req) {
print_head_requests(req, req_cnt);
}

req->clock_time -= start_ts;
if (req->clock_time <= warmup_sec) {
cache->get(cache, req);
Expand Down Expand Up @@ -72,15 +82,15 @@ void simulate(reader_t *reader, cache_t *cache, int report_interval,
#pragma GCC diagnostic ignored "-Wformat-truncation"
if (!ignore_obj_size) {
snprintf(output_str, 1024,
"%s %s cache size %8s, %16lu req, miss ratio %.4lf, throughput "
"%.2lf MQPS\n",
"%s %s cache size %8s, %16lu req, miss ratio %.4lf, throughput "
"%.2lf MQPS\n",
reader->trace_path, cache->cache_name, size_str,
(unsigned long)req_cnt, (double)miss_cnt / (double)req_cnt,
(double)req_cnt / 1000000.0 / runtime);
} else {
snprintf(output_str, 1024,
"%s %s cache size %8ld, %16lu req, miss ratio %.4lf, throughput "
"%.2lf MQPS\n",
"%s %s cache size %8ld, %16lu req, miss ratio %.4lf, throughput "
"%.2lf MQPS\n",
reader->trace_path, cache->cache_name, cache->cache_size,
(unsigned long)req_cnt, (double)miss_cnt / (double)req_cnt,
(double)req_cnt / 1000000.0 / runtime);
Expand Down
13 changes: 6 additions & 7 deletions libCacheSim/include/libCacheSim/request.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,14 @@ static inline request_t *clone_request(const request_t *req) {
*/
static inline void free_request(request_t *req) { my_free(request_t, req); }

static inline void print_request(request_t *req) {
static inline void print_request(request_t *req, int log_level) {
#ifdef SUPPORT_TTL
INFO("req clcok_time %lu, id %llu, size %ld, ttl %ld, op %s, valid %d\n",
(unsigned long)req->clock_time, (unsigned long long)req->obj_id,
(long)req->obj_size, (long)req->ttl, req_op_str[req->op], req->valid);
LOGGING(log_level, "req clcok_time %lu, id %llu, size %ld, ttl %ld, op %s, valid %d\n",
(unsigned long)req->clock_time, (unsigned long long)req->obj_id, (long)req->obj_size, (long)req->ttl,
req_op_str[req->op], req->valid);
#else
printf("req clcok_time %lu, id %llu, size %ld, op %s, valid %d\n",
(unsigned long)req->clock_time, (unsigned long long)req->obj_id,
(long)req->obj_size, req_op_str[req->op], req->valid);
LOGGING(log_level, "req clcok_time %lu, id %llu, size %ld, op %s, valid %d\n", (unsigned long)req->clock_time,
(unsigned long long)req->obj_id, (long)req->obj_size, req_op_str[req->op], req->valid);
#endif
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ static int oracleSysTwrNSBin_read_one_req(reader_t *reader, request_t *req) {
if (req->val_size == 0 && reader->ignore_size_zero_req && (req->op == OP_GET || req->op == OP_GETS) &&
reader->read_direction == READ_FORWARD) {
ERROR("find size 0 request\n");
print_request(req);
print_request(req, WARN_LEVEL);
xiaguan marked this conversation as resolved.
Show resolved Hide resolved
return oracleSysTwrNSBin_read_one_req(reader, req);
}

Expand Down
Loading