Skip to content

Commit

Permalink
Scaling in different steps
Browse files Browse the repository at this point in the history
  • Loading branch information
marosg42 committed Jan 27, 2018
1 parent 880bd44 commit 2a41965
Show file tree
Hide file tree
Showing 6 changed files with 306 additions and 20 deletions.
5 changes: 4 additions & 1 deletion multiload/global.h
Expand Up @@ -49,7 +49,10 @@ struct _LoadGraph {
double loadavg1;
NetSpeed *netspeed_in;
NetSpeed *netspeed_out;
guint net_granularity;
guint net_threshold;
guint net_threshold1;
guint net_threshold2;
guint net_threshold3;

gboolean visible;
gboolean tooltip_update;
Expand Down
6 changes: 3 additions & 3 deletions multiload/linux-proc.c
Expand Up @@ -362,7 +362,6 @@ 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]);

if(ticks < 2) /* avoid initial spike */
{
ticks++;
Expand All @@ -384,10 +383,11 @@ GetNet (int Maximum, int data [4], LoadGraph *g)
total += delta[i];
}

max = autoscaler_get_max(&scaler, total);
//max = autoscaler_get_max(&scaler, total);

for (i = 0; i < COUNT_TYPES; i++) {
data[i] = rint (delta[i]);
//data[i] = rint (delta[i]);
data[i] = delta[i];
}
}

Expand Down
42 changes: 36 additions & 6 deletions multiload/load-graph.c
Expand Up @@ -91,21 +91,44 @@ load_graph_draw (LoadGraph *g)
/* This is for network graph */
else if (g->id == 2)
{
guint maxnet = 1;
guint maxnet = 1;
gint segments = 1;
gint combined = 0;
for (i = 0; i < g->draw_width; i++)
{
g->pos [i] = g->draw_height - 1;
combined = 0;
for (j = 0; j < g->n; j++)
combined += g->data[i][j];
//for (j = 0; j < g->n; j++)
combined += g->data[i][0];
combined += g->data[i][1];
combined += g->data[i][2];
if (combined > maxnet)
maxnet = combined;
}
maxnet = maxnet/g->net_granularity;
//printf("max = %d ", maxnet);
guint level = 0;
GdkRGBA grid_color;
if (maxnet > g->net_threshold3) {
g->net_threshold = g->net_threshold3;
level = 3;
}
else
if (maxnet > g->net_threshold2) {
g->net_threshold = g->net_threshold2;
level = 2;
}
else {
g->net_threshold = g->net_threshold1;
level = 1;
if (maxnet < g->net_threshold1)
level = 0;
}

//printf("level %d maxnet = %d ", level, maxnet);
maxnet = maxnet/g->net_threshold;
segments = MAX (maxnet+1,1);
float ratio = (float)g->draw_height/g->net_granularity/segments;
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);

for (j = 0; j < g->n-1; j++)
{
Expand Down Expand Up @@ -133,7 +156,6 @@ load_graph_draw (LoadGraph *g)

/* draw grid lines if needed */
gdk_cairo_set_source_rgba (cr, &(g->colors [4]));

double spacing = 0;
for (k = 0; k < segments -1; k++)
{
Expand All @@ -142,6 +164,14 @@ load_graph_draw (LoadGraph *g)
cairo_line_to (cr, g->draw_width-0.5, spacing);
}
cairo_stroke (cr);
if (level > 0)
{
gdk_cairo_set_source_rgba (cr, &(g->colors [5]));
for (k = 0; k< level; k++ )
cairo_rectangle(cr, 0.5, (k*2) * g->draw_height/5, 5, g->draw_height/5);
cairo_fill(cr);
}
cairo_stroke (cr);
}
/* this is Load graph */
else
Expand Down
25 changes: 19 additions & 6 deletions multiload/main.c
Expand Up @@ -363,21 +363,31 @@ multiload_create_graphs(MultiloadApplet *ma)
} graph_types[] = {
{ _("CPU Load"), "cpuload", 5, GetLoad },
{ _("Memory Load"), "memload", 5, GetMemory },
{ _("Net Load"), "netload2", 5, GetNet },
{ _("Net Load"), "netload2", 6, GetNet },
{ _("Swap Load"), "swapload", 2, GetSwap },
{ _("Load Average"), "loadavg", 3, GetLoadAvg },
{ _("Disk Load"), "diskload", 3, GetDiskLoad }
};

gint speed, size;
guint net_granularity;
guint net_threshold1;
guint net_threshold2;
guint net_threshold3;
gint i;

speed = g_settings_get_int (ma->settings, "speed");
size = g_settings_get_int (ma->settings, "size");
net_granularity = g_settings_get_uint (ma->settings, "netgranularity");
if (net_granularity == 0)
net_granularity = 100000;
net_threshold1 = g_settings_get_uint (ma->settings, "netthreshold1");
net_threshold2 = g_settings_get_uint (ma->settings, "netthreshold2");
net_threshold3 = g_settings_get_uint (ma->settings, "netthreshold3");
if (net_threshold1 >= net_threshold2)
{
net_threshold1 = net_threshold2 / 2;
}
if (net_threshold2 >= net_threshold3)
{
net_threshold3 = net_threshold2 * 2;
}
speed = MAX (speed, 50);
size = CLAMP (size, 10, 400);

Expand Down Expand Up @@ -408,8 +418,11 @@ multiload_create_graphs(MultiloadApplet *ma)
graph_types[i].callback);
}
/* 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_granularity = net_granularity;
ma->graphs[2]->net_threshold1 = net_threshold1;
ma->graphs[2]->net_threshold2 = net_threshold2;
ma->graphs[2]->net_threshold3 = net_threshold3;
/* 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;
}
Expand Down
16 changes: 16 additions & 0 deletions multiload/org.mate.panel.applet.multiload.gschema.xml.in
Expand Up @@ -93,10 +93,26 @@
<default>'#ffffff'</default>
<summary>Grid line color</summary>
</key>
<key name="netload2-color5" type="s">
<default>'#0000ff'</default>
<summary>Indicator color</summary>
</key>
<key name="netgranularity" type="u">
<default>100000</default>
<summary>Network graph granularity in bytes</summary>
</key>
<key name="netthreshold1" type="u">
<default>500000</default>
<summary>Network threshold 1 in bytes</summary>
</key>
<key name="netthreshold2" type="u">
<default>1500000</default>
<summary>Network threshold 2 in bytes</summary>
</key>
<key name="netthreshold3" type="u">
<default>15000000</default>
<summary>Network threshold 3 in bytes</summary>
</key>
<key name="swapload-color0" type="s">
<default>'#8b00c3'</default>
<summary>Graph color for user-related swap usage</summary>
Expand Down

0 comments on commit 2a41965

Please sign in to comment.