summaryrefslogtreecommitdiff
path: root/multiload
diff options
context:
space:
mode:
Diffstat (limited to 'multiload')
-rw-r--r--multiload/global.h23
-rw-r--r--multiload/linux-proc.c57
-rw-r--r--multiload/load-graph.c27
-rw-r--r--multiload/main.c20
-rw-r--r--multiload/properties.c22
5 files changed, 85 insertions, 64 deletions
diff --git a/multiload/global.h b/multiload/global.h
index 606db7e4..ea8b6330 100644
--- a/multiload/global.h
+++ b/multiload/global.h
@@ -42,18 +42,6 @@ struct _LoadGraph {
gint show_frame;
- long cpu_time [NCPUSTATES];
- long cpu_last [NCPUSTATES];
- int cpu_initialized;
-
- double loadavg1;
- NetSpeed *netspeed_in;
- NetSpeed *netspeed_out;
- guint net_threshold;
- guint net_threshold1;
- guint net_threshold2;
- guint net_threshold3;
-
gboolean visible;
gboolean tooltip_update;
const gchar *name;
@@ -81,6 +69,17 @@ struct _MultiloadApplet
GtkWidget *prop_dialog;
GtkWidget *notebook;
int last_clicked;
+
+ long cpu_time [NCPUSTATES];
+ long cpu_last [NCPUSTATES];
+ int cpu_initialized;
+
+ double loadavg1;
+ NetSpeed *netspeed_in;
+ NetSpeed *netspeed_out;
+ guint net_threshold1;
+ guint net_threshold2;
+ guint net_threshold3;
};
#include "load-graph.h"
diff --git a/multiload/linux-proc.c b/multiload/linux-proc.c
index 00b35b50..b7bdec8b 100644
--- a/multiload/linux-proc.c
+++ b/multiload/linux-proc.c
@@ -52,33 +52,35 @@ GetLoad (int Maximum, int data [5], LoadGraph *g)
{
int usr, nice, sys, iowait, free;
int total;
-
glibtop_cpu cpu;
+ MultiloadApplet *multiload;
+
+ multiload = g->multiload;
glibtop_get_cpu (&cpu);
g_return_if_fail ((cpu.flags & needed_cpu_flags) == needed_cpu_flags);
- g->cpu_time [0] = cpu.user;
- g->cpu_time [1] = cpu.nice;
- g->cpu_time [2] = cpu.sys;
- g->cpu_time [3] = cpu.iowait + cpu.irq + cpu.softirq;
- g->cpu_time [4] = cpu.idle;
+ multiload->cpu_time [0] = cpu.user;
+ multiload->cpu_time [1] = cpu.nice;
+ multiload->cpu_time [2] = cpu.sys;
+ multiload->cpu_time [3] = cpu.iowait + cpu.irq + cpu.softirq;
+ multiload->cpu_time [4] = cpu.idle;
- if (!g->cpu_initialized) {
- memcpy (g->cpu_last, g->cpu_time, sizeof (g->cpu_last));
- g->cpu_initialized = 1;
+ if (!multiload->cpu_initialized) {
+ memcpy (multiload->cpu_last, multiload->cpu_time, sizeof (multiload->cpu_last));
+ multiload->cpu_initialized = 1;
}
- usr = g->cpu_time [0] - g->cpu_last [0];
- nice = g->cpu_time [1] - g->cpu_last [1];
- sys = g->cpu_time [2] - g->cpu_last [2];
- iowait = g->cpu_time [3] - g->cpu_last [3];
- free = g->cpu_time [4] - g->cpu_last [4];
+ usr = multiload->cpu_time [0] - multiload->cpu_last [0];
+ nice = multiload->cpu_time [1] - multiload->cpu_last [1];
+ sys = multiload->cpu_time [2] - multiload->cpu_last [2];
+ iowait = multiload->cpu_time [3] - multiload->cpu_last [3];
+ free = multiload->cpu_time [4] - multiload->cpu_last [4];
total = usr + nice + sys + free + iowait;
- memcpy(g->cpu_last, g->cpu_time, sizeof g->cpu_last);
+ memcpy(multiload->cpu_last, multiload->cpu_time, sizeof multiload->cpu_last);
usr = rint (Maximum * (float)(usr) / total);
nice = rint (Maximum * (float)(nice) / total);
@@ -107,7 +109,11 @@ GetDiskLoad (int Maximum, int data [3], LoadGraph *g)
guint64 read, write;
guint64 readdiff, writediff;
- nvme_diskstats = g_settings_get_boolean (g->multiload->settings, "diskload-nvme-diskstats");
+ MultiloadApplet *multiload;
+
+ multiload = g->multiload;
+
+ nvme_diskstats = g_settings_get_boolean (multiload->settings, "diskload-nvme-diskstats");
if(first_call)
{
@@ -125,7 +131,7 @@ GetDiskLoad (int Maximum, int data [3], LoadGraph *g)
fdr = fopen("/proc/diskstats", "r");
if (!fdr)
{
- g_settings_set_boolean (g->multiload->settings, "diskload-nvme-diskstats", FALSE);
+ g_settings_set_boolean (multiload->settings, "diskload-nvme-diskstats", FALSE);
return;
}
@@ -297,14 +303,17 @@ void
GetLoadAvg (int Maximum, int data [2], LoadGraph *g)
{
glibtop_loadavg loadavg;
+ MultiloadApplet *multiload;
+
+ multiload = g->multiload;
glibtop_get_loadavg (&loadavg);
g_return_if_fail ((loadavg.flags & needed_loadavg_flags) == needed_loadavg_flags);
- /* g->loadavg1 represents %used */
- g->loadavg1 = loadavg.loadavg[0];
+ /* multiload->loadavg1 represents %used */
+ multiload->loadavg1 = loadavg.loadavg[0];
- data [0] = rint ((float) Maximum * g->loadavg1);
+ data [0] = rint ((float) Maximum * multiload->loadavg1);
data [1] = Maximum - data[0];
}
@@ -369,6 +378,10 @@ GetNet (int Maximum, int data [4], LoadGraph *g)
gchar **devices;
glibtop_netlist netlist;
+ MultiloadApplet *multiload;
+
+ multiload = g->multiload;
+
if(ticks == 0)
{
autoscaler_init(&scaler, 60, 501);
@@ -405,8 +418,8 @@ GetNet (int Maximum, int data [4], LoadGraph *g)
}
g_strfreev(devices);
- netspeed_add(g->netspeed_in, present[IN_COUNT]);
- netspeed_add(g->netspeed_out, present[OUT_COUNT]);
+ netspeed_add (multiload->netspeed_in, present[IN_COUNT]);
+ netspeed_add (multiload->netspeed_out, present[OUT_COUNT]);
if(ticks < 2) /* avoid initial spike */
{
diff --git a/multiload/load-graph.c b/multiload/load-graph.c
index 6652a6f2..f1d1a9d0 100644
--- a/multiload/load-graph.c
+++ b/multiload/load-graph.c
@@ -51,6 +51,9 @@ load_graph_draw (LoadGraph *g)
guint i, j, k;
cairo_t *cr;
int load;
+ MultiloadApplet *multiload;
+
+ multiload = g->multiload;
/* we might get called before the configure event so that
* g->disp->allocation may not have the correct size
@@ -94,6 +97,8 @@ load_graph_draw (LoadGraph *g)
guint maxnet = 1;
gint segments = 1;
gint combined;
+ guint net_threshold;
+
for (i = 0; i < g->draw_width; i++)
{
g->pos [i] = g->draw_height - 1;
@@ -106,27 +111,27 @@ load_graph_draw (LoadGraph *g)
}
//printf("max = %d ", maxnet);
guint level = 0;
- if (maxnet > g->net_threshold3) {
- g->net_threshold = g->net_threshold3;
+ if (maxnet > multiload->net_threshold3) {
+ net_threshold = multiload->net_threshold3;
level = 3;
}
else
- if (maxnet > g->net_threshold2) {
- g->net_threshold = g->net_threshold2;
+ if (maxnet > multiload->net_threshold2) {
+ net_threshold = multiload->net_threshold2;
level = 2;
}
else {
- g->net_threshold = g->net_threshold1;
+ net_threshold = multiload->net_threshold1;
level = 1;
- if (maxnet < g->net_threshold1)
+ if (maxnet < multiload->net_threshold1)
level = 0;
}
//printf("level %d maxnet = %d ", level, maxnet);
- maxnet = maxnet/g->net_threshold;
+ maxnet = maxnet/net_threshold;
segments = MAX (maxnet+1,1);
- float ratio = (float)g->draw_height/g->net_threshold/segments;
- //printf("segments %d ratio = %f t1=%ld t2=%ld t3=%ld t=%ld\n", segments, ratio, g->net_threshold1, g->net_threshold2, g->net_threshold3, g->net_threshold);
+ float ratio = (float)g->draw_height/net_threshold/segments;
+ //printf("segments %d ratio = %f t1=%ld t2=%ld t3=%ld t=%ld\n", segments, ratio, multiload->net_threshold1, multiload->net_threshold2, multiload->net_threshold3, multiload->net_threshold);
for (j = 0; j < g->n-1; j++)
{
@@ -338,8 +343,6 @@ load_graph_destroy (GtkWidget *widget, gpointer data_ptr)
LoadGraph *g = (LoadGraph *) data_ptr;
load_graph_stop (g);
- netspeed_delete(g->netspeed_in);
- netspeed_delete(g->netspeed_out);
gtk_widget_destroy(widget);
}
@@ -405,8 +408,6 @@ load_graph_new (MultiloadApplet *ma, guint n, const gchar *label,
MatePanelAppletOrient orient;
g = g_new0 (LoadGraph, 1);
- g->netspeed_in = netspeed_new(g);
- g->netspeed_out = netspeed_new(g);
g->visible = visible;
g->name = name;
g->n = n;
diff --git a/multiload/main.c b/multiload/main.c
index cd647cba..db7ef3cc 100644
--- a/multiload/main.c
+++ b/multiload/main.c
@@ -209,6 +209,9 @@ multiload_destroy_cb(GtkWidget *widget, gpointer data)
g_free(ma->graphs[i]);
}
+ netspeed_delete (ma->netspeed_in);
+ netspeed_delete (ma->netspeed_out);
+
if (ma->about_dialog)
gtk_widget_destroy (ma->about_dialog);
@@ -267,10 +270,13 @@ void
multiload_applet_tooltip_update(LoadGraph *g)
{
gchar *tooltip_text, *name;
+ MultiloadApplet *multiload;
g_assert(g);
g_assert(g->name);
+ multiload = g->multiload;
+
/* label the tooltip intuitively */
if (!strncmp(g->name, "cpuload", strlen("cpuload")))
name = g_strdup(_("Processor"));
@@ -308,12 +314,12 @@ multiload_applet_tooltip_update(LoadGraph *g)
} else if (!strcmp(g->name, "loadavg")) {
tooltip_text = g_strdup_printf(_("The system load average is %0.02f"),
- g->loadavg1);
+ multiload->loadavg1);
} else if (!strcmp(g->name, "netload2")) {
char *tx_in, *tx_out;
- tx_in = netspeed_get(g->netspeed_in);
- tx_out = netspeed_get(g->netspeed_out);
+ tx_in = netspeed_get(multiload->netspeed_in);
+ tx_out = netspeed_get(multiload->netspeed_out);
/* xgettext: same as in graphic tab of g-s-m */
tooltip_text = g_strdup_printf(_("%s:\n"
"Receiving %s\n"
@@ -415,9 +421,11 @@ multiload_create_graphs(MultiloadApplet *ma)
/* for Network graph, colors[4] is grid line color, it should not be used in loop in load-graph.c */
/* for Network graph, colors[5] is indicator color, it should not be used in loop in load-graph.c */
ma->graphs[2]->n = 4;
- ma->graphs[2]->net_threshold1 = net_threshold1;
- ma->graphs[2]->net_threshold2 = net_threshold2;
- ma->graphs[2]->net_threshold3 = net_threshold3;
+ ma->net_threshold1 = net_threshold1;
+ ma->net_threshold2 = net_threshold2;
+ ma->net_threshold3 = net_threshold3;
+ ma->netspeed_in = netspeed_new(ma->graphs[2]);
+ ma->netspeed_out = netspeed_new(ma->graphs[2]);
/* for Load graph, colors[2] is grid line color, it should not be used in loop in load-graph.c */
ma->graphs[4]->n = 2;
}
diff --git a/multiload/properties.c b/multiload/properties.c
index de4c060b..8849943c 100644
--- a/multiload/properties.c
+++ b/multiload/properties.c
@@ -185,45 +185,45 @@ spin_button_changed_cb(GtkWidget *widget, gpointer name)
case PROP_NET_THRESHOLD1:
g_settings_set_uint (ma->settings, (gchar *)name, value);
- if (value >= ma->graphs[2]->net_threshold2)
+ if (value >= ma->net_threshold2)
{
gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget),
(gdouble)g_settings_get_uint (ma->settings, "netthreshold2") - 1);
- ma->graphs[2]->net_threshold1 = g_settings_get_uint (ma->settings, "netthreshold2") - 1;
+ ma->net_threshold1 = g_settings_get_uint (ma->settings, "netthreshold2") - 1;
}
else
- ma->graphs[2]->net_threshold1 = value;
+ ma->net_threshold1 = value;
break;
case PROP_NET_THRESHOLD2:
g_settings_set_uint (ma->settings, (gchar *)name, value);
- if (value >= ma->graphs[2]->net_threshold3)
+ if (value >= ma->net_threshold3)
{
gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget),
(gdouble)g_settings_get_uint (ma->settings, "netthreshold3") - 1);
- ma->graphs[2]->net_threshold2 = g_settings_get_uint (ma->settings, "netthreshold3") - 1;
+ ma->net_threshold2 = g_settings_get_uint (ma->settings, "netthreshold3") - 1;
}
- else if (value <= ma->graphs[2]->net_threshold1)
+ else if (value <= ma->net_threshold1)
{
gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget),
(gdouble)g_settings_get_uint (ma->settings, "netthreshold1") + 1);
- ma->graphs[2]->net_threshold2 = g_settings_get_uint (ma->settings, "netthreshold1") + 1;
+ ma->net_threshold2 = g_settings_get_uint (ma->settings, "netthreshold1") + 1;
}
else
- ma->graphs[2]->net_threshold2 = value;
+ ma->net_threshold2 = value;
break;
case PROP_NET_THRESHOLD3:
g_settings_set_uint (ma->settings, (gchar *)name, value);
- if (value <= ma->graphs[2]->net_threshold2)
+ if (value <= ma->net_threshold2)
{
gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget),
(gdouble)g_settings_get_uint (ma->settings, "netthreshold2") + 1);
- ma->graphs[2]->net_threshold3 = g_settings_get_uint (ma->settings, "netthreshold2") + 1;
+ ma->net_threshold3 = g_settings_get_uint (ma->settings, "netthreshold2") + 1;
}
else
- ma->graphs[2]->net_threshold3 = value;
+ ma->net_threshold3 = value;
break;
default:
g_assert_not_reached();