cpupowerutils: bench - ConfigStyle bugfixes

Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>
This commit is contained in:
Dominik Brodowski
2011-04-19 19:20:12 +02:00
parent f5ac0641d1
commit 02af3cb5aa
8 changed files with 75 additions and 58 deletions

View File

@@ -86,20 +86,22 @@ FILE *prepare_output(const char *dirname)
len += strlen(sysdata.nodename) + strlen(sysdata.release);
filename = realloc(filename, sizeof(char) * len);
if(filename == NULL) {
if (filename == NULL) {
perror("realloc");
return NULL;
}
snprintf(filename, len - 1, "%s/benchmark_%s_%s_%li.log",
snprintf(filename, len - 1, "%s/benchmark_%s_%s_%li.log",
dirname, sysdata.nodename, sysdata.release, time(NULL));
} else {
snprintf(filename, len -1, "%s/benchmark_%li.log", dirname, time(NULL));
snprintf(filename, len - 1, "%s/benchmark_%li.log",
dirname, time(NULL));
}
dprintf("logilename: %s\n", filename);
if ((output = fopen(filename, "w+")) == NULL) {
output = fopen(filename, "w+");
if (output == NULL) {
perror("fopen");
fprintf(stderr, "error: unable to open logfile\n");
}
@@ -130,7 +132,7 @@ struct config *prepare_default_config()
config->load_step = 500000;
config->cycles = 5;
config->rounds = 50;
config->cpu = 0;
config->cpu = 0;
config->prio = SCHED_HIGH;
config->verbose = 0;
strncpy(config->governor, "ondemand", 8);
@@ -166,13 +168,12 @@ int prepare_config(const char *path, struct config *config)
if (configfile == NULL) {
perror("fopen");
fprintf(stderr, "error: unable to read configfile\n");
fprintf(stderr, "error: unable to read configfile\n");
free(config);
return 1;
}
while (getline(&line, &len, configfile) != -1)
{
while (getline(&line, &len, configfile) != -1) {
if (line[0] == '#' || line[0] == ' ')
continue;
@@ -183,35 +184,35 @@ int prepare_config(const char *path, struct config *config)
if (strncmp("sleep", opt, strlen(opt)) == 0)
sscanf(val, "%li", &config->sleep);
else if (strncmp("load", opt, strlen(opt)) == 0)
else if (strncmp("load", opt, strlen(opt)) == 0)
sscanf(val, "%li", &config->load);
else if (strncmp("load_step", opt, strlen(opt)) == 0)
else if (strncmp("load_step", opt, strlen(opt)) == 0)
sscanf(val, "%li", &config->load_step);
else if (strncmp("sleep_step", opt, strlen(opt)) == 0)
else if (strncmp("sleep_step", opt, strlen(opt)) == 0)
sscanf(val, "%li", &config->sleep_step);
else if (strncmp("cycles", opt, strlen(opt)) == 0)
else if (strncmp("cycles", opt, strlen(opt)) == 0)
sscanf(val, "%u", &config->cycles);
else if (strncmp("rounds", opt, strlen(opt)) == 0)
else if (strncmp("rounds", opt, strlen(opt)) == 0)
sscanf(val, "%u", &config->rounds);
else if (strncmp("verbose", opt, strlen(opt)) == 0)
else if (strncmp("verbose", opt, strlen(opt)) == 0)
sscanf(val, "%u", &config->verbose);
else if (strncmp("output", opt, strlen(opt)) == 0)
else if (strncmp("output", opt, strlen(opt)) == 0)
config->output = prepare_output(val);
else if (strncmp("cpu", opt, strlen(opt)) == 0)
else if (strncmp("cpu", opt, strlen(opt)) == 0)
sscanf(val, "%u", &config->cpu);
else if (strncmp("governor", opt, 14) == 0)
else if (strncmp("governor", opt, 14) == 0)
strncpy(config->governor, val, 14);
else if (strncmp("priority", opt, strlen(opt)) == 0) {
if (string_to_prio(val) != SCHED_ERR)
if (string_to_prio(val) != SCHED_ERR)
config->prio = string_to_prio(val);
}
}