diff options
author | Leandro Pereira <leandro@hardinfo.org> | 2020-05-03 10:38:26 -0700 |
---|---|---|
committer | Leandro Pereira <leandro@hardinfo.org> | 2020-05-03 10:52:52 -0700 |
commit | eaeabcd97a80b3a5522d0a1882ac6a8d3940edad (patch) | |
tree | 7a97b5856db4b81ac94c515483c2a6f8a4f80e92 /modules/benchmark.c | |
parent | 2710ef2b1d5a9e97085e0a2cd6bd0e16e0438dfd (diff) |
Reindent benchmark.c
Diffstat (limited to 'modules/benchmark.c')
-rw-r--r-- | modules/benchmark.c | 555 |
1 files changed, 287 insertions, 268 deletions
diff --git a/modules/benchmark.c b/modules/benchmark.c index e00e5977..068b466c 100644 --- a/modules/benchmark.c +++ b/modules/benchmark.c @@ -16,39 +16,43 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#include <config.h> #include <hardinfo.h> #include <iconcache.h> #include <shell.h> -#include <config.h> #include <syncmanager.h> -#include <sys/time.h> #include <sys/resource.h> +#include <sys/time.h> -#include <sys/types.h> #include <signal.h> +#include <sys/types.h> -#include "benchmark.h" #include "appf.h" +#include "benchmark.h" #include "benchmark/bench_results.c" bench_value bench_results[BENCHMARK_N_ENTRIES]; static void do_benchmark(void (*benchmark_function)(void), int entry); -static gchar *benchmark_include_results_reverse(bench_value result, const gchar * benchmark); -static gchar *benchmark_include_results(bench_value result, const gchar * benchmark); +static gchar *benchmark_include_results_reverse(bench_value result, + const gchar *benchmark); +static gchar *benchmark_include_results(bench_value result, + const gchar *benchmark); /* ModuleEntry entries, scan_*(), callback_*(), etc. */ #include "benchmark/benches.c" static gboolean sending_benchmark_results = FALSE; -char *bench_value_to_str(bench_value r) { +char *bench_value_to_str(bench_value r) +{ gboolean has_rev = r.revision >= 0; gboolean has_extra = r.extra && *r.extra != 0; gboolean has_user_note = r.user_note && *r.user_note != 0; - char *ret = g_strdup_printf("%lf; %lf; %d", r.result, r.elapsed_time, r.threads_used); + char *ret = g_strdup_printf("%lf; %lf; %d", r.result, r.elapsed_time, + r.threads_used); if (has_rev || has_extra || has_user_note) ret = appf(ret, "; ", "%d", r.revision); if (has_extra || has_user_note) @@ -58,17 +62,25 @@ char *bench_value_to_str(bench_value r) { return ret; } -bench_value bench_value_from_str(const char* str) { +bench_value bench_value_from_str(const char *str) +{ bench_value ret = EMPTY_BENCH_VALUE; char rstr[32] = "", estr[32] = "", *p; int t, c, v; char extra[256], user_note[256]; if (str) { - /* try to handle floats from locales that use ',' or '.' as decimal sep */ - c = sscanf(str, "%[-+0-9.,]; %[-+0-9.,]; %d; %d; %255[^\r\n;|]; %255[^\r\n;|]", rstr, estr, &t, &v, extra, user_note); + /* try to handle floats from locales that use ',' or '.' as decimal sep + */ + c = sscanf( + str, "%[-+0-9.,]; %[-+0-9.,]; %d; %d; %255[^\r\n;|]; %255[^\r\n;|]", + rstr, estr, &t, &v, extra, user_note); if (c >= 3) { - if ((p = strchr(rstr, ','))) { *p = '.'; } - if ((p = strchr(estr, ','))) { *p = '.'; } + if ((p = strchr(rstr, ','))) { + *p = '.'; + } + if ((p = strchr(estr, ','))) { + *p = '.'; + } ret.result = g_ascii_strtod(rstr, NULL); ret.elapsed_time = g_ascii_strtod(estr, NULL); ret.threads_used = t; @@ -89,38 +101,42 @@ bench_value bench_value_from_str(const char* str) { typedef struct _ParallelBenchTask ParallelBenchTask; struct _ParallelBenchTask { - gint thread_number; - guint start, end; - gpointer data, callback; + gint thread_number; + guint start, end; + gpointer data, callback; int *stop; }; static gpointer benchmark_crunch_for_dispatcher(gpointer data) { - ParallelBenchTask *pbt = (ParallelBenchTask *)data; + ParallelBenchTask *pbt = (ParallelBenchTask *)data; gpointer (*callback)(void *data, gint thread_number); gpointer return_value = g_malloc(sizeof(double)); int count = 0; if ((callback = pbt->callback)) { - while(!*pbt->stop) { + while (!*pbt->stop) { callback(pbt->data, pbt->thread_number); /* don't count if didn't finish in time */ if (!*pbt->stop) count++; } } else { - DEBUG("this is thread %p; callback is NULL and it should't be!", g_thread_self()); + DEBUG("this is thread %p; callback is NULL and it should't be!", + g_thread_self()); } g_free(pbt); - *(double*)return_value = (double)count; + *(double *)return_value = (double)count; return return_value; } -bench_value benchmark_crunch_for(float seconds, gint n_threads, - gpointer callback, gpointer callback_data) { +bench_value benchmark_crunch_for(float seconds, + gint n_threads, + gpointer callback, + gpointer callback_data) +{ int cpu_procs, cpu_cores, cpu_threads, thread_number, stop = 0; GSList *threads = NULL, *t; GTimer *timer; @@ -144,19 +160,19 @@ bench_value benchmark_crunch_for(float seconds, gint n_threads, DEBUG("launching thread %d", thread_number); pbt->thread_number = thread_number; - pbt->data = callback_data; + pbt->data = callback_data; pbt->callback = callback; pbt->stop = &stop; - thread = g_thread_new("dispatcher", - (GThreadFunc)benchmark_crunch_for_dispatcher, pbt); + thread = g_thread_new( + "dispatcher", (GThreadFunc)benchmark_crunch_for_dispatcher, pbt); threads = g_slist_prepend(threads, thread); DEBUG("thread %d launched as context %p", thread_number, thread); } /* wait for time */ - //while ( g_timer_elapsed(timer, NULL) < seconds ) { } + // while ( g_timer_elapsed(timer, NULL) < seconds ) { } g_usleep(seconds * 1000000); /* signal all threads to stop */ @@ -168,7 +184,7 @@ bench_value benchmark_crunch_for(float seconds, gint n_threads, for (t = threads; t; t = t->next) { DEBUG("waiting for thread with context %p", t->data); gpointer *rv = g_thread_join((GThread *)t->data); - ret.result += *(double*)rv; + ret.result += *(double *)rv; g_free(rv); } @@ -182,17 +198,21 @@ bench_value benchmark_crunch_for(float seconds, gint n_threads, static gpointer benchmark_parallel_for_dispatcher(gpointer data) { - ParallelBenchTask *pbt = (ParallelBenchTask *)data; - gpointer (*callback)(unsigned int start, unsigned int end, void *data, gint thread_number); - gpointer return_value = NULL; + ParallelBenchTask *pbt = (ParallelBenchTask *)data; + gpointer (*callback)(unsigned int start, unsigned int end, void *data, + gint thread_number); + gpointer return_value = NULL; if ((callback = pbt->callback)) { DEBUG("this is thread %p; items %d -> %d, data %p", g_thread_self(), pbt->start, pbt->end, pbt->data); - return_value = callback(pbt->start, pbt->end, pbt->data, pbt->thread_number); - DEBUG("this is thread %p; return value is %p", g_thread_self(), return_value); + return_value = + callback(pbt->start, pbt->end, pbt->data, pbt->thread_number); + DEBUG("this is thread %p; return value is %p", g_thread_self(), + return_value); } else { - DEBUG("this is thread %p; callback is NULL and it should't be!", g_thread_self()); + DEBUG("this is thread %p; callback is NULL and it should't be!", + g_thread_self()); } g_free(pbt); @@ -201,25 +221,35 @@ static gpointer benchmark_parallel_for_dispatcher(gpointer data) } /* one call for each thread to be used */ -bench_value benchmark_parallel(gint n_threads, gpointer callback, gpointer callback_data) { +bench_value +benchmark_parallel(gint n_threads, gpointer callback, gpointer callback_data) +{ int cpu_procs, cpu_cores, cpu_threads; cpu_procs_cores_threads(&cpu_procs, &cpu_cores, &cpu_threads); - if (n_threads == 0) n_threads = cpu_threads; - else if (n_threads == -1) n_threads = cpu_cores; - return benchmark_parallel_for(n_threads, 0, n_threads, callback, callback_data); + if (n_threads == 0) + n_threads = cpu_threads; + else if (n_threads == -1) + n_threads = cpu_cores; + return benchmark_parallel_for(n_threads, 0, n_threads, callback, + callback_data); } /* Note: * benchmark_parallel_for(): element [start] included, but [end] is excluded. - * callback(): expected to processes elements [start] through [end] inclusive. + * callback(): expected to processes elements [start] through [end] + * inclusive. */ -bench_value benchmark_parallel_for(gint n_threads, guint start, guint end, - gpointer callback, gpointer callback_data) { - gchar *temp; - int cpu_procs, cpu_cores, cpu_threads; - guint iter_per_thread, iter, thread_number = 0; - GSList *threads = NULL, *t; - GTimer *timer; +bench_value benchmark_parallel_for(gint n_threads, + guint start, + guint end, + gpointer callback, + gpointer callback_data) +{ + gchar *temp; + int cpu_procs, cpu_cores, cpu_threads; + guint iter_per_thread, iter, thread_number = 0; + GSList *threads = NULL, *t; + GTimer *timer; bench_value ret = EMPTY_BENCH_VALUE; @@ -238,18 +268,19 @@ bench_value benchmark_parallel_for(gint n_threads, guint start, guint end, iter_per_thread = (end - start) / ret.threads_used; if (iter_per_thread == 0) { - DEBUG("not enough items per thread; disabling one thread"); - ret.threads_used--; + DEBUG("not enough items per thread; disabling one thread"); + ret.threads_used--; } else { - break; + break; } } - DEBUG("Using %d threads across %d logical processors; processing %d elements (%d per thread)", + DEBUG("Using %d threads across %d logical processors; processing %d " + "elements (%d per thread)", ret.threads_used, cpu_threads, (end - start), iter_per_thread); g_timer_start(timer); - for (iter = start; iter < end; ) { + for (iter = start; iter < end;) { ParallelBenchTask *pbt = g_new0(ParallelBenchTask, 1); GThread *thread; @@ -262,13 +293,13 @@ bench_value benchmark_parallel_for(gint n_threads, guint start, guint end, DEBUG("launching thread %d", 1 + thread_number); pbt->thread_number = thread_number++; - pbt->start = ts; - pbt->end = te - 1; - pbt->data = callback_data; + pbt->start = ts; + pbt->end = te - 1; + pbt->data = callback_data; pbt->callback = callback; - thread = g_thread_new("dispatcher", - (GThreadFunc)benchmark_parallel_for_dispatcher, pbt); + thread = g_thread_new( + "dispatcher", (GThreadFunc)benchmark_parallel_for_dispatcher, pbt); threads = g_slist_prepend(threads, thread); DEBUG("thread %d launched as context %p", thread_number, thread); @@ -279,8 +310,9 @@ bench_value benchmark_parallel_for(gint n_threads, guint start, guint end, DEBUG("waiting for thread with context %p", t->data); gpointer *rv = g_thread_join((GThread *)t->data); if (rv) { - if (ret.result == -1.0) ret.result = 0; - ret.result += *(double*)rv; + if (ret.result == -1.0) + ret.result = 0; + ret.result += *(double *)rv; } g_free(rv); } @@ -296,7 +328,7 @@ bench_value benchmark_parallel_for(gint n_threads, guint start, guint end, return ret; } -gchar *hi_more_info(gchar * entry) +gchar *hi_more_info(gchar *entry) { gchar *info = moreinfo_lookup_with_prefix("BENCH", entry); if (info) @@ -304,7 +336,7 @@ gchar *hi_more_info(gchar * entry) return g_strdup("?"); } -gchar *hi_get_field(gchar * field) +gchar *hi_get_field(gchar *field) { gchar *info = moreinfo_lookup_with_prefix("BENCH", field); if (info) @@ -312,25 +344,26 @@ gchar *hi_get_field(gchar * field) return g_strdup(field); } -static void br_mi_add(char **results_list, bench_result *b, gboolean select) { +static void br_mi_add(char **results_list, bench_result *b, gboolean select) +{ static unsigned int ri = 0; /* to ensure key is unique */ gchar *rkey, *lbl, *elbl, *this_marker; - this_marker = format_with_ansi_color(_("This Machine"), "0;30;43", params.fmt_opts); + this_marker = + format_with_ansi_color(_("This Machine"), "0;30;43", params.fmt_opts); rkey = g_strdup_printf("%s__%d", b->machine->mid, ri++); - lbl = g_strdup_printf("%s%s%s%s", - select ? this_marker : "", select ? " " : "", - b->machine->cpu_name, - b->legacy ? problem_marker() : ""); + lbl = g_strdup_printf("%s%s%s%s", select ? this_marker : "", + select ? " " : "", b->machine->cpu_name, + b->legacy ? problem_marker() : ""); elbl = key_label_escape(lbl); *results_list = h_strdup_cprintf("$@%s%s$%s=%.2f|%s\n", *results_list, - select ? "*" : "", rkey, elbl, - b->bvalue.result, b->machine->cpu_config); + select ? "*" : "", rkey, elbl, + b->bvalue.result, b->machine->cpu_config); - moreinfo_add_with_prefix("BENCH", rkey, bench_result_more_info(b) ); + moreinfo_add_with_prefix("BENCH", rkey, bench_result_more_info(b)); g_free(lbl); g_free(elbl); @@ -338,20 +371,19 @@ static void br_mi_add(char **results_list, bench_result *b, gboolean select) { g_free(this_marker); } -gint bench_result_sort (gconstpointer a, gconstpointer b) { - bench_result - *A = (bench_result*)a, - *B = (bench_result*)b; - if ( A->bvalue.result < B->bvalue.result ) +gint bench_result_sort(gconstpointer a, gconstpointer b) +{ + bench_result *A = (bench_result *)a, *B = (bench_result *)b; + if (A->bvalue.result < B->bvalue.result) return -1; - if ( A->bvalue.result > B->bvalue.result ) + if (A->bvalue.result > B->bvalue.result) return 1; return 0; } static gchar *__benchmark_include_results(bench_value r, - const gchar * benchmark, - ShellOrderType order_type) + const gchar *benchmark, + ShellOrderType order_type) { bench_result *b = NULL; GKeyFile *conf; @@ -371,7 +403,8 @@ static gchar *__benchmark_include_results(bench_value r, /* load saved results */ conf = g_key_file_new(); - path = g_build_filename(g_get_user_config_dir(), "hardinfo", "benchmark.conf", NULL); + path = g_build_filename(g_get_user_config_dir(), "hardinfo", + "benchmark.conf", NULL); if (!g_file_test(path, G_FILE_TEST_EXISTS)) { DEBUG("local benchmark.conf not found, trying system-wide"); g_free(path); @@ -386,7 +419,8 @@ static gchar *__benchmark_include_results(bench_value r, gchar **values; bench_result *sbr; - values = g_key_file_get_string_list(conf, benchmark, machines[i], NULL, NULL); + values = g_key_file_get_string_list(conf, benchmark, machines[i], NULL, + NULL); sbr = bench_result_benchmarkconf(benchmark, machines[i], values); result_list = g_slist_append(result_list, sbr); @@ -404,11 +438,13 @@ static gchar *__benchmark_include_results(bench_value r, /* limit results to those near the current result */ len = g_slist_length(result_list); - if (win_size == 0) win_size = 1; - if (win_size < 0) win_size = len; + if (win_size == 0) + win_size = 1; + if (win_size < 0) + win_size = len; loc = g_slist_index(result_list, b); /* -1 if not found */ if (loc >= 0) { - win_min = loc - win_size/2; + win_min = loc - win_size / 2; win_max = win_min + win_size; if (win_min < 0) { win_min = 0; @@ -422,16 +458,16 @@ static gchar *__benchmark_include_results(bench_value r, win_max = len; } - DEBUG("...len: %d, loc: %d, win_size: %d, win: [%d..%d]\n", - len, loc, win_size, win_min, win_max-1 ); + DEBUG("...len: %d, loc: %d, win_size: %d, win: [%d..%d]\n", len, loc, + win_size, win_min, win_max - 1); /* prepare for shell */ i = 0; li = result_list; while (li) { - bench_result *tr = (bench_result*)li->data; + bench_result *tr = (bench_result *)li->data; if (i >= win_min && i < win_max) - br_mi_add(&results, tr, (tr == b) ? 1 : 0 ); + br_mi_add(&results, tr, (tr == b) ? 1 : 0); bench_result_free(tr); /* no longer needed */ i++; li = g_slist_next(li); @@ -441,28 +477,30 @@ static gchar *__benchmark_include_results(bench_value r, /* send to shell */ return g_strdup_printf("[$ShellParam$]\n" - "Zebra=1\n" - "OrderType=%d\n" - "ViewType=4\n" - "ColumnTitle$Extra1=%s\n" /* CPU Clock */ - "ColumnTitle$Progress=%s\n" /* Results */ - "ColumnTitle$TextValue=%s\n" /* CPU */ - "ShowColumnHeaders=true\n" - "[%s]\n%s", - order_type, - _("CPU Config"), _("Results"), _("CPU"), - benchmark, results); - + "Zebra=1\n" + "OrderType=%d\n" + "ViewType=4\n" + "ColumnTitle$Extra1=%s\n" /* CPU Clock */ + "ColumnTitle$Progress=%s\n" /* Results */ + "ColumnTitle$TextValue=%s\n" /* CPU */ + "ShowColumnHeaders=true\n" + "[%s]\n%s", + order_type, _("CPU Config"), _("Results"), _("CPU"), + benchmark, results); } -static gchar *benchmark_include_results_reverse(bench_value result, const gchar * benchmark) +static gchar *benchmark_include_results_reverse(bench_value result, + const gchar *benchmark) { - return __benchmark_include_results(result, benchmark, SHELL_ORDER_DESCENDING); + return __benchmark_include_results(result, benchmark, + SHELL_ORDER_DESCENDING); } -static gchar *benchmark_include_results(bench_value result, const gchar * benchmark) +static gchar *benchmark_include_results(bench_value result, + const gchar *benchmark) { - return __benchmark_include_results(result, benchmark, SHELL_ORDER_ASCENDING); + return __benchmark_include_results(result, benchmark, + SHELL_ORDER_ASCENDING); } typedef struct _BenchmarkDialog BenchmarkDialog; @@ -471,11 +509,10 @@ struct _BenchmarkDialog { bench_value r; }; -static gboolean do_benchmark_handler(GIOChannel *source, - GIOCondition condition, - gpointer data) +static gboolean +do_benchmark_handler(GIOChannel *source, GIOCondition condition, gpointer data) { - BenchmarkDialog *bench_dialog = (BenchmarkDialog*)data; + BenchmarkDialog *bench_dialog = (BenchmarkDialog *)data; GIOStatus status; gchar *result; bench_value r = EMPTY_BENCH_VALUE; @@ -505,101 +542,100 @@ static void do_benchmark(void (*benchmark_function)(void), int entry) { int old_priority = 0; - if (params.skip_benchmarks) return; + if (params.skip_benchmarks) + return; if (params.gui_running && !sending_benchmark_results) { - gchar *argv[] = { params.argv0, "-b", entries[entry].name, - "-m", "benchmark.so", "-a", NULL }; - GPid bench_pid; - gint bench_stdout; - GtkWidget *bench_dialog; - GtkWidget *bench_image; - BenchmarkDialog *benchmark_dialog; - GSpawnFlags spawn_flags = G_SPAWN_STDERR_TO_DEV_NULL; - gchar *bench_status; - - bench_value r = EMPTY_BENCH_VALUE; - bench_results[entry] = r; - - bench_status = g_strdup_printf(_("Benchmarking: <b>%s</b>."), entries[entry].name); - - shell_view_set_enabled(FALSE); - shell_status_update(bench_status); - - g_free(bench_status); - - bench_image = icon_cache_get_image("benchmark.png"); - gtk_widget_show(bench_image); - - bench_dialog = gtk_message_dialog_new(GTK_WINDOW(shell_get_main_shell()->window), - GTK_DIALOG_MODAL, - GTK_MESSAGE_INFO, - GTK_BUTTONS_NONE, - _("Benchmarking. Please do not move your mouse " \ - "or press any keys.")); - gtk_dialog_add_buttons(GTK_DIALOG(bench_dialog), - _("Cancel"), GTK_RESPONSE_ACCEPT, NULL); - -G_GNUC_BEGIN_IGNORE_DEPRECATIONS - gtk_message_dialog_set_image(GTK_MESSAGE_DIALOG(bench_dialog), bench_image); -G_GNUC_END_IGNORE_DEPRECATIONS - - while (gtk_events_pending()) { - gtk_main_iteration(); - } - - benchmark_dialog = g_new0(BenchmarkDialog, 1); - benchmark_dialog->dialog = bench_dialog; - benchmark_dialog->r = r; - - if (!g_path_is_absolute(params.argv0)) { - spawn_flags |= G_SPAWN_SEARCH_PATH; - } - - if (g_spawn_async_with_pipes(NULL, - argv, NULL, - spawn_flags, - NULL, NULL, - &bench_pid, - NULL, &bench_stdout, NULL, - NULL)) { - GIOChannel *channel; - guint watch_id; - - DEBUG("spawning benchmark; pid=%d", bench_pid); - - channel = g_io_channel_unix_new(bench_stdout); - watch_id = g_io_add_watch(channel, G_IO_IN, do_benchmark_handler, - benchmark_dialog); - - switch (gtk_dialog_run(GTK_DIALOG(bench_dialog))) { + gchar *argv[] = {params.argv0, "-b", entries[entry].name, + "-m", "benchmark.so", "-a", + NULL}; + GPid bench_pid; + gint bench_stdout; + GtkWidget *bench_dialog; + GtkWidget *bench_image; + BenchmarkDialog *benchmark_dialog; + GSpawnFlags spawn_flags = G_SPAWN_STDERR_TO_DEV_NULL; + gchar *bench_status; + + bench_value r = EMPTY_BENCH_VALUE; + bench_results[entry] = r; + + bench_status = + g_strdup_printf(_("Benchmarking: <b>%s</b>."), entries[entry].name); + + shell_view_set_enabled(FALSE); + shell_status_update(bench_status); + + g_free(bench_status); + + bench_image = icon_cache_get_image("benchmark.png"); + gtk_widget_show(bench_image); + + bench_dialog = gtk_message_dialog_new( + GTK_WINDOW(shell_get_main_shell()->window), GTK_DIALOG_MODAL, + GTK_MESSAGE_INFO, GTK_BUTTONS_NONE, + _("Benchmarking. Please do not move your mouse " + "or press any keys.")); + gtk_dialog_add_buttons(GTK_DIALOG(bench_dialog), _("Cancel"), + GTK_RESPONSE_ACCEPT, NULL); + + G_GNUC_BEGIN_IGNORE_DEPRECATIONS + gtk_message_dialog_set_image(GTK_MESSAGE_DIALOG(bench_dialog), + bench_image); + G_GNUC_END_IGNORE_DEPRECATIONS + + while (gtk_events_pending()) { + gtk_main_iteration(); + } + + benchmark_dialog = g_new0(BenchmarkDialog, 1); + benchmark_dialog->dialog = bench_dialog; + benchmark_dialog->r = r; + + if (!g_path_is_absolute(params.argv0)) { + spawn_flags |= G_SPAWN_SEARCH_PATH; + } + + if (g_spawn_async_with_pipes(NULL, argv, NULL, spawn_flags, NULL, NULL, + &bench_pid, NULL, &bench_stdout, NULL, + NULL)) { + GIOChannel *channel; + guint watch_id; + + DEBUG("spawning benchmark; pid=%d", bench_pid); + + channel = g_io_channel_unix_new(bench_stdout); + watch_id = g_io_add_watch(channel, G_IO_IN, do_benchmark_handler, + benchmark_dialog); + + switch (gtk_dialog_run(GTK_DIALOG(bench_dialog))) { case GTK_RESPONSE_NONE: - DEBUG("benchmark finished"); - break; + DEBUG("benchmark finished"); + break; case GTK_RESPONSE_ACCEPT: - DEBUG("cancelling benchmark"); + DEBUG("cancelling benchmark"); - gtk_widget_destroy(bench_dialog); - g_source_remove(watch_id); - kill(bench_pid, SIGINT); - } + gtk_widget_destroy(bench_dialog); + g_source_remove(watch_id); + kill(bench_pid, SIGINT); + } - bench_results[entry] = benchmark_dialog->r; + bench_results[entry] = benchmark_dialog->r; - g_io_channel_unref(channel); - shell_view_set_enabled(TRUE); - shell_status_set_enabled(TRUE); - g_free(benchmark_dialog); + g_io_channel_unref(channel); + shell_view_set_enabled(TRUE); + shell_status_set_enabled(TRUE); + g_free(benchmark_dialog); - shell_status_update(_("Done.")); + shell_status_update(_("Done.")); - return; - } + return; + } - gtk_widget_destroy(bench_dialog); - g_free(benchmark_dialog); - shell_status_set_enabled(TRUE); - shell_status_update(_("Done.")); + gtk_widget_destroy(bench_dialog); + g_free(benchmark_dialog); + shell_status_set_enabled(TRUE); + shell_status_update(_("Done.")); } setpriority(PRIO_PROCESS, 0, -20); @@ -607,30 +643,19 @@ G_GNUC_END_IGNORE_DEPRECATIONS setpriority(PRIO_PROCESS, 0, old_priority); } -gchar *hi_module_get_name(void) -{ - return g_strdup(_("Benchmarks")); -} +gchar *hi_module_get_name(void) { return g_strdup(_("Benchmarks")); } -guchar hi_module_get_weight(void) -{ - return 240; -} +guchar hi_module_get_weight(void) { return 240; } -ModuleEntry *hi_module_get_entries(void) -{ - return entries; -} +ModuleEntry *hi_module_get_entries(void) { return entries; } ModuleAbout *hi_module_get_about(void) { static ModuleAbout ma[] = { - { - .author = "Leandro A. F. Pereira", - .description = N_("Perform tasks and compare with other systems"), - .version = VERSION, - .license = "GNU GPL version 2"} - }; + {.author = "Leandro A. F. Pereira", + .description = N_("Perform tasks and compare with other systems"), + .version = VERSION, + .license = "GNU GPL version 2"}}; return ma; } @@ -638,7 +663,7 @@ ModuleAbout *hi_module_get_about(void) static gchar *get_benchmark_results() { gint i; - void (*scan_callback) (gboolean rescan); + void (*scan_callback)(gboolean rescan); sending_benchmark_results = TRUE; @@ -646,31 +671,28 @@ static gchar *get_benchmark_results() gchar *machineclock = module_call_method("devices::getProcessorFrequency"); gchar *machineram = module_call_method("computer::getMemoryTotal"); gchar *result = g_strdup_printf("[param]\n" - "machine=%s\n" - "machineclock=%s\n" - "machineram=%s\n" - "nbenchmarks=%zu\n", - machine, - machineclock, - machineram, - G_N_ELEMENTS(entries) - 1); + "machine=%s\n" + "machineclock=%s\n" + "machineram=%s\n" + "nbenchmarks=%zu\n", + machine, machineclock, machineram, + G_N_ELEMENTS(entries) - 1); for (i = 0; i < G_N_ELEMENTS(entries); i++) { scan_callback = entries[i].scan_callback; if (!scan_callback) continue; if (bench_results[i].result < 0.0) { - /* benchmark was cancelled */ - scan_callback(TRUE); + /* benchmark was cancelled */ + scan_callback(TRUE); } else { - scan_callback(FALSE); + scan_callback(FALSE); } result = h_strdup_cprintf("[bench%d]\n" "name=%s\n" "value=%f\n", - result, - i, entries[i].name, bench_results[i]); + result, i, entries[i].name, bench_results[i]); } g_free(machine); @@ -689,36 +711,40 @@ static gchar *run_benchmark(gchar *name) DEBUG("name = %s", name); for (i = 0; entries[i].name; i++) { - if (g_str_equal(entries[i].name, name)) { - void (*scan_callback)(gboolean rescan); - - 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) { - /* attach the user note */ - if (params.bench_user_note) - strncpy(bench_results[i].user_note, params.bench_user_note, 255); - - 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; + if (g_str_equal(entries[i].name, name)) { + void (*scan_callback)(gboolean rescan); + + 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) { + /* attach the user note */ + if (params.bench_user_note) + strncpy(bench_results[i].user_note, + params.bench_user_note, 255); + + 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]); } - /* defaults to "short" which is below */ - } - - return bench_value_to_str(bench_results[i]); } - } } return NULL; @@ -726,28 +752,21 @@ static gchar *run_benchmark(gchar *name) ShellModuleMethod *hi_exported_methods(void) { - static ShellModuleMethod m[] = { - {"runBenchmark", run_benchmark}, - {NULL} - }; + static ShellModuleMethod m[] = {{"runBenchmark", run_benchmark}, {NULL}}; return m; } void hi_module_init(void) { - static SyncEntry se[] = { - { - .fancy_name = N_("Send benchmark results"), - .name = "SendBenchmarkResults", - .save_to = NULL, - .get_data = get_benchmark_results}, - { - .fancy_name = N_("Receive benchmark results"), - .name = "RecvBenchmarkResults", - .save_to = "benchmark.conf", - .get_data = NULL} - }; + static SyncEntry se[] = {{.fancy_name = N_("Send benchmark results"), + .name = "SendBenchmarkResults", + .save_to = NULL, + .get_data = get_benchmark_results}, + {.fancy_name = N_("Receive benchmark results"), + .name = "RecvBenchmarkResults", + .save_to = "benchmark.conf", + .get_data = NULL}}; sync_manager_add_entry(&se[0]); sync_manager_add_entry(&se[1]); @@ -755,13 +774,13 @@ void hi_module_init(void) bench_value er = EMPTY_BENCH_VALUE; int i; for (i = 0; i < G_N_ELEMENTS(entries) - 1; i++) { - bench_results[i] = er; + bench_results[i] = er; } } gchar **hi_module_get_dependencies(void) { - static gchar *deps[] = { "devices.so", NULL }; + static gchar *deps[] = {"devices.so", NULL}; return deps; } |