Skip to content

Commit 9a9d87b

Browse files
authored
Apply clang-format
1 parent a9fcbdc commit 9a9d87b

1 file changed

Lines changed: 33 additions & 22 deletions

File tree

libCacheSim/bin/cli_reader_utils.c

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ extern "C" {
1818
*
1919
* @param args
2020
*/
21-
trace_type_e trace_type_str_to_enum(const char *trace_type_str, const char *trace_path) {
21+
trace_type_e trace_type_str_to_enum(const char *trace_type_str,
22+
const char *trace_path) {
2223
if (strcasecmp(trace_type_str, "auto") == 0) {
2324
trace_type_e trace_type = detect_trace_type(trace_path);
2425
if (trace_type == UNKNOWN_TRACE) {
25-
ERROR(
26-
"cannot detect trace type from trace path %s, "
27-
"please specify the trace type manually\n",
28-
trace_path);
26+
ERROR("cannot detect trace type from trace path %s, "
27+
"please specify the trace type manually\n",
28+
trace_path);
2929
}
3030
return trace_type;
3131
} else if (strcasecmp(trace_type_str, "txt") == 0) {
@@ -43,7 +43,8 @@ trace_type_e trace_type_str_to_enum(const char *trace_type_str, const char *trac
4343
return TWRNS_TRACE;
4444
} else if (strcasecmp(trace_type_str, "vscsi") == 0) {
4545
return VSCSI_TRACE;
46-
} else if (strcasecmp(trace_type_str, "oracleGeneralBin") == 0 || strcasecmp(trace_type_str, "oracleGeneral") == 0) {
46+
} else if (strcasecmp(trace_type_str, "oracleGeneralBin") == 0 ||
47+
strcasecmp(trace_type_str, "oracleGeneral") == 0) {
4748
return ORACLE_GENERAL_TRACE;
4849
} else if (strcasecmp(trace_type_str, "oracleSysTwrNS") == 0) {
4950
return ORACLE_SYS_TWRNS_TRACE;
@@ -56,11 +57,11 @@ trace_type_e trace_type_str_to_enum(const char *trace_type_str, const char *trac
5657
}
5758

5859
bool is_true(const char *arg) {
59-
if (strcasecmp(arg, "true") == 0 || strcasecmp(arg, "1") == 0 || strcasecmp(arg, "yes") == 0 ||
60-
strcasecmp(arg, "y") == 0) {
60+
if (strcasecmp(arg, "true") == 0 || strcasecmp(arg, "1") == 0 ||
61+
strcasecmp(arg, "yes") == 0 || strcasecmp(arg, "y") == 0) {
6162
return true;
62-
} else if (strcasecmp(arg, "false") == 0 || strcasecmp(arg, "0") == 0 || strcasecmp(arg, "no") == 0 ||
63-
strcasecmp(arg, "n") == 0) {
63+
} else if (strcasecmp(arg, "false") == 0 || strcasecmp(arg, "0") == 0 ||
64+
strcasecmp(arg, "no") == 0 || strcasecmp(arg, "n") == 0) {
6465
return false;
6566
} else {
6667
ERROR("Invalid value: %s, expect true/false", arg);
@@ -83,12 +84,14 @@ static void _check_parsed_result(char *end, int col_idx) {
8384
* @param reader_params_str
8485
* @param params
8586
*/
86-
void parse_reader_params(const char *reader_params_str, reader_init_param_t *params) {
87+
void parse_reader_params(const char *reader_params_str,
88+
reader_init_param_t *params) {
8789
params->delimiter = '\0';
8890
params->obj_id_is_num = false;
8991
params->obj_id_is_num_set = false;
9092

91-
if (reader_params_str == NULL) return;
93+
if (reader_params_str == NULL)
94+
return;
9295
char *params_str = strdup(reader_params_str);
9396
char *old_params_str = params_str;
9497
char *end;
@@ -112,7 +115,8 @@ void parse_reader_params(const char *reader_params_str, reader_init_param_t *par
112115
} else if (strcasecmp(key, "obj-id-col") == 0) {
113116
params->obj_id_field = (int)strtol(value, &end, 0);
114117
_check_parsed_result(end, params->obj_id_field);
115-
} else if (strcasecmp(key, "obj-size-col") == 0 || strcasecmp(key, "size-col") == 0) {
118+
} else if (strcasecmp(key, "obj-size-col") == 0 ||
119+
strcasecmp(key, "size-col") == 0) {
116120
params->obj_size_field = (int)strtol(value, &end, 0);
117121
_check_parsed_result(end, params->obj_size_field);
118122
} else if (strcasecmp(key, "cnt-col") == 0) {
@@ -143,7 +147,8 @@ void parse_reader_params(const char *reader_params_str, reader_init_param_t *par
143147
params->obj_id_is_num = is_true(value);
144148
} else if (strcasecmp(key, "block-size") == 0) {
145149
params->block_size = (int)(strtol(value, &end, 0));
146-
} else if (strcasecmp(key, "header") == 0 || strcasecmp(key, "has-header") == 0) {
150+
} else if (strcasecmp(key, "header") == 0 ||
151+
strcasecmp(key, "has-header") == 0) {
147152
params->has_header = is_true(value);
148153
params->has_header_set = true;
149154
} else if (strcasecmp(key, "format") == 0) {
@@ -219,7 +224,8 @@ bool should_disable_obj_metadata(reader_t *reader) {
219224
bool disable_obj_metadata = true;
220225
request_t *req = new_request();
221226
for (int i = 0; i < N_TEST; i++) {
222-
if (read_one_req(reader, req) != 0) break;
227+
if (read_one_req(reader, req) != 0)
228+
break;
223229

224230
if (req->obj_size > 1) {
225231
disable_obj_metadata = false;
@@ -233,7 +239,8 @@ bool should_disable_obj_metadata(reader_t *reader) {
233239
}
234240
#undef N_TEST
235241

236-
void cal_working_set_size(reader_t *reader, int64_t *wss_obj, int64_t *wss_byte) {
242+
void cal_working_set_size(reader_t *reader, int64_t *wss_obj,
243+
int64_t *wss_byte) {
237244
reset_reader(reader);
238245
request_t *req = new_request();
239246
GHashTable *obj_table = g_hash_table_new(g_direct_hash, g_direct_equal);
@@ -254,7 +261,8 @@ void cal_working_set_size(reader_t *reader, int64_t *wss_obj, int64_t *wss_byte)
254261
while (read_one_req(reader, req) == 0) {
255262
n_req += 1;
256263
if (n_req % 2000000 == 0) {
257-
DEBUG("processed %ld requests, %lld objects, %lld bytes\n", (long)n_req, (long long)*wss_obj, (long long)*wss_byte);
264+
DEBUG("processed %ld requests, %lld objects, %lld bytes\n", (long)n_req,
265+
(long long)*wss_obj, (long long)*wss_byte);
258266
}
259267
if (scaling_factor > 1 && req->obj_id % scaling_factor != 0) {
260268
continue;
@@ -273,10 +281,12 @@ void cal_working_set_size(reader_t *reader, int64_t *wss_obj, int64_t *wss_byte)
273281
*wss_byte *= scaling_factor;
274282

275283
if (scaling_factor > 1) {
276-
INFO("estimated working set size (%.2f sample ratio): %lld object %lld byte\n", 1.0 / scaling_factor, (long long)*wss_obj,
277-
(long long)*wss_byte);
284+
INFO("estimated working set size (%.2f sample ratio): %lld object %lld "
285+
"byte\n",
286+
1.0 / scaling_factor, (long long)*wss_obj, (long long)*wss_byte);
278287
} else {
279-
INFO("working set size: %lld object %lld byte\n", (long long)*wss_obj, (long long)*wss_byte);
288+
INFO("working set size: %lld object %lld byte\n", (long long)*wss_obj,
289+
(long long)*wss_byte);
280290
}
281291

282292
g_hash_table_destroy(obj_table);
@@ -295,8 +305,9 @@ void cal_working_set_size(reader_t *reader, int64_t *wss_obj, int64_t *wss_byte)
295305
* @param sample_ratio
296306
* @return reader_t*
297307
*/
298-
reader_t *create_reader(const char *trace_type_str, const char *trace_path, const char *trace_type_params,
299-
const int64_t n_req, const bool ignore_obj_size, const int sample_ratio) {
308+
reader_t *create_reader(const char *trace_type_str, const char *trace_path,
309+
const char *trace_type_params, const int64_t n_req,
310+
const bool ignore_obj_size, const int sample_ratio) {
300311
/* convert trace type string to enum */
301312
trace_type_e trace_type = trace_type_str_to_enum(trace_type_str, trace_path);
302313

0 commit comments

Comments
 (0)