aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTuukka Tikkanen <tuukka.tikkanen@linaro.org>2014-12-10 15:21:31 +0200
committerTuukka Tikkanen <tuukka.tikkanen@linaro.org>2014-12-12 08:57:27 +0200
commite648fabb41c1c672ac6ff0bd8a07f39d199a8053 (patch)
tree2a6848ae7d14723f784f8b39b410b01e846de147
parentf18b1b7a4df9dec114386d9839a2c1e408fb0556 (diff)
report_ops: Change way of referring to different report formats
The initial implementation of default, boxless and csv report formats required making the report format ops structures global. Getoptions() referred directly to these structures when assigning the active ops pointer. This patch adds a name field to the structures and places pointers to the structures in a special segment so that the list of ops structures can be iterated like an array without having to create such an array explicitly. Getoptions() is modified to record only the name and main() will then obtain the actual structure pointer by name. The ops array head and sentinel is combined into the same source files that have been used for trace file ops arrays. The files are renamed to ops_head.c and ops_tail.c. Command line options parsing now checks that there is only one specification of report format. Usage function lists the available formats. -C and -B are retained as shortcuts for -r csv and -r boxless, respectively. Signed-off-by: Tuukka Tikkanen <tuukka.tikkanen@linaro.org>
-rw-r--r--Makefile15
-rw-r--r--csv_report.c5
-rw-r--r--default_report.c10
-rw-r--r--idlestat.c42
-rw-r--r--idlestat.h2
-rw-r--r--ops_head.c (renamed from trace_ops_head.c)5
-rw-r--r--ops_tail.c (renamed from trace_ops_tail.c)5
-rw-r--r--report_ops.h14
-rw-r--r--reports.c73
9 files changed, 151 insertions, 20 deletions
diff --git a/Makefile b/Makefile
index 0de28be..590c54d 100644
--- a/Makefile
+++ b/Makefile
@@ -24,12 +24,15 @@
CFLAGS?=-g -Wall
CC=gcc
-OBJS = idlestat.o topology.o trace.o utils.o energy_model.o \
- default_report.o csv_report.o \
- trace_ops_head.o \
- tracefile_idlestat.o \
- tracefile_ftrace.o \
- trace_ops_tail.o
+TRACE_OBJS = tracefile_idlestat.o tracefile_ftrace.o
+REPORT_OBJS = default_report.o csv_report.o
+
+
+OBJS = idlestat.o topology.o trace.o utils.o energy_model.o reports.o \
+ ops_head.o \
+ $(REPORT_OBJS) \
+ $(TRACE_OBJS) \
+ ops_tail.o
default: idlestat
diff --git a/csv_report.c b/csv_report.c
index fb74eed..245aa8c 100644
--- a/csv_report.c
+++ b/csv_report.c
@@ -103,7 +103,8 @@ static void csv_wakeup_single_state(struct wakeup_irq *irqinfo, void *report_dat
}
}
-struct report_ops csv_report_ops = {
+static struct report_ops csv_report_ops = {
+ .name = "csv",
.check_output = csv_check_output,
.open_report_file = csv_open_report_file,
@@ -127,3 +128,5 @@ struct report_ops csv_report_ops = {
.wakeup_single_state = csv_wakeup_single_state,
.wakeup_end_cpu = csv_cstate_end_cpu,
};
+
+EXPORT_REPORT_OPS(csv);
diff --git a/default_report.c b/default_report.c
index c1d0af8..62f4046 100644
--- a/default_report.c
+++ b/default_report.c
@@ -263,7 +263,8 @@ static void default_wakeup_table_footer(void *report_data)
}
-struct report_ops default_report_ops = {
+static struct report_ops default_report_ops = {
+ .name = "default",
.check_output = default_check_output, /* Shared */
.open_report_file = default_open_report_file, /* Shared */
@@ -288,7 +289,10 @@ struct report_ops default_report_ops = {
.wakeup_end_cpu = default_end_cpu,
};
-struct report_ops boxless_report_ops = {
+EXPORT_REPORT_OPS(default);
+
+static struct report_ops boxless_report_ops = {
+ .name = "boxless",
.check_output = default_check_output,
.open_report_file = default_open_report_file,
@@ -312,3 +316,5 @@ struct report_ops boxless_report_ops = {
.wakeup_single_state = boxless_wakeup_single_state,
.wakeup_end_cpu = boxless_end_cpu,
};
+
+EXPORT_REPORT_OPS(boxless);
diff --git a/idlestat.c b/idlestat.c
index 228c67a..f13a2fd 100644
--- a/idlestat.c
+++ b/idlestat.c
@@ -1142,10 +1142,12 @@ static void help(const char *cmd)
fprintf(stderr,
"\nUsage:\nTrace mode:\n\t%s --trace -f|--trace-file <filename>"
" -o|--output-file <filename> -t|--duration <seconds>"
+ " -r|--report-format <format>"
" -C|--csv-report -B|--boxless-report"
" -c|--idle -p|--frequency -w|--wakeup", basename(cmd));
fprintf(stderr,
"\nReporting mode:\n\t%s --import -f|--trace-file <filename>"
+ " -r|--report-format <format>"
" -C|--csv-report -B|--boxless-report"
" -o|--output-file <filename>", basename(cmd));
fprintf(stderr,
@@ -1167,6 +1169,8 @@ static void help(const char *cmd)
"\n5. Run a trace, post-process the results and print all"
" statistics into a file:\n\tsudo ./%s --trace -f /tmp/mytrace -t 10 -p -c -w"
" -o /tmp/myreport\n", basename(cmd));
+ fprintf(stderr, "\nReport formats supported:");
+ list_report_formats_to_stderr();
}
static void version(const char *cmd)
@@ -1189,6 +1193,7 @@ int getoptions(int argc, char *argv[], struct program_options *options)
{ "frequency", no_argument, NULL, 'p' },
{ "wakeup", no_argument, NULL, 'w' },
{ "energy-model-file", required_argument, NULL, 'e' },
+ { "report-format", required_argument, NULL, 'r' },
{ "csv-report", no_argument, NULL, 'C' },
{ "boxless-report", no_argument, NULL, 'B' },
{ 0, 0, 0, 0 }
@@ -1199,13 +1204,12 @@ int getoptions(int argc, char *argv[], struct program_options *options)
options->filename = NULL;
options->outfilename = NULL;
options->mode = -1;
- options->report_ops = &default_report_ops;
while (1) {
int optindex = 0;
- c = getopt_long(argc, argv, ":de:f:o:ht:cpwVvCB",
+ c = getopt_long(argc, argv, ":de:f:o:ht:r:cpwVvCB",
long_options, &optindex);
if (c == -1)
break;
@@ -1243,12 +1247,30 @@ int getoptions(int argc, char *argv[], struct program_options *options)
case 'e':
options->energy_model_filename = optarg;
break;
+ case 'r':
+ if (options->report_type_name == NULL) {
+ options->report_type_name = optarg;
+ break;
+ }
+ fprintf(stderr, "-r: report type already set to %s\n",
+ options->report_type_name);
+ return -1;
case 'C':
- options->report_ops = &csv_report_ops;
- break;
+ if (options->report_type_name == NULL) {
+ options->report_type_name = "csv";
+ break;
+ }
+ fprintf(stderr, "-C: report type already set to %s\n",
+ options->report_type_name);
+ return -1;
case 'B':
- options->report_ops = &boxless_report_ops;
- break;
+ if (options->report_type_name == NULL) {
+ options->report_type_name = "boxless";
+ break;
+ }
+ fprintf(stderr, "-B: report type already set to %s\n",
+ options->report_type_name);
+ return -1;
case 0: /* getopt_long() set a variable, just keep going */
break;
case ':': /* missing option argument */
@@ -1264,6 +1286,9 @@ int getoptions(int argc, char *argv[], struct program_options *options)
}
}
+ if (options->report_type_name == NULL)
+ options->report_type_name = "default";
+
if (options->mode < 0) {
fprintf(stderr, "select a mode: --trace or --import\n");
return -1;
@@ -1490,7 +1515,10 @@ int main(int argc, char *argv[], char *const envp[])
return 1;
}
- output_handler = options.report_ops;
+ output_handler = get_report_ops(options.report_type_name);
+ if (is_err(output_handler))
+ return 1;
+
if (output_handler->check_options &&
output_handler->check_options(&options) < 0)
return 1;
diff --git a/idlestat.h b/idlestat.h
index 2c92a2b..5a35672 100644
--- a/idlestat.h
+++ b/idlestat.h
@@ -131,7 +131,7 @@ struct program_options {
char *outfilename;
int verbose;
char *energy_model_filename;
- struct report_ops *report_ops;
+ char *report_type_name;
void *report_data;
};
diff --git a/trace_ops_head.c b/ops_head.c
index 74fb091..10cee49 100644
--- a/trace_ops_head.c
+++ b/ops_head.c
@@ -1,6 +1,11 @@
+#include "report_ops.h"
#include "trace_ops.h"
#include <stddef.h>
const struct trace_ops
__attribute__((__used__)) __attribute__ ((__section__ ("__trace_ops")))
*trace_ops_head = NULL;
+
+const struct report_ops
+ __attribute__((__used__)) __attribute__ ((__section__ ("__report_ops")))
+ *report_ops_head = NULL;
diff --git a/trace_ops_tail.c b/ops_tail.c
index 7ef187b..b658322 100644
--- a/trace_ops_tail.c
+++ b/ops_tail.c
@@ -1,6 +1,11 @@
+#include "report_ops.h"
#include "trace_ops.h"
#include <stddef.h>
static const struct trace_ops
__attribute__((__used__)) __attribute__ ((__section__ ("__trace_ops")))
*trace_ops_tail = NULL;
+
+static const struct report_ops
+ __attribute__((__used__)) __attribute__ ((__section__ ("__report_ops")))
+ *report_ops_tail = NULL;
diff --git a/report_ops.h b/report_ops.h
index fe6100e..2c659e3 100644
--- a/report_ops.h
+++ b/report_ops.h
@@ -7,6 +7,7 @@ struct cpufreq_pstate;
struct wakeup_irq;
struct report_ops {
+ const char *name;
int (*check_options)(struct program_options *);
int (*check_output)(struct program_options *, void *);
@@ -32,8 +33,15 @@ struct report_ops {
void (*wakeup_end_cpu)(void *);
};
-extern struct report_ops default_report_ops;
-extern struct report_ops csv_report_ops;
-extern struct report_ops boxless_report_ops;
+extern void list_report_formats_to_stderr(void);
+extern struct report_ops *get_report_ops(const char *name);
+
+#define EXPORT_REPORT_OPS(reporttype_name) \
+ static const struct report_ops \
+ __attribute__ ((__used__)) \
+ __attribute__ ((__section__ ("__report_ops"))) \
+ * reporttype_name ## _report_ptr = &reporttype_name##_report_ops
+
+extern const struct report_ops *report_ops_head;
#endif
diff --git a/reports.c b/reports.c
new file mode 100644
index 0000000..7ce139b
--- /dev/null
+++ b/reports.c
@@ -0,0 +1,73 @@
+/*
+ * reports.c
+ *
+ * Copyright (C) 2014, Linaro Limited.
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * Contributors:
+ * Tuukka Tikkanen <tuukka.tikkanen@linaro.org>
+ *
+ */
+
+#include "report_ops.h"
+#include "utils.h"
+#include <stdio.h>
+#include <string.h>
+#include <assert.h>
+
+void list_report_formats_to_stderr(void)
+{
+ const struct report_ops **ops_it;
+
+ for (ops_it = (&report_ops_head)+1 ; *ops_it ; ++ops_it)
+ fprintf(stderr, " %s", (*ops_it)->name);
+
+ fprintf(stderr, "\n");
+}
+
+struct report_ops *get_report_ops(const char *name)
+{
+ const struct report_ops **ops_it;
+
+ for (ops_it = (&report_ops_head)+1 ; *ops_it ; ++ops_it) {
+ /* All formats must export all of the asserted ops */
+ assert((*ops_it)->name);
+ assert((*ops_it)->check_output);
+ assert((*ops_it)->open_report_file);
+ assert((*ops_it)->close_report_file);
+ assert((*ops_it)->cstate_table_header);
+ assert((*ops_it)->cstate_table_footer);
+ assert((*ops_it)->cstate_cpu_header);
+ assert((*ops_it)->cstate_single_state);
+ assert((*ops_it)->cstate_end_cpu);
+ assert((*ops_it)->pstate_table_header);
+ assert((*ops_it)->pstate_table_footer);
+ assert((*ops_it)->pstate_cpu_header);
+ assert((*ops_it)->pstate_single_state);
+ assert((*ops_it)->pstate_end_cpu);
+ assert((*ops_it)->wakeup_table_header);
+ assert((*ops_it)->wakeup_table_footer);
+ assert((*ops_it)->wakeup_cpu_header);
+ assert((*ops_it)->wakeup_single_state);
+ assert((*ops_it)->wakeup_end_cpu);
+ /* Compare name */
+ if (!strcmp((*ops_it)->name, name))
+ return (struct report_ops *)*ops_it;
+ }
+ return NULL;
+}