diff options
author | Burt P <pburt0@gmail.com> | 2017-12-18 21:38:10 -0600 |
---|---|---|
committer | Leandro A. F. Pereira <leandro@hardinfo.org> | 2018-02-27 07:41:51 -0800 |
commit | 45bf74abab1b665143acbcd3d44e05793dd1b32d (patch) | |
tree | b1c0fdbc2fe5f7623c6b4d8a22c79948203c3103 | |
parent | c8785521f39c3a86454ade890018ca021272c621 (diff) |
Add cli param to format result for -b
For running benchmarks from the command line, add a new param
to specify the output format:
-g "conf" gives a line suitable for benchmark.conf
-g "shell" gives the complete "moreinfo" shell data
-g "short" (or nothing) gives the bench_value string as before
Signed-off-by: Burt P <pburt0@gmail.com>
-rw-r--r-- | hardinfo/hardinfo.c | 1 | ||||
-rw-r--r-- | hardinfo/util.c | 8 | ||||
-rw-r--r-- | includes/hardinfo.h | 1 | ||||
-rw-r--r-- | modules/benchmark.c | 17 |
4 files changed, 27 insertions, 0 deletions
diff --git a/hardinfo/hardinfo.c b/hardinfo/hardinfo.c index 4401a551..3c0ade11 100644 --- a/hardinfo/hardinfo.c +++ b/hardinfo/hardinfo.c @@ -123,6 +123,7 @@ int main(int argc, char **argv) if (!result) { g_error(_("Unknown benchmark ``%s'' or libbenchmark.so not loaded"), params.run_benchmark); } else { + fprintf(stderr, "\n"); g_print("%s\n", result); g_free(result); } diff --git a/hardinfo/util.c b/hardinfo/util.c index efa19b9c..7bcc5dd5 100644 --- a/hardinfo/util.c +++ b/hardinfo/util.c @@ -390,6 +390,7 @@ void parameters_init(int *argc, char ***argv, ProgramParameters * param) static gboolean run_xmlrpc_server = FALSE; static gchar *report_format = NULL; static gchar *run_benchmark = NULL; + static gchar *result_format = NULL; static gchar **use_modules = NULL; static GOptionEntry options[] = { @@ -412,6 +413,12 @@ void parameters_init(int *argc, char ***argv, ProgramParameters * param) .arg_data = &run_benchmark, .description = N_("run benchmark; requires benchmark.so to be loaded")}, { + .long_name = "result-format", + .short_name = 'g', + .arg = G_OPTION_ARG_STRING, + .arg_data = &result_format, + .description = N_("benchmark result format ([short], conf, shell)")}, + { .long_name = "list-modules", .short_name = 'l', .arg = G_OPTION_ARG_NONE, @@ -468,6 +475,7 @@ void parameters_init(int *argc, char ***argv, ProgramParameters * param) param->list_modules = list_modules; param->use_modules = use_modules; param->run_benchmark = run_benchmark; + param->result_format = result_format; param->autoload_deps = autoload_deps; param->run_xmlrpc_server = run_xmlrpc_server; param->argv0 = *(argv)[0]; diff --git a/includes/hardinfo.h b/includes/hardinfo.h index f42f1e6c..637aa1fd 100644 --- a/includes/hardinfo.h +++ b/includes/hardinfo.h @@ -55,6 +55,7 @@ struct _ProgramParameters { gchar **use_modules; gchar *run_benchmark; + gchar *result_format; gchar *path_lib; gchar *path_data; gchar *argv0; diff --git a/modules/benchmark.c b/modules/benchmark.c index 80575cfa..ed23243b 100644 --- a/modules/benchmark.c +++ b/modules/benchmark.c @@ -712,6 +712,23 @@ static gchar *run_benchmark(gchar *name) if ((scan_callback = entries[i].scan_callback)) { scan_callback(FALSE); +#define CHK_RESULT_FORMAT(F) (params.result_format && strcmp(params.result_format, F) == 0) + + if (params.run_benchmark) { + if (CHK_RESULT_FORMAT("conf") ) { + bench_result *b = bench_result_this_machine(name, bench_results[i]); + char *temp = bench_result_benchmarkconf_line(b); + bench_result_free(b); + return temp; + } else if (CHK_RESULT_FORMAT("shell") ) { + bench_result *b = bench_result_this_machine(name, bench_results[i]); + char *temp = bench_result_more_info_complete(b); + bench_result_free(b); + return temp; + } + /* defaults to "short" which is below*/ + } + return bench_value_to_str(bench_results[i]); } } |