MCPcopy Create free account
hub / github.com/1a1a11a/libCacheSim / LeCaR_parse_params

Function LeCaR_parse_params

libCacheSim/cache/eviction/LeCaR.c:594–631  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

592}
593
594static void LeCaR_parse_params(cache_t *cache,
595 const char *cache_specific_params) {
596 LeCaR_params_t *params = (LeCaR_params_t *)cache->eviction_params;
597 char *params_str = strdup(cache_specific_params);
598 char *old_params_str = params_str;
599 char *end;
600
601 while (params_str != NULL && params_str[0] != '\0') {
602 /* different parameters are separated by comma,
603 * key and value are separated by = */
604 char *key = strsep((char **)&params_str, "=");
605 char *value = strsep((char **)&params_str, ",");
606
607 // skip the white space
608 while (params_str != NULL && *params_str == ' ') {
609 params_str++;
610 }
611
612 if (strcasecmp(key, "update-weight") == 0) {
613 if ((int)strtol(value, &end, 0) == 1)
614 params->update_weight = true;
615 else
616 params->update_weight = false;
617 if (strlen(end) > 2) {
618 ERROR("param parsing error, find string \"%s\" after number\n", end);
619 }
620 } else if (strcasecmp(key, "lru-weight") == 0) {
621 params->w_lru = (double)strtod(value, &end);
622 } else if (strcasecmp(key, "print") == 0) {
623 printf("current parameters: %s\n", LeCaR_current_params(cache, params));
624 exit(0);
625 } else {
626 ERROR("%s does not have parameter %s\n", cache->cache_name, key);
627 exit(1);
628 }
629 }
630 free(old_params_str);
631}
632
633// ***********************************************************************
634// **** ****

Callers 1

LeCaR_initFunction · 0.85

Calls 1

LeCaR_current_paramsFunction · 0.85

Tested by

no test coverage detected