Skip to content

Commit

Permalink
add traceConv and fix previous CI error
Browse files Browse the repository at this point in the history
  • Loading branch information
1a1a11a committed Dec 14, 2024
1 parent d19603b commit c561fa7
Show file tree
Hide file tree
Showing 12 changed files with 599 additions and 162 deletions.
68 changes: 24 additions & 44 deletions libCacheSim/bin/cli_reader_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ bool is_true(const char *arg) {
}
}

static void _check_parsed_result(char *end, int col_idx) {
if (strlen(end) > 2) {
ERROR("param parsing error, find string \"%s\" after number\n", end);
}
if (col_idx < 1) {
ERROR("field/col index should start from 1\n");
}
}

/**
* @brief parse the reader parameters
*
Expand Down Expand Up @@ -96,55 +105,26 @@ void parse_reader_params(const char *reader_params_str, reader_init_param_t *par

key = replace_char(key, '_', '-');

if (strcasecmp(key, "block-size") == 0) {
params->block_size = (int)strtol(value, &end, 0);
if (strlen(end) > 2) {
ERROR("param parsing error, find string \"%s\" after number\n", end);
}
if (params->time_field < 1) {
ERROR("field/col index should start from 1\n");
}
} else if (strcasecmp(key, "time-col") == 0 || strcasecmp(key, "time-field") == 0) {
if (strcasecmp(key, "time-col") == 0) {
params->time_field = (int)strtol(value, &end, 0);
if (strlen(end) > 2) {
ERROR("param parsing error, find string \"%s\" after number\n", end);
}
if (params->time_field < 1) {
ERROR("field/col index should start from 1\n");
}
} else if (strcasecmp(key, "obj-id-col") == 0 || strcasecmp(key, "obj-id-field") == 0) {
_check_parsed_result(end, params->time_field);
} else if (strcasecmp(key, "obj-id-col") == 0) {
params->obj_id_field = (int)strtol(value, &end, 0);
if (strlen(end) > 2) {
ERROR("param parsing error, find string \"%s\" after number\n", end);
}
if (params->obj_id_field < 1) {
ERROR("field/col index should start from 1\n");
}
} else if (strcasecmp(key, "obj-size-col") == 0 || strcasecmp(key, "obj-size-field") == 0 ||
strcasecmp(key, "size-col") == 0 || strcasecmp(key, "size-field") == 0) {
_check_parsed_result(end, params->obj_id_field);
} else if (strcasecmp(key, "obj-size-col") == 0 || strcasecmp(key, "size-col") == 0) {
params->obj_size_field = (int)strtol(value, &end, 0);
if (strlen(end) > 2) {
ERROR("param parsing error, find string \"%s\" after number\n", end);
}
if (params->obj_size_field < 1) {
ERROR("field/col index should start from 1\n");
}
} else if (strcasecmp(key, "cnt-col") == 0 || strcasecmp(key, "cnt-field") == 0) {
_check_parsed_result(end, params->obj_size_field);
} else if (strcasecmp(key, "cnt-col") == 0) {
params->cnt_field = (int)strtol(value, &end, 0);
if (strlen(end) > 2) {
ERROR("param parsing error, find string \"%s\" after number\n", end);
}
if (params->cnt_field < 1) {
ERROR("field/col index should start from 1\n");
}
} else if (strcasecmp(key, "next-access-col") == 0 || strcasecmp(key, "next-access-field") == 0) {
} else if (strcasecmp(key, "op-col") == 0) {
params->op_field = (int)strtol(value, &end, 0);
_check_parsed_result(end, params->op_field);
} else if (strcasecmp(key, "tenant-col") == 0) {
params->tenant_field = (int)(strtol(value, &end, 0));
_check_parsed_result(end, params->tenant_field);
} else if (strcasecmp(key, "next-access-col") == 0) {
params->next_access_vtime_field = (int)strtol(value, &end, 0);
if (strlen(end) > 2) {
ERROR("param parsing error, find string \"%s\" after number\n", end);
}
if (params->next_access_vtime_field < 1) {
ERROR("field/col index should start from 1\n");
}
_check_parsed_result(end, params->next_access_vtime_field);
} else if (strcasecmp(key, "obj-id-is-num") == 0) {
params->obj_id_is_num_set = true;
params->obj_id_is_num = is_true(value);
Expand Down
2 changes: 1 addition & 1 deletion libCacheSim/bin/traceUtils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ set_target_properties(tracePrint
)


add_executable(traceConv traceConvMain.cpp traceConv.cpp cli_parser.cpp)
add_executable(traceConv traceConvMain.cpp traceConvOracleGeneral.cpp traceConvLCS.cpp cli_parser.cpp utils.cpp)
target_link_libraries(traceConv cliReaderLib ${ALL_MODULES} ${LIBS} ${CMAKE_THREAD_LIBS_INIT})
set_target_properties(traceConv
PROPERTIES
Expand Down
42 changes: 14 additions & 28 deletions libCacheSim/bin/traceUtils/cli_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const char *argp_program_bug_address =
enum argp_option_short {
OPTION_TRACE_TYPE_PARAMS = 't',
OPTION_OUTPUT_PATH = 'o',
OPTION_OUTPUT_FORMAT = 'f',
OPTION_SAMPLE_RATIO = 's',
OPTION_IGNORE_OBJ_SIZE = 0x101,

Expand All @@ -33,6 +34,7 @@ enum argp_option_short {
OPTION_FIELD_DELIMITER = 0x201,
OPTION_OBJ_ID_ONLY = 0x202,
OPTION_OBJ_ID_32bit = 0x204,
OPTION_PRINT_STAT = 0x208,

// trace filter
OPTION_FILTER_TYPE = 0x301,
Expand All @@ -56,6 +58,8 @@ static struct argp_option options[] = {
"specify to ignore the object size from the trace", 2},

{0, 0, 0, 0, "traceConv options:"},
{"output-format", OPTION_OUTPUT_FORMAT, "lcs", 0,
"currently support lcs/lcs_v1/lcs_v2/lcs_v3/oracleGeneral", 4},
{"output-txt", OPTION_OUTPUT_TXT, "false", 0,
"output trace in txt format in addition to binary format", 4},
{"remove-size-change", OPTION_REMOVE_SIZE_CHANGE, "false", 0,
Expand All @@ -64,6 +68,8 @@ static struct argp_option options[] = {
4},

{0, 0, 0, 0, "tracePrint options:"},
{"print-stat", OPTION_PRINT_STAT, "false", 0,
"Print trace statistics only available for lcs traces", 6},
{"num-req", OPTION_NUM_REQ, "-1", 0,
"Number of requests to process, -1 means all requests in the trace", 6},
{"field-delimiter", OPTION_FIELD_DELIMITER, ",", 0,
Expand Down Expand Up @@ -111,9 +117,15 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) {
case OPTION_OUTPUT_TXT:
arguments->output_txt = is_true(arg) ? true : false;
break;
case OPTION_OUTPUT_FORMAT:
arguments->output_format = arg;
break;
case OPTION_NUM_REQ:
arguments->n_req = atoll(arg);
break;
case OPTION_PRINT_STAT:
arguments->print_stat = is_true(arg) ? true : false;
break;
case OPTION_FIELD_DELIMITER:
arguments->delimiter = arg[0];
break;
Expand Down Expand Up @@ -161,40 +173,16 @@ static char args_doc[] = "trace_path trace_type";
static char doc[] =
"\n"
"tracePrint: utility to print binary trace in human-readable format\n"
"traceConv: utility to convert a trace to oracleGeneral format\n\n"
"traceConv: utility to convert a trace to lcs format\n\n"
"traceFilter: utility to filter a trace\n\n"
"example usage: ./tracePrint /trace/path oracleGeneral -n 20 "
"--obj-id-only=1\n\n"
"example usage: ./traceConv /trace/path csv -o "
"/path/new_trace.oracleGeneral -t "
"/path/new_trace.lcs -t "
"\"obj-id-col=5,time-col=2,obj-size-col=4\"\n\n"
"example usage: ./traceFilter /trace/path lcs -o /path/new_trace.lcs "
"--filter fifo --filter-size 0.1\n\n";

/**
* @brief initialize the arguments
*
* @param args
*/
static void init_arg(struct arguments *args) {
memset(args, 0, sizeof(struct arguments));

args->n_req = -1;
args->trace_path = NULL;
args->trace_type_str = NULL;
args->trace_type_params = NULL;
args->ignore_obj_size = false;
args->sample_ratio = 1.0;
memset(args->ofilepath, 0, OFILEPATH_LEN);
args->output_txt = false;
args->remove_size_change = false;
args->cache_name = NULL;
args->cache_size = 0;
args->delimiter = ',';
args->print_obj_id_only = false;
args->print_obj_id_32bit = false;
}

