diff options
author | Simon Quigley <tsimonq2@ubuntu.com> | 2017-06-19 14:38:41 -0500 |
---|---|---|
committer | Simon Quigley <tsimonq2@ubuntu.com> | 2017-06-19 14:38:41 -0500 |
commit | 11b8179a57e675c6672cbe649c655230ae3e9744 (patch) | |
tree | 2919c366d51e154e65279156fef5b4f97b8fd2f9 /benchmark.c | |
parent | 720f5023a8f68aaaa54cb6b7bf46efee23b5b4c3 (diff) |
Import Upstream version 0.4.2.1
Diffstat (limited to 'benchmark.c')
-rw-r--r-- | benchmark.c | 334 |
1 files changed, 233 insertions, 101 deletions
diff --git a/benchmark.c b/benchmark.c index d66d0b8c..7f5025de 100644 --- a/benchmark.c +++ b/benchmark.c @@ -1,6 +1,6 @@ /* * HardInfo - Displays System Information - * Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@linuxmag.com.br> + * Copyright (C) 2003-2007 Leandro A. F. Pereira <leandro@linuxmag.com.br> * * 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 @@ -20,148 +20,280 @@ #include <iconcache.h> #include <shell.h> #include <config.h> -#include <binreloc.h> +#include <syncmanager.h> enum { BENCHMARK_ZLIB, BENCHMARK_FIB, BENCHMARK_MD5, BENCHMARK_SHA1, - BENCHMARK_BLOWFISH + BENCHMARK_BLOWFISH, + BENCHMARK_RAYTRACE, + BENCHMARK_N_ENTRIES } Entries; -static ModuleEntry hi_entries[] = { - {"CPU ZLib", "compress.png"}, - {"CPU Fibonacci", "module.png"}, - {"CPU MD5", "module.png"}, - {"CPU SHA1", "module.png"}, - {"CPU Blowfish", "blowfish.png"} +void scan_zlib(gboolean reload); +void scan_raytr(gboolean reload); +void scan_bfsh(gboolean reload); +void scan_md5(gboolean reload); +void scan_fib(gboolean reload); +void scan_sha1(gboolean reload); + +gchar *callback_zlib(); +gchar *callback_raytr(); +gchar *callback_bfsh(); +gchar *callback_md5(); +gchar *callback_fib(); +gchar *callback_sha1(); + +static ModuleEntry entries[] = { + {"CPU ZLib", "compress.png", callback_zlib, scan_zlib}, + {"CPU Fibonacci", "module.png", callback_fib, scan_fib}, + {"CPU MD5", "module.png", callback_md5, scan_md5}, + {"CPU SHA1", "module.png", callback_sha1, scan_sha1}, + {"CPU Blowfish", "blowfish.png", callback_bfsh, scan_bfsh}, + {"FPU Raytracing", "raytrace.png", callback_raytr, scan_raytr}, + { NULL } }; -static gchar * -benchmark_include_results(gchar *results, const gchar *benchmark) +static gchar *__benchmark_include_results(gdouble result, + const gchar * benchmark, + ShellOrderType order_type) { GKeyFile *conf; - gchar **machines, *bconf_path; + gchar **machines; + gchar *path, *results = ""; int i; - + conf = g_key_file_new(); - bconf_path = g_strdup_printf("%s/hardinfo/benchmark.conf", - gbr_find_data_dir(PREFIX)); - g_key_file_load_from_file(conf, bconf_path, 0, NULL); + path = g_build_filename(g_get_home_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); + path = g_build_filename(params.path_data, "benchmark.conf", NULL); + } + + g_key_file_load_from_file(conf, path, 0, NULL); + machines = g_key_file_get_keys(conf, benchmark, NULL, NULL); for (i = 0; machines && machines[i]; i++) { - gchar *value = g_key_file_get_value(conf, benchmark, machines[i], NULL); - results = g_strconcat(results, machines[i], "=", value, "\n", NULL); - g_free(value); + gchar *value = g_key_file_get_value(conf, benchmark, machines[i], NULL); + results = g_strconcat(results, machines[i], "=", value, "\n", NULL); + g_free(value); } - + g_strfreev(machines); + g_free(path); g_key_file_free(conf); - g_free(bconf_path); - - return g_strconcat(results, "[$ShellParam$]\n" - "Zebra=1\n", NULL); + + DEBUG("results = %s", results); + + return g_strdup_printf("[$ShellParam$]\n" + "Zebra=1\n" + "OrderType=%d\n" + "ViewType=3\n" + "[%s]\n" + "<i>This Machine</i>=%.3f\n" + "%s", order_type, benchmark, result, results); +} + +static gchar *benchmark_include_results_reverse(gdouble result, + const gchar * benchmark) +{ + return __benchmark_include_results(result, benchmark, + SHELL_ORDER_DESCENDING); } +static gchar *benchmark_include_results(gdouble result, + const gchar * benchmark) +{ + return __benchmark_include_results(result, benchmark, + SHELL_ORDER_ASCENDING); +} + +static gdouble bench_results[BENCHMARK_N_ENTRIES]; + #include <arch/common/fib.h> #include <arch/common/zlib.h> #include <arch/common/md5.h> #include <arch/common/sha1.h> #include <arch/common/blowfish.h> +#include <arch/common/raytrace.h> -static gchar *bench_zlib = NULL, - *bench_fib = NULL, - *bench_md5 = NULL, - *bench_sha1 = NULL, - *bench_fish = NULL; +gchar *callback_zlib() +{ + return benchmark_include_results_reverse(bench_results[BENCHMARK_ZLIB], "CPU ZLib"); +} -gchar * -hi_info(gint entry) +gchar *callback_raytr() { - switch (entry) { - case BENCHMARK_ZLIB: - if (bench_zlib) - return g_strdup(bench_zlib); - - bench_zlib = benchmark_zlib(); - return g_strdup(bench_zlib); - - case BENCHMARK_BLOWFISH: - if (bench_fish) - return g_strdup(bench_fish); - - bench_fish = benchmark_fish(); - return g_strdup(bench_fish); - - case BENCHMARK_MD5: - if (bench_md5) - return g_strdup(bench_md5); - - bench_md5 = benchmark_md5(); - return g_strdup(bench_md5); - - case BENCHMARK_FIB: - if (bench_fib) - return g_strdup(bench_fib); - - bench_fib = benchmark_fib(); - return g_strdup(bench_fib); - - case BENCHMARK_SHA1: - if (bench_sha1) - return g_strdup(bench_sha1); - - bench_sha1 = benchmark_sha1(); - return g_strdup(bench_sha1); - - default: - return g_strdup("[Empty]\n"); - } + return benchmark_include_results(bench_results[BENCHMARK_RAYTRACE], "FPU Raytracing"); } -void -hi_reload(gint entry) +gchar *callback_bfsh() +{ + return benchmark_include_results(bench_results[BENCHMARK_BLOWFISH], "CPU Blowfish"); +} + +gchar *callback_md5() +{ + return benchmark_include_results_reverse(bench_results[BENCHMARK_MD5], "CPU MD5"); +} + +gchar *callback_fib() +{ + return benchmark_include_results(bench_results[BENCHMARK_FIB], "CPU Fibonacci"); +} + +gchar *callback_sha1() +{ + return benchmark_include_results_reverse(bench_results[BENCHMARK_SHA1], "CPU SHA1"); +} + +void scan_zlib(gboolean reload) +{ + SCAN_START(); + benchmark_zlib(); + SCAN_END(); +} + +void scan_raytr(gboolean reload) +{ + SCAN_START(); + benchmark_raytrace(); + SCAN_END(); +} + +void scan_bfsh(gboolean reload) +{ + SCAN_START(); + benchmark_fish(); + SCAN_END(); +} + +void scan_md5(gboolean reload) +{ + SCAN_START(); + benchmark_md5(); + SCAN_END(); +} + +void scan_fib(gboolean reload) +{ + SCAN_START(); + benchmark_fib(); + SCAN_END(); +} + +void scan_sha1(gboolean reload) +{ + SCAN_START(); + benchmark_sha1(); + SCAN_END(); +} + +const gchar *hi_note_func(gint entry) { switch (entry) { - case BENCHMARK_ZLIB: - if (bench_zlib) g_free(bench_zlib); - bench_zlib = benchmark_zlib(); - break; - case BENCHMARK_BLOWFISH: - if (bench_fish) g_free(bench_fish); - bench_fish = benchmark_fish(); - break; - case BENCHMARK_MD5: - if (bench_md5) g_free(bench_md5); - bench_md5 = benchmark_md5(); - break; - case BENCHMARK_FIB: - if (bench_fib) g_free(bench_fib); - bench_fib = benchmark_fib(); - break; - case BENCHMARK_SHA1: - if (bench_sha1) g_free(bench_sha1); - bench_sha1 = benchmark_sha1(); - break; + case BENCHMARK_ZLIB: + return "Results in KiB/second. Higher is better."; + + case BENCHMARK_MD5: + case BENCHMARK_SHA1: + return "Results in MiB/second. Higher is better."; + + case BENCHMARK_RAYTRACE: + case BENCHMARK_BLOWFISH: + case BENCHMARK_FIB: + return "Results in seconds. Lower is better."; } + + return NULL; } -gint -hi_n_entries(void) +gchar *hi_module_get_name(void) { - return G_N_ELEMENTS(hi_entries) - 1; + return g_strdup("Benchmarks"); } -GdkPixbuf * -hi_icon(gint entry) +guchar hi_module_get_weight(void) { - return icon_cache_get_pixbuf(hi_entries[entry].icon); + return 240; } -gchar * -hi_name(gint entry) +ModuleEntry *hi_module_get_entries(void) { - return hi_entries[entry].name; + return entries; } + +ModuleAbout * +hi_module_get_about(void) +{ + static ModuleAbout ma[] = { + { + .author = "Leandro A. F. Pereira", + .description = "Perform tasks and compare with other systems", + .version = VERSION, + .license = "GNU GPL version 2" + } + }; + + return ma; +} + +static gchar *get_benchmark_results() +{ + void (*scan_callback)(gboolean rescan); + + gint i = G_N_ELEMENTS(entries) - 1; + gchar *machine = module_call_method("devices::getProcessorName"); + gchar *param = g_strdup_printf("[param]\n" + "machine=%s\n" + "nbenchmarks=%d\n", + machine, i); + gchar *result = param; + + for (; i >= 0; i--) { + if ((scan_callback = entries[i].scan_callback)) { + scan_callback(FALSE); + + result = g_strdup_printf("%s\n" + "[bench%d]\n" + "name=%s\n" + "value=%f\n", + result, + i, + entries[i].name, + bench_results[i]); + } + } + + g_free(machine); + g_free(param); + + return result; +} + +void +hi_module_init(void) +{ + static SyncEntry se[] = { + { + .fancy_name = "Send Benchmark Results", + .name = "SendBenchmarkResults", + .save_to = NULL, + .get_data = get_benchmark_results + }, + { + .fancy_name = "Receive Benchmark Results", + .name = "RecvBenchmarkResults", + .save_to = "benchmark.conf", + .get_data = NULL + } + }; + + sync_manager_add_entry(&se[0]); + sync_manager_add_entry(&se[1]); +} + |