aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorhwspeedy <ns@bigbear.dk>2024-04-28 15:30:38 +0200
committerhwspeedy <ns@bigbear.dk>2024-04-28 15:30:38 +0200
commit4153afe55440fdc3841d38d5feaf88937add74b7 (patch)
treecea6c98cd169a66ddeb159d07375f61a6a3a6d17 /modules
parent3a21342979308eae15eb00a48aa9a2147d7db60e (diff)
FIX focuslost, missing status updates, benchmark aborting improved
Diffstat (limited to 'modules')
-rw-r--r--modules/benchmark.c85
-rw-r--r--modules/benchmark/benches.c27
-rw-r--r--modules/computer.c10
3 files changed, 65 insertions, 57 deletions
diff --git a/modules/benchmark.c b/modules/benchmark.c
index 770cb446..8e0b51fb 100644
--- a/modules/benchmark.c
+++ b/modules/benchmark.c
@@ -375,6 +375,7 @@ static void br_mi_add(char **results_list, bench_result *b, gboolean select)
if (*this_marker)
g_free(this_marker);
}
+
gint bench_result_sort(gconstpointer a, gconstpointer b)
{
bench_result *A = (bench_result *)a, *B = (bench_result *)b;
@@ -496,8 +497,7 @@ static struct bench_window get_bench_window(GSList *result_list,
window.max = len;
}
- DEBUG("...len: %d, loc: %d, win_size: %d, win: [%d..%d]\n", len, loc, size,
- window.min, window.max - 1);
+ //DEBUG("...len: %d, loc: %d, win_size: %d, win: [%d..%d]\n", len, loc, size, window.min, window.max - 1);
return window;
}
@@ -540,14 +540,11 @@ static gchar *benchmark_include_results_internal(bench_value this_machine_value,
/* prepare for shell */
moreinfo_del_with_prefix("BENCH");
- const struct bench_window window =
- get_bench_window(result_list, this_machine);
+ const struct bench_window window = get_bench_window(result_list, this_machine);
+
for (i = 0, li = result_list; li; li = g_slist_next(li), i++) {
bench_result *br = li->data;
-
- if (is_in_bench_window(&window, i))
- br_mi_add(&results, br, br == this_machine);
-
+ if (is_in_bench_window(&window, i)) br_mi_add(&results, br, br == this_machine);
bench_result_free(br); /* no longer needed */
}
g_slist_free(result_list);
@@ -603,16 +600,15 @@ do_benchmark_handler(GIOChannel *source, GIOCondition condition, gpointer data)
DEBUG("error while reading benchmark result");
r.result = -1.0f;
if(bench_dialog && &bench_dialog->r) bench_dialog->r = r;
- if(bench_dialog && bench_dialog->dialog) gtk_widget_destroy(bench_dialog->dialog);
+ gtk_dialog_response(GTK_DIALOG(bench_dialog->dialog),100);
return FALSE;
}
if(result) r = bench_value_from_str(result);
if(result && bench_dialog && &bench_dialog->r) bench_dialog->r = r;
- if(bench_dialog && bench_dialog->dialog) gtk_widget_destroy(bench_dialog->dialog);
g_free(result);
-
+ gtk_dialog_response(GTK_DIALOG(bench_dialog->dialog),GTK_RESPONSE_NONE);
return FALSE;
}
@@ -623,34 +619,36 @@ static void do_benchmark(void (*benchmark_function)(void), int entry)
if (params.skip_benchmarks)
return;
- if (params.gui_running) {
+ if (params.gui_running && !params.run_benchmark) {
gchar *argv[] = {params.argv0, "-b",entries[entry].name,NULL};
GPid bench_pid;
gint bench_stdout;
- GtkWidget *bench_dialog;
+ GtkWidget *bench_dialog = NULL;
GtkWidget *bench_image;
- BenchmarkDialog *benchmark_dialog;
+ BenchmarkDialog *benchmark_dialog = NULL;
GSpawnFlags spawn_flags = G_SPAWN_STDERR_TO_DEV_NULL;
- gchar *bench_status;
+ gchar *bench_status;
GtkWidget *content_area, *box, *label;
bench_value r = EMPTY_BENCH_VALUE;
+ GIOChannel *channel=NULL;
+ guint watch_id;
+ gboolean done=FALSE;
bench_results[entry] = r;
- bench_status = g_strdup_printf(_("Benchmarking: <b>%s</b>."), entries[entry].name);
+ bench_status = g_strdup_printf(_("Benchmarking: <b>%s</b>."), entries[entry].name);
shell_status_update(bench_status);
-
- g_free(bench_status);
-
- bench_image = icon_cache_get_image("benchmark.png");
+ g_free(bench_status);
bench_dialog = gtk_dialog_new_with_buttons ("Benchmarking...",
GTK_WINDOW(shell_get_main_shell()->transient_dialog),
- GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL,
+ GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL,
_("Stop"), GTK_RESPONSE_ACCEPT,
NULL);
content_area = gtk_dialog_get_content_area (GTK_DIALOG(bench_dialog));
+ bench_image = icon_cache_get_image("benchmark.png");
+
#if GTK_CHECK_VERSION(3,0,0)
box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 1);
#else
@@ -658,8 +656,6 @@ static void do_benchmark(void (*benchmark_function)(void), int entry)
#endif
label = gtk_label_new ("Please do not move your mouse\nor press any keys.");
- gtk_widget_show (bench_image);
-
#if GTK_CHECK_VERSION(3,0,0)
gtk_widget_set_halign (bench_image, GTK_ALIGN_START);
#else
@@ -673,9 +669,7 @@ static void do_benchmark(void (*benchmark_function)(void), int entry)
gtk_window_set_deletable(GTK_WINDOW(bench_dialog), FALSE);
gtk_widget_show_all (bench_dialog);
- while (gtk_events_pending()) {
- gtk_main_iteration();
- }
+ //while (gtk_events_pending()) {gtk_main_iteration();}
benchmark_dialog = g_new0(BenchmarkDialog, 1);
benchmark_dialog->dialog = bench_dialog;
@@ -688,37 +682,41 @@ static void do_benchmark(void (*benchmark_function)(void), int entry)
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);
+ //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);
- gboolean done=FALSE;
- switch (gtk_dialog_run(GTK_DIALOG(bench_dialog))) {
+ watch_id = g_io_add_watch(channel, G_IO_IN, do_benchmark_handler, benchmark_dialog);
+
+ switch (gtk_dialog_run(GTK_DIALOG(benchmark_dialog->dialog))) {
case GTK_RESPONSE_NONE:
- DEBUG("benchmark finished");
+ //DEBUG("benchmark finished");
if(benchmark_dialog) bench_results[entry] = benchmark_dialog->r;
done=TRUE;
break;
- case GTK_RESPONSE_ACCEPT:
- DEBUG("cancelling benchmark");
- }
+ case GTK_RESPONSE_ACCEPT:
+ //DEBUG("cancelling benchmark");
+ break;
+ }
- DEBUG("benchmark exiting");
- if(!done) if(bench_dialog) gtk_widget_destroy(bench_dialog);
+ //if(!done) DEBUG("benchmark NOT done");
if(!done) if(watch_id) g_source_remove(watch_id);
if(!done) kill(bench_pid, SIGINT);
+ if(!done) params.aborting_benchmarks=1;
g_io_channel_unref(channel);
+ //shell_status_set_enabled(FALSE);
+ //shell_view_set_enabled(TRUE);
+ if(benchmark_dialog && benchmark_dialog->dialog) gtk_widget_destroy(benchmark_dialog->dialog);
g_free(benchmark_dialog);
return;
}
- gtk_widget_destroy(bench_dialog);
+ //shell_status_set_enabled(FALSE);
+ //shell_view_set_enabled(TRUE);
+ //gtk_widget_activate(GTK_WINDOW(shell_get_main_shell()->window));
+ if(benchmark_dialog && benchmark_dialog->dialog) gtk_widget_destroy(benchmark_dialog->dialog);
g_free(benchmark_dialog);
+ return;
}
setpriority(PRIO_PROCESS, 0, -20);
@@ -843,9 +841,7 @@ static gchar *get_benchmark_results(gsize *len)
static gchar *run_benchmark(gchar *name)
{
int i;
-
- DEBUG("run_benchmark = %s", name);
-
+ //DEBUG("run_benchmark = %s", name);
for (i = 0; entries[i].name; i++) {
if (g_str_equal(entries[i].name, name)) {
void (*scan_callback)(gboolean rescan);
@@ -871,7 +867,6 @@ static gchar *run_benchmark(gchar *name)
}
}
}
-
return NULL;
}
diff --git a/modules/benchmark/benches.c b/modules/benchmark/benches.c
index 34ed5983..24d3bf19 100644
--- a/modules/benchmark/benches.c
+++ b/modules/benchmark/benches.c
@@ -20,22 +20,28 @@
#define BENCH_CALLBACK(CN, BN, BID, R) \
gchar *CN() { \
- if (R) \
+ DEBUG("BENCH CALLBACK %s\n",BN); \
+ params.aborting_benchmarks=0; \
+ if (R) \
return benchmark_include_results_reverse(bench_results[BID], BN); \
- else \
- return benchmark_include_results(bench_results[BID], BN); \
+ else \
+ return benchmark_include_results(bench_results[BID], BN); \
}
-#define BENCH_SCAN_SIMPLE(SN, BF, BID) \
+#define BENCH_SCAN_SIMPLE(SN, BF, BID, BN) \
void SN(gboolean reload) { \
- static gboolean scanned = FALSE; if (reload || bench_results[BID].result<=0.0) scanned = FALSE;if (scanned) return; \
- do_benchmark(BF, BID); \
- SCAN_END(); \
+ static gboolean scanned=FALSE; \
+ if(params.aborting_benchmarks) return; \
+ if (reload || bench_results[BID].result<=0.0) scanned = FALSE; \
+ if(reload){DEBUG("BENCH SCAN RELOAD %s\n",BN);} else if(scanned) {DEBUG("BENCH SCAN OK %s\n",BN);}else{DEBUG("BENCH SCAN %s\n",BN);} \
+ if (scanned) return; \
+ do_benchmark(BF, BID); \
+ scanned = TRUE; \
}
#define BENCH_SIMPLE(BID, BN, BF, R) \
BENCH_CALLBACK(callback_##BF, BN, BID, R); \
- BENCH_SCAN_SIMPLE(scan_##BF, BF, BID);
+ BENCH_SCAN_SIMPLE(scan_##BF, BF, BID, BN);
// ID, NAME, FUNCTION, R (0 = lower is better, 1 = higher is better)
BENCH_SIMPLE(BENCHMARK_FIB, "CPU Fibonacci", benchmark_fib, 1);
@@ -59,7 +65,8 @@ BENCH_SIMPLE(BENCHMARK_MEMORY_ALL, "SysBench Memory (Multi-thread)", benchmark_m
BENCH_CALLBACK(callback_benchmark_gui, "GPU Drawing", BENCHMARK_GUI, 1);
void scan_benchmark_gui(gboolean reload)
{
- static gboolean scanned = FALSE;
+ static gboolean scanned=FALSE;
+ if(params.aborting_benchmarks) return;
if (reload || bench_results[BENCHMARK_GUI].result<=0.0) scanned = FALSE;
if (scanned) return;
@@ -75,7 +82,7 @@ void scan_benchmark_gui(gboolean reload)
} else {
bench_results[BENCHMARK_GUI] = er;
}
- SCAN_END();
+ scanned = TRUE;
}
//Note: Same order as entries, used for json to server
diff --git a/modules/computer.c b/modules/computer.c
index 9b8c7a9c..11befa7b 100644
--- a/modules/computer.c
+++ b/modules/computer.c
@@ -454,6 +454,7 @@ static gchar *detect_machine_type(void)
/* Table based off imvirt by Thomas Liske <liske@ibh.de>
Copyright (c) 2008 IBH IT-Service GmbH under GPLv2. */
+char get_virtualization[100]={};
gchar *computer_get_virtualization(void)
{
gboolean found = FALSE;
@@ -492,6 +493,8 @@ gchar *computer_get_virtualization(void)
{ NULL }
};
gchar *tmp;
+ //Caching for speedup
+ if(get_virtualization[0]!=0) return g_strdup(get_virtualization);
DEBUG("Detecting virtual machine");
@@ -526,6 +529,7 @@ gchar *computer_get_virtualization(void)
if (found) {
DEBUG("%s found (by reading file %s)",
vm_types[j].vmtype, files[i]);
+ strcpy(get_virtualization,_(vm_types[j].vmtype));//Save
return g_strdup(_(vm_types[j].vmtype));
}
}
@@ -533,8 +537,10 @@ gchar *computer_get_virtualization(void)
}
DEBUG("no virtual machine detected; assuming physical machine");
-
- return detect_machine_type();
+ char *c=detect_machine_type();
+ strcpy(get_virtualization,c);//Save
+ free(c);
+ return g_strdup(get_virtualization);
}
gchar *callback_summary(void)