aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Renninger <trenn@suse.de>2009-11-03 09:20:57 +0100
committerDominik Brodowski <linux@dominikbrodowski.net>2009-11-07 11:21:04 +0100
commit810f89febdac6c433d84fe853a245a97198356c3 (patch)
tree2da287f7afcec76be3efdeceda7f78d3c19c50e3
parentb7e6359765e530fa03a2c01013c8c95009e57eb2 (diff)
downloadcpufrequtils-810f89febdac6c433d84fe853a245a97198356c3.tar.gz
cpufreq-bench: Don't fail if the output dir does not exist, but try to create it
Otherwise this resulted in a segfault if the log directory does not exist. Also only print configs to stdout in verbose mode. Signed-off-by: Thomas Renninger <trenn@suse.de> Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>
-rw-r--r--bench/benchmark.c18
-rw-r--r--bench/benchmark.h1
-rw-r--r--bench/main.c38
-rw-r--r--bench/parse.c31
-rw-r--r--bench/system.c14
5 files changed, 62 insertions, 40 deletions
diff --git a/bench/benchmark.c b/bench/benchmark.c
index 08b86ae..5e8d8bf 100644
--- a/bench/benchmark.c
+++ b/bench/benchmark.c
@@ -34,7 +34,7 @@
* @retval rounds of calculation
**/
-unsigned int calculate_timespace(long load)
+unsigned int calculate_timespace(long load, struct config *config)
{
int i;
long long now, then;
@@ -42,7 +42,8 @@ unsigned int calculate_timespace(long load)
unsigned int rounds = 0;
unsigned int timed = 0;
- printf("calibrating load of %lius, please wait...\n", load);
+ if (config->verbose)
+ printf("calibrating load of %lius, please wait...\n", load);
/* get the initial calculation time for a specific number of rounds */
now = get_time();
@@ -64,8 +65,8 @@ unsigned int calculate_timespace(long load)
timed = (unsigned int)(then - now);
estimated = rounds;
}
-
- printf("calibration done\n");
+ if (config->verbose)
+ printf("calibration done\n");
return estimated;
}
@@ -103,10 +104,12 @@ void start_benchmark(struct config *config)
/* calibrate the calculation time. the resulting calculation
* _rounds should produce a load which matches the configured
* load time */
- calculations = calculate_timespace(load_time);
+ calculations = calculate_timespace(load_time, config);
- printf("_round %i: doing %u cycles with %u calculations for %lius\n",
- _round + 1, config->cycles, calculations, load_time);
+ if (config->verbose)
+ printf("_round %i: doing %u cycles with %u calculations"
+ " for %lius\n", _round + 1, config->cycles,
+ calculations, load_time);
fprintf(config->output, "%li %li %li %u ",
load_time, sleep_time, load_time / calculations, calculations);
@@ -149,6 +152,7 @@ void start_benchmark(struct config *config)
/* compare the avarage sleep/load cycles */
fprintf(config->output, "%li ", powersave_time / config->cycles);
fprintf(config->output, "%.3f\n", performance_time * 100.0 / powersave_time);
+ fflush(config->output);
if (config->verbose)
printf("performance is at %.2f%%\n", performance_time * 100.0 / powersave_time);
diff --git a/bench/benchmark.h b/bench/benchmark.h
index 9def4fd..0691f91 100644
--- a/bench/benchmark.h
+++ b/bench/benchmark.h
@@ -24,5 +24,4 @@
}} \
-unsigned int calculate_timespace(long load);
void start_benchmark(struct config *config);
diff --git a/bench/main.c b/bench/main.c
index 1ff1525..d5589f6 100644
--- a/bench/main.c
+++ b/bench/main.c
@@ -172,24 +172,26 @@ int main(int argc, char **argv)
}
}
- printf("starting benchmark with parameters:\n");
- printf("config:\n\t"
- "sleep=%li\n\t"
- "load=%li\n\t"
- "sleep_step=%li\n\t"
- "load_step=%li\n\t"
- "cpu=%u\n\t"
- "cycles=%u\n\t"
- "rounds=%u\n\t"
- "governor=%s\n\n",
- config->sleep,
- config->load,
- config->sleep_step,
- config->load_step,
- config->cpu,
- config->cycles,
- config->rounds,
- config->governor);
+ if (config->verbose) {
+ printf("starting benchmark with parameters:\n");
+ printf("config:\n\t"
+ "sleep=%li\n\t"
+ "load=%li\n\t"
+ "sleep_step=%li\n\t"
+ "load_step=%li\n\t"
+ "cpu=%u\n\t"
+ "cycles=%u\n\t"
+ "rounds=%u\n\t"
+ "governor=%s\n\n",
+ config->sleep,
+ config->load,
+ config->sleep_step,
+ config->load_step,
+ config->cpu,
+ config->cycles,
+ config->rounds,
+ config->governor);
+ }
prepare_user(config);
prepare_system(config);
diff --git a/bench/parse.c b/bench/parse.c
index 2b26279..d03028a 100644
--- a/bench/parse.c
+++ b/bench/parse.c
@@ -22,7 +22,11 @@
#include <stdarg.h>
#include <string.h>
#include <time.h>
+#include <dirent.h>
+
#include <sys/utsname.h>
+#include <sys/types.h>
+#include <sys/stat.h>
#include "parse.h"
#include "config.h"
@@ -57,14 +61,25 @@ enum sched_prio string_to_prio(const char *str)
* @retval NULL when the file can't be created
**/
-FILE *prepare_output(const char *dir)
+FILE *prepare_output(const char *dirname)
{
FILE *output = NULL;
int len;
char *filename;
struct utsname sysdata;
-
- len = strlen(dir) + 30;
+ DIR *dir;
+
+ dir = opendir(dirname);
+ if (dir == NULL) {
+ if (mkdir(dirname, 0755)) {
+ perror("mkdir");
+ fprintf(stderr, "error: Cannot create dir %s\n",
+ dirname);
+ return NULL;
+ }
+ }
+
+ len = strlen(dirname) + 30;
filename = malloc(sizeof(char) * len);
if (uname(&sysdata) == 0) {
@@ -77,9 +92,9 @@ FILE *prepare_output(const char *dir)
}
snprintf(filename, len - 1, "%s/benchmark_%s_%s_%li.log",
- dir, sysdata.nodename, sysdata.release, time(NULL));
+ dirname, sysdata.nodename, sysdata.release, time(NULL));
} else {
- snprintf(filename, len -1, "%s/benchmark_%li.log", dir, time(NULL));
+ snprintf(filename, len -1, "%s/benchmark_%li.log", dirname, time(NULL));
}
dprintf("logilename: %s\n", filename);
@@ -118,11 +133,7 @@ struct config *prepare_default_config()
config->verbose = 0;
strncpy(config->governor, "ondemand", 8);
- if ((config->output = prepare_output("/tmp")) == NULL) {
- free(config);
- return NULL;
- }
-
+ config->output = stdout;
return config;
}
diff --git a/bench/system.c b/bench/system.c
index d089057..b51f242 100644
--- a/bench/system.c
+++ b/bench/system.c
@@ -147,15 +147,21 @@ void prepare_user(const struct config *config)
load_time += 2 * config->cycles * (config->load + config->load_step * round) + (config->load + config->load_step * round * 4);
}
- printf("approx. test duration: %im\n", (int)((sleep_time + load_time) / 60000000));
- printf("your terminal may hardly be responsible while the benchmark is running\n");
+ if (config->verbose) {
+ printf("approx. test duration: %im\n",
+ (int)((sleep_time + load_time) / 60000000));
+ printf("your terminal may hardly be responsible while the "
+ "benchmark is running\n");
+ }
for (i = 5; i >= 0; i--) {
- printf("\rbenchmark starts in %is", i);
+ if (config->verbose)
+ printf("\rbenchmark starts in %is", i);
fflush(stdout);
sleep(1);
}
- printf("\n");
+ if (config->verbose)
+ printf("\n");
}
/**