aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTuukka Tikkanen <tuukka.tikkanen@linaro.org>2014-12-10 14:00:20 +0200
committerTuukka Tikkanen <tuukka.tikkanen@linaro.org>2014-12-12 08:57:27 +0200
commitffff381eadc10ee8a23bcf96ddac1c81b67d7fdd (patch)
tree53dd4d68f9fc84931fd23a75738fa91460f48549
parentd2011821a22ce57898421b24f4703cfac94c58e3 (diff)
idlestat: Rename print_vrb and make it a real function
print_vrb (print verbose) is a preprocessor macro defined in utils.h. It behaves like fprintf(stderr, ...) if the level argument is greater than or equal to current options->verbose value (incremented by one for each -v parameter on command line). Unfortunately the macro does depend on variable "options" being visible in the scope it is used in, which prevents using it in any function that does not have that variable declared in it or passed to it. This patch makes the macro a real function and disconnects the dependency of having options visible at call site. Instead while the options are passed, a call to set_verbose_level() is make whenever the value of options->verbose changes. The name and call semantics are adjusted to increase versatility of the function. Two variants are created: verbose_printf(int min_level, const char *fmt, ...) verbose_fprintf(FILE *f, int min_level, const char *fmt, ...) These two behave like printf and fprintf if level >= current verbose level, otherwise they do nothing and return 0. Signed-off-by: Tuukka Tikkanen <tuukka.tikkanen@linaro.org>
-rw-r--r--energy_model.c28
-rw-r--r--idlestat.c2
-rw-r--r--utils.c28
-rw-r--r--utils.h10
4 files changed, 48 insertions, 20 deletions
diff --git a/energy_model.c b/energy_model.c
index 1878e3c..6a88a16 100644
--- a/energy_model.c
+++ b/energy_model.c
@@ -338,7 +338,7 @@ void calculate_energy_consumption(struct cpu_topology *cpu_topo, struct program_
cluster_idl = 0.0;
cluster_wkp = 0.0;
- print_vrb(1, "\n\nCluster%c%29s | %13s | %7s | %7s | %12s | %12s | %12s |\n",
+ verbose_fprintf(stderr, 1, "\n\nCluster%c%29s | %13s | %7s | %7s | %12s | %12s | %12s |\n",
'A' + current_cluster, "", "[us] Duration", "Power", "Energy", "E_cap", "E_idle", "E_wkup");
/* All C-States on current cluster */
@@ -347,14 +347,14 @@ void calculate_energy_consumption(struct cpu_topology *cpu_topo, struct program_
struct cpuidle_cstate *c = &s_phy->cstates->cstate[j];
if (c->nrdata == 0) {
- print_vrb(2, " C%-2d +%7d hits for [%s]\n",
+ verbose_fprintf(stderr, 2, " C%-2d +%7d hits for [%s]\n",
j, c->nrdata, c->name);
continue;
}
cp = find_cstate_energy_info(current_cluster, c->name);
if (!cp) {
- print_vrb(2, " C%-2d no energy model for [%s] (%d hits, %f duration)\n",
+ verbose_fprintf(stderr, 2, " C%-2d no energy model for [%s] (%d hits, %f duration)\n",
j, c->name, c->nrdata, c->duration);
continue;
}
@@ -364,7 +364,7 @@ void calculate_energy_consumption(struct cpu_topology *cpu_topo, struct program_
cluster_wkp += c->nrdata * clustp->wakeup_energy.cluster_wakeup_energy;
- print_vrb(1, " C%-2d +%7d wkps frm [%4s] | %13s | %7s | %7d | %12s | %12s | %12.0f |\n",
+ verbose_fprintf(stderr, 1, " C%-2d +%7d wkps frm [%4s] | %13s | %7s | %7d | %12s | %12s | %12.0f |\n",
j, c->nrdata, c->name,
"", "",
clustp->wakeup_energy.cluster_wakeup_energy,
@@ -374,7 +374,7 @@ void calculate_energy_consumption(struct cpu_topology *cpu_topo, struct program_
cluster_idl += c->duration * cp->cluster_idle_power;
- print_vrb(1, " C%-2d +%7d hits for [%7s] | %13.0f | %7d | %7s | %12s | %12.0f | %12s |\n",
+ verbose_fprintf(stderr, 1, " C%-2d +%7d hits for [%7s] | %13.0f | %7d | %7s | %12s | %12.0f | %12s |\n",
j, c->nrdata, c->name,
c->duration,
cp->cluster_idle_power,
@@ -397,20 +397,20 @@ void calculate_energy_consumption(struct cpu_topology *cpu_topo, struct program_
for (i = 0; i < s_cpu->cstates->cstate_max + 1; i++) {
struct cpuidle_cstate *c = &s_cpu->cstates->cstate[i];
if (c->nrdata == 0) {
- print_vrb(2, "Cpu%d C%-2d +%7d hits for [%4s]\n",
+ verbose_fprintf(stderr, 2, "Cpu%d C%-2d +%7d hits for [%4s]\n",
s_cpu->cpu_id, i, c->nrdata, c->name);
continue;
}
cp = find_cstate_energy_info(current_cluster, c->name);
if (!cp) {
- print_vrb(2, "Cpu%d C%-2d no energy model for [%s] (%d hits, %f duration)\n",
+ verbose_fprintf(stderr, 2, "Cpu%d C%-2d no energy model for [%s] (%d hits, %f duration)\n",
s_cpu->cpu_id, i, c->name,
c->nrdata, c->duration);
continue;
}
cluster_idl += c->duration * cp->core_idle_power;
- print_vrb(1, "Cpu%d C%-2d +%7d hits for [%7s] | %13.0f | %7d | %7s | %12s | %12.0f | %12s |\n",
+ verbose_fprintf(stderr, 1, "Cpu%d C%-2d +%7d hits for [%7s] | %13.0f | %7d | %7s | %12s | %12.0f | %12s |\n",
s_cpu->cpu_id, i, c->nrdata, c->name,
c->duration,
cp->core_idle_power,
@@ -423,7 +423,7 @@ void calculate_energy_consumption(struct cpu_topology *cpu_topo, struct program_
cluster_wkp += c->nrdata * clustp->wakeup_energy.core_wakeup_energy;
- print_vrb(1, "Cpu%d C%-2d +%6d wkps frm [%4s] | %13s | %7s | %7d | %12s | %12s | %12.0f |\n",
+ verbose_fprintf(stderr, 1, "Cpu%d C%-2d +%6d wkps frm [%4s] | %13s | %7s | %7d | %12s | %12s | %12.0f |\n",
s_cpu->cpu_id, i, c->nrdata, c->name,
"", "",
clustp->wakeup_energy.core_wakeup_energy,
@@ -438,13 +438,13 @@ void calculate_energy_consumption(struct cpu_topology *cpu_topo, struct program_
struct cpufreq_pstate *p = &s_cpu->pstates->pstate[i];
if (p->count == 0) {
- print_vrb(2, "Cpu%d P%-2d +%7d hits for [%d]\n",
+ verbose_fprintf(stderr, 2, "Cpu%d P%-2d +%7d hits for [%d]\n",
s_cpu->cpu_id, i, p->count, p->freq/1000);
continue;
}
pp = find_pstate_energy_info(current_cluster, p->freq/1000);
if (!pp) {
- print_vrb(2, "Cpu%d P%-2d no energy model for [%d] (%d hits, %f duration)\n",
+ verbose_fprintf(stderr, 2, "Cpu%d P%-2d no energy model for [%d] (%d hits, %f duration)\n",
s_cpu->cpu_id, i, p->freq/1000,
p->count, p->duration);
continue;
@@ -454,7 +454,7 @@ void calculate_energy_consumption(struct cpu_topology *cpu_topo, struct program_
cluster_cap += p->duration * pp->core_power;
- print_vrb(1, "Cpu%d P%-2d +%7d hits for [%7d] | %13.0f | %7d | %7s | %12.0f | %12s | %12s |\n",
+ verbose_fprintf(stderr, 1, "Cpu%d P%-2d +%7d hits for [%7d] | %13.0f | %7d | %7s | %12.0f | %12s | %12s |\n",
s_cpu->cpu_id, i, p->count, p->freq/1000,
p->duration, pp->core_power,
"",
@@ -472,7 +472,7 @@ void calculate_energy_consumption(struct cpu_topology *cpu_topo, struct program_
pp = &clustp->p_energy[i];
cluster_cap += pp->max_core_duration * pp->cluster_power;
- print_vrb(1, " P%02d cap estimate for [%7d] | %13.0f | %7d | %7s | %12.0f | %12s | %12s |\n",
+ verbose_fprintf(stderr, 1, " P%02d cap estimate for [%7d] | %13.0f | %7d | %7s | %12.0f | %12s | %12s |\n",
clustp->number_cap_states - i - 1, pp->speed,
pp->max_core_duration,
pp->cluster_power,
@@ -496,7 +496,7 @@ void calculate_energy_consumption(struct cpu_topology *cpu_topo, struct program_
printf("\n");
- print_vrb(1, "\n\nCluster%c%29s | %13s | %7s | %7s | %12s | %12s | %12s |\n",
+ verbose_fprintf(stderr, 1, "\n\nCluster%c%29s | %13s | %7s | %7s | %12s | %12s | %12s |\n",
'A' + current_cluster, "", "[us] Duration", "Power", "Energy", "E_cap", "E_idle", "E_wkup");
/* Convert all [us] components to [s] just here to avoid summing
diff --git a/idlestat.c b/idlestat.c
index 8a58050..3020a47 100644
--- a/idlestat.c
+++ b/idlestat.c
@@ -1238,7 +1238,7 @@ int getoptions(int argc, char *argv[], struct program_options *options)
exit(0);
break;
case 'v':
- options->verbose++;
+ set_verbose_level(++options->verbose);
break;
case 'e':
options->energy_model_filename = optarg;
diff --git a/utils.c b/utils.c
index 64220ba..18ec001 100644
--- a/utils.c
+++ b/utils.c
@@ -34,6 +34,7 @@
#include <unistd.h>
#include <sys/ioctl.h>
#include <assert.h>
+#include <stdarg.h>
#include "utils.h"
@@ -57,6 +58,33 @@ int is_err(const void *ptr)
return ptr == ERROR_VALUE_PTR;
}
+static int verbose_level;
+
+void set_verbose_level(int level)
+{
+ verbose_level = level;
+}
+
+int verbose_printf(int min_level, const char *fmt, ...)
+{
+ va_list ap;
+
+ if (min_level > verbose_level)
+ return 0;
+
+ return vprintf(fmt, ap);
+}
+
+int verbose_fprintf(FILE *f, int min_level, const char *fmt, ...)
+{
+ va_list ap;
+
+ if (min_level > verbose_level)
+ return 0;
+
+ return vfprintf(f, fmt, ap);
+}
+
int write_int(const char *path, int val)
{
FILE *f;
diff --git a/utils.h b/utils.h
index cb0abf9..dc79bcc 100644
--- a/utils.h
+++ b/utils.h
@@ -27,11 +27,11 @@
#ifndef __UTILS_H
#define __UTILS_H
-#define print_vrb(level, fmt, ...) \
- do { \
- if (options->verbose >= (level)) \
- fprintf(stderr, (fmt), ##__VA_ARGS__); \
- } while(0)
+#include <stdio.h>
+
+extern void set_verbose_level(int level);
+extern int verbose_printf(int min_level, const char *fmt, ...);
+extern int verbose_fprintf(FILE *f, int min_level, const char *fmt, ...);
extern int write_int(const char *path, int val);
extern int read_int(const char *path, int *val);