aboutsummaryrefslogtreecommitdiff
path: root/idlestat.c
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 /idlestat.c
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>
Diffstat (limited to 'idlestat.c')
-rw-r--r--idlestat.c42
1 files changed, 35 insertions, 7 deletions
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;