static void print_parsed_arg(struct arguments *args) {
#define OUTPUT_STR_LEN 1024
int n = 0;
Expand Down Expand Up @@ -261,6 +249,4 @@ void parse_cmd(int argc, char *argv[], struct arguments *args) {

print_parsed_arg(args);
}

void free_arg(struct arguments *args) { close_reader(args->reader); }
} // namespace cli
40 changes: 37 additions & 3 deletions libCacheSim/bin/traceUtils/internal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ struct arguments {
/* some objects may change size during the trace, this keeps the size as the
* last size in the trace */
bool remove_size_change;
char *output_format;

/* trace print */
int64_t num_req; /* number of requests to print */
char delimiter;
bool print_stat;
bool print_obj_id_only;
bool print_obj_id_32bit;

Expand All @@ -47,7 +49,33 @@ struct arguments {
namespace cli {
void parse_cmd(int argc, char *argv[], struct arguments *args);

void free_arg(struct arguments *args);
/**
* @brief initialize the arguments
*
* @param args
*/
static void init_arg(struct arguments *args) {
memset(args, 0, sizeof(struct arguments));

args->n_req = -1;
args->trace_path = NULL;
args->trace_type_str = NULL;
args->trace_type_params = NULL;
args->ignore_obj_size = false;
args->sample_ratio = 1.0;
memset(args->ofilepath, 0, OFILEPATH_LEN);
args->output_txt = false;
args->remove_size_change = false;
args->cache_name = NULL;
args->output_format = "lcs";
args->cache_size = 0;
args->delimiter = ',';
args->print_stat = false;
args->print_obj_id_only = false;
args->print_obj_id_32bit = false;
}

static void free_arg(struct arguments *args) { close_reader(args->reader); }
} // namespace cli

namespace traceConv {
Expand All @@ -63,7 +91,13 @@ namespace traceConv {
* @param remove_size_change whether remove object size change during traceConv
* @param use_lcs_format whether use lcs format
*/
void convert_to_oracleGeneral(reader_t *reader, std::string ofilepath, bool output_txt, bool remove_size_change,
bool use_lcs_format);
void convert_to_oracleGeneral(reader_t *reader, std::string ofilepath, bool output_txt, bool remove_size_change);

/** convert to lcs format */
void convert_to_lcs(reader_t *reader, std::string ofilepath, bool output_txt, bool remove_size_change, int lcs_ver);

} // namespace traceConv

namespace utils {
void *setup_mmap(const std::string &file_path, size_t *size);
} // namespace utils
Loading

0 comments on commit c561fa7

Please sign in to comment.