From 9f9e6d2a3491c351a1570ebab331a225d257c177 Mon Sep 17 00:00:00 2001 From: Tuukka Tikkanen Date: Wed, 17 Dec 2014 15:23:06 +0200 Subject: Reports: Add support for allocating and releasing report_data While passing around the per report data pointer has been previously implemented, there was no mechanism for the report ops to allocate or release the data as needed. This patch moves allocation of report_data pointer from struct options to main() and adds calls necessary for allocating (and initializing) and releasing the data. Signed-off-by: Tuukka Tikkanen --- idlestat.c | 34 ++++++++++++++++++++++------------ idlestat.h | 1 - report_ops.h | 3 +++ 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/idlestat.c b/idlestat.c index 2edf5ef..cfaa098 100644 --- a/idlestat.c +++ b/idlestat.c @@ -1536,6 +1536,7 @@ int main(int argc, char *argv[], char *const envp[]) struct init_pstates *initp = NULL; struct report_ops *output_handler = NULL; struct cpu_topology *cpu_topo = NULL; + void *report_data = NULL; args = getoptions(argc, argv, &options); if (args <= 0) @@ -1556,7 +1557,13 @@ int main(int argc, char *argv[], char *const envp[]) output_handler->check_options(&options) < 0) return 1; - if (output_handler->check_output(&options, options.report_data)) + if (output_handler->allocate_report_data) { + report_data = output_handler->allocate_report_data(&options); + if (is_err(report_data)) + return 1; + } + + if (output_handler->check_output(&options, report_data)) return 1; if (options.energy_model_filename && @@ -1662,35 +1669,38 @@ int main(int argc, char *argv[], char *const envp[]) * the same cluster */ if (0 == establish_idledata_to_topo(datas)) { - if (output_handler->open_report_file(options.outfilename, options.report_data)) + if (output_handler->open_report_file(options.outfilename, report_data)) return 1; if (options.display & IDLE_DISPLAY) { - output_handler->cstate_table_header(options.report_data); - dump_cpu_topo_info(output_handler, options.report_data, display_cstates, cpu_topo, 1); - output_handler->cstate_table_footer(options.report_data); + output_handler->cstate_table_header(report_data); + dump_cpu_topo_info(output_handler, report_data, display_cstates, cpu_topo, 1); + output_handler->cstate_table_footer(report_data); } if (options.display & FREQUENCY_DISPLAY) { - output_handler->pstate_table_header(options.report_data); - dump_cpu_topo_info(output_handler, options.report_data, display_pstates, cpu_topo, 0); - output_handler->pstate_table_footer(options.report_data); + output_handler->pstate_table_header(report_data); + dump_cpu_topo_info(output_handler, report_data, display_pstates, cpu_topo, 0); + output_handler->pstate_table_footer(report_data); } if (options.display & WAKEUP_DISPLAY) { - output_handler->wakeup_table_header(options.report_data); - dump_cpu_topo_info(output_handler, options.report_data, display_wakeup, cpu_topo, 1); - output_handler->wakeup_table_footer(options.report_data); + output_handler->wakeup_table_header(report_data); + dump_cpu_topo_info(output_handler, report_data, display_wakeup, cpu_topo, 1); + output_handler->wakeup_table_footer(report_data); } if (options.energy_model_filename) calculate_energy_consumption(cpu_topo, &options); - output_handler->close_report_file(options.report_data); + output_handler->close_report_file(report_data); } release_init_pstates(initp); release_datas(datas); + if (output_handler->release_report_data) + output_handler->release_report_data(report_data); + return 0; } diff --git a/idlestat.h b/idlestat.h index 4a6c98e..b4db47f 100644 --- a/idlestat.h +++ b/idlestat.h @@ -134,7 +134,6 @@ struct program_options { int verbose; char *energy_model_filename; char *report_type_name; - void *report_data; }; #define IDLE_DISPLAY 0x1 diff --git a/report_ops.h b/report_ops.h index 7abbd06..cc983ca 100644 --- a/report_ops.h +++ b/report_ops.h @@ -11,6 +11,9 @@ struct report_ops { int (*check_options)(struct program_options *); int (*check_output)(struct program_options *, void *); + void * (*allocate_report_data)(struct program_options *); + void (*release_report_data)(void *); + int (*open_report_file)(char *path, void *); int (*close_report_file)(void *); -- cgit v1.2.3