diff options
-rw-r--r-- | CMakeLists.txt | 8 | ||||
-rw-r--r-- | includes/benchmark.h | 2 | ||||
-rw-r--r-- | modules/benchmark/benches.c | 14 | ||||
-rw-r--r-- | modules/benchmark/iperf3.c | 122 |
4 files changed, 138 insertions, 8 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 8902a9b1..c0c724ed 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -84,9 +84,7 @@ add_definitions("-Wformat") add_definitions("-Wformat-security") set(PACKAGE_LIBSOUP2_MINVERSION 2.42) -#Actually needed for save settings, steal_pointer - FIXME -set(PACKAGE_LIBGLIB2_MINVERSION 2.44) -#set(PACKAGE_LIBGLIB2_MINVERSION 2.28) +set(PACKAGE_LIBGLIB2_MINVERSION 2.24) ###################################DISTRO CHANGES############################### #Please add all distro relates stuff here @@ -148,9 +146,6 @@ if(${distro}${disversion} MATCHES "Oracle6*") set(HARDINFO2_GTK3 0) #old deprecated version - but ok set(PACKAGE_LIBSOUP2_MINVERSION 2.34.3) - #save settings disabled, steal_pointer disabled - set(PACKAGE_LIBGLIB2_MINVERSION 2.28.8) - message("-- Low GLIB2 version 2.28.0") endif() #debian 8 @@ -304,6 +299,7 @@ set(MODULE_benchmark_SOURCES_GTKANY modules/benchmark/sha1.c modules/benchmark/zlib.c modules/benchmark/sysbench.c + modules/benchmark/iperf3.c ) set(MODULE_benchmark_SOURCES_GTK2 modules/benchmark/drawing.c diff --git a/includes/benchmark.h b/includes/benchmark.h index 08392ad2..e7a0fc21 100644 --- a/includes/benchmark.h +++ b/includes/benchmark.h @@ -21,6 +21,7 @@ enum BenchmarkEntries { BENCHMARK_SBCPU_SINGLE, BENCHMARK_SBCPU_ALL, BENCHMARK_SBCPU_QUAD, + BENCHMARK_IPERF3_SINGLE, BENCHMARK_MEMORY_SINGLE, BENCHMARK_MEMORY_DUAL, BENCHMARK_MEMORY_QUAD, @@ -47,6 +48,7 @@ void benchmark_gui(void); void benchmark_nqueens(void); void benchmark_raytrace(void); void benchmark_zlib(void); +void benchmark_iperf3_single(void); typedef struct { double result; diff --git a/modules/benchmark/benches.c b/modules/benchmark/benches.c index c621d695..0a9f2bc2 100644 --- a/modules/benchmark/benches.c +++ b/modules/benchmark/benches.c @@ -47,6 +47,7 @@ BENCH_SIMPLE(BENCHMARK_BLOWFISH_THREADS, "CPU Blowfish (Multi-thread)", benchmar BENCH_SIMPLE(BENCHMARK_BLOWFISH_CORES, "CPU Blowfish (Multi-core)", benchmark_bfish_cores, 1); BENCH_SIMPLE(BENCHMARK_ZLIB, "CPU Zlib", benchmark_zlib, 1); BENCH_SIMPLE(BENCHMARK_CRYPTOHASH, "CPU CryptoHash", benchmark_cryptohash, 1); +BENCH_SIMPLE(BENCHMARK_IPERF3_SINGLE, "Iperf3 localhost", benchmark_iperf3_single, 1); BENCH_SIMPLE(BENCHMARK_SBCPU_SINGLE, "SysBench CPU (Single-thread)", benchmark_sbcpu_single, 1); BENCH_SIMPLE(BENCHMARK_SBCPU_ALL, "SysBench CPU (Multi-thread)", benchmark_sbcpu_all, 1); BENCH_SIMPLE(BENCHMARK_SBCPU_QUAD, "SysBench CPU (Four threads)", benchmark_sbcpu_quad, 1); @@ -151,6 +152,14 @@ static ModuleEntry entries[] = { scan_benchmark_raytrace, MODULE_FLAG_NONE, }, + [BENCHMARK_IPERF3_SINGLE] = + { + N_("Internal Network Speed"), + "memory.png", + callback_benchmark_iperf3_single, + scan_benchmark_iperf3_single, + MODULE_FLAG_NONE, + }, [BENCHMARK_SBCPU_SINGLE] = { N_("SysBench CPU (Single-thread)"), @@ -229,14 +238,15 @@ const gchar *hi_note_func(gint entry) case BENCHMARK_SBCPU_ALL: return _("Alexey Kopytov's <i><b>sysbench</b></i> is required.\n" "Results in events/second. Higher is better."); - case BENCHMARK_MEMORY_SINGLE: case BENCHMARK_MEMORY_DUAL: case BENCHMARK_MEMORY_QUAD: case BENCHMARK_MEMORY_ALL: return _("Alexey Kopytov's <i><b>sysbench</b></i> is required.\n" "Results in MiB/second. Higher is better."); - + case BENCHMARK_IPERF3_SINGLE: + return _("<i><b>iperf3</b></i> is required.\n" + "Results in Gbits/s. Higher is better."); case BENCHMARK_CRYPTOHASH: case BENCHMARK_BLOWFISH_SINGLE: case BENCHMARK_BLOWFISH_THREADS: diff --git a/modules/benchmark/iperf3.c b/modules/benchmark/iperf3.c new file mode 100644 index 00000000..5f773743 --- /dev/null +++ b/modules/benchmark/iperf3.c @@ -0,0 +1,122 @@ +/* + * HardInfo - System Information and Benchmark + * Copyright (C) 2020 Burt P. <pburt0@gmail.com> + * + * 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 + * the Free Software Foundation, version 2. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "hardinfo.h" +#include "benchmark.h" +#include <json-glib/json-glib.h> +#include <math.h> + +static int iperf3_version() { + int ret = -1.0; + int v1 = 0, v2 = 0, v3 = 0, mc = 0; + gboolean spawned; + gchar *out, *err, *p, *next_nl; + + spawned = g_spawn_command_line_sync("iperf3 --version", + &out, &err, NULL, NULL); + if (spawned) { + ret = 0; + p = out; + while(next_nl = strchr(p, '\n')) { + *next_nl = 0; + /* version */ + mc = sscanf(p, "iperf %d.%d", &v1, &v2); + if (mc >= 1) { + ret += v1 * 1000000; + ret += v2 * 1000; + ret += v3; + break; + } + p = next_nl + 1; + } + g_free(out); + g_free(err); + } + return ret; +} + +static gboolean iperf3_server() { + const char* argv[] = { + "iperf3", "-s", "--port", "61981", "--one-off", NULL }; + return g_spawn_async(NULL, (char**)argv, NULL, + G_SPAWN_STDERR_TO_DEV_NULL | G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_SEARCH_PATH, + NULL, NULL, NULL, NULL); +} + +static double _get_double(JsonParser *j, const char* path) { + double r = NAN; + GError *e = NULL; + JsonNode *root = json_parser_get_root(j); + JsonNode *ra = json_path_query(path, root, &e); + if (e) { + fprintf (stderr, "json_path_query(%s) error: %s\n", path, e->message); + } else { + JsonArray *arr = json_node_get_array(ra); + r = json_array_get_double_element(arr, 0); + } + json_node_free(ra); + return r; +} + +static bench_value iperf3_client() { + bench_value ret = EMPTY_BENCH_VALUE; + int v1 = 0, v2 = 0, v3 = 0, mc = 0; + gboolean spawned; + gchar *out, *err; + GError *e = NULL; + + const char cmd_line[] = "iperf3 -c localhost --port 61981 --json --omit 3 --time 5"; + + spawned = g_spawn_command_line_sync(cmd_line, + &out, &err, NULL, NULL); + if (spawned) { + JsonParser *j = json_parser_new(); + if (json_parser_load_from_data(j, out, -1, &e)) { + if (e) { + fprintf (stderr, "json_parser_load_from_data error: %s\n", e->message); + exit(-1); + } + strncpy(ret.extra, cmd_line, sizeof(ret.extra)-1); + ret.threads_used = 1; + ret.elapsed_time = _get_double(j, "$.end.sum_received.seconds"); + ret.result = _get_double(j, "$.end.sum_received.bits_per_second"); + ret.result /= 1000000.0; // now mega + ret.result /= 1000.0; // now giga + g_object_unref(j); + } + g_free(out); + g_free(err); + } + return ret; +} + +void benchmark_iperf3_single(void) { + bench_value r = EMPTY_BENCH_VALUE; + + shell_view_set_enabled(FALSE); + shell_status_update("Performing iperf3 localhost benchmark (single thread)..."); + + int v = iperf3_version(); + if (v > 0) { + iperf3_server(); + sleep(1); + r = iperf3_client(); + r.revision = v; + } + bench_results[BENCHMARK_IPERF3_SINGLE] = r; +} |