Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiload network scale #301

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 6 additions & 5 deletions multiload/global.h
Expand Up @@ -49,6 +49,7 @@ struct _LoadGraph {
double loadavg1;
NetSpeed *netspeed_in;
NetSpeed *netspeed_out;
guint net_granularity;

gboolean visible;
gboolean tooltip_update;
Expand All @@ -58,20 +59,20 @@ struct _LoadGraph {
struct _MultiloadApplet
{
MatePanelApplet *applet;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pushed these cleanups as a separate commit


GSettings *settings;

LoadGraph *graphs[NGRAPHS];

GtkWidget *box;

gboolean view_cpuload;
gboolean view_memload;
gboolean view_netload;
gboolean view_swapload;
gboolean view_loadavg;
gboolean view_diskload;

GtkWidget *about_dialog;
GtkWidget *check_boxes[NGRAPHS];
GtkWidget *prop_dialog;
Expand Down
10 changes: 3 additions & 7 deletions multiload/linux-proc.c
Expand Up @@ -387,14 +387,10 @@ GetNet (int Maximum, int data [4], LoadGraph *g)

max = autoscaler_get_max(&scaler, total);

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

//data[4] = Maximum - data[3] - data[2] - data[1] - data[0];
data[COUNT_TYPES] = Maximum;
for (i = 0; i < COUNT_TYPES; i++)
data[COUNT_TYPES] -= data[i];

memcpy(past, present, sizeof past);
}
58 changes: 56 additions & 2 deletions multiload/load-graph.c
Expand Up @@ -66,8 +66,8 @@ load_graph_draw (LoadGraph *g)
cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);

/* all graphs except Load go this path */
if (g->id != 4)
/* all graphs except Load and Net go this path */
if (g->id != 4 && g->id != 2)
{
for (i = 0; i < g->draw_width; i++)
g->pos [i] = g->draw_height - 1;
Expand All @@ -87,7 +87,61 @@ load_graph_draw (LoadGraph *g)
}
cairo_stroke (cr);
}
}
/* This is for network graph */
else if (g->id == 2)
{
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];
if (combined > maxnet)
maxnet = combined;
}
maxnet = maxnet/g->net_granularity;
segments = MAX (maxnet+1,1);
float ratio = (float)g->draw_height/g->net_granularity/segments;

for (j = 0; j < g->n-1; j++)
{
gdk_cairo_set_source_rgba (cr, &(g->colors [j]));

for (i = 0; i < g->draw_width; i++)
{
cairo_move_to (cr, g->draw_width - i - 0.5, g->pos[i] + 0.5);
cairo_line_to (cr, g->draw_width - i - 0.5, g->pos[i] - 0.5 - ((g->data [i][j] * ratio)));
g->pos [i] -= ((g->data [i][j] * ratio));
}
cairo_stroke (cr);
}

for (j = g->n-1; j < g->n; j++)
{
gdk_cairo_set_source_rgba (cr, &(g->colors [j]));
for (i = 0; i < g->draw_width; i++)
{
cairo_move_to (cr, g->draw_width - i - 0.5, g->pos[i] + 0.5);
cairo_line_to (cr, g->draw_width - i - 0.5, 0.5);
}
cairo_stroke (cr);
}

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

double spacing = 0;
for (k = 0; k < segments -1; k++)
{
spacing = ((double) g->draw_height/segments) * (k+1);
cairo_move_to (cr, 0.5, spacing);
cairo_line_to (cr, g->draw_width-0.5, spacing);
}
cairo_stroke (cr);
}
/* this is Load graph */
else
Expand Down
13 changes: 10 additions & 3 deletions multiload/main.c
Expand Up @@ -363,17 +363,21 @@ multiload_create_graphs(MultiloadApplet *ma)
} graph_types[] = {
{ _("CPU Load"), "cpuload", 5, GetLoad },
{ _("Memory Load"), "memload", 5, GetMemory },
{ _("Net Load"), "netload2", 4, GetNet },
{ _("Net Load"), "netload2", 5, GetNet },
{ _("Swap Load"), "swapload", 2, GetSwap },
{ _("Load Average"), "loadavg", 3, GetLoadAvg },
{ _("Disk Load"), "diskload", 3, GetDiskLoad }
};

gint speed, size;
guint net_granularity;
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;
speed = MAX (speed, 50);
size = CLAMP (size, 10, 400);

Expand Down Expand Up @@ -403,8 +407,11 @@ multiload_create_graphs(MultiloadApplet *ma)
graph_types[i].name,
graph_types[i].callback);
}
/* 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;
/* for Network graph, colors[4] is grid line color, it should not be used in loop in load-graph.c */
ma->graphs[2]->n = 4;
ma->graphs[2]->net_granularity = net_granularity;
/* 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;
}

/* remove the old graphs and rebuild them */
Expand Down
8 changes: 8 additions & 0 deletions multiload/org.mate.panel.applet.multiload.gschema.xml.in
Expand Up @@ -89,6 +89,14 @@
<default>'#000000'</default>
<summary>Network graph background color</summary>
</key>
<key name="netload2-color4" type="s">
<default>'#ffffff'</default>
<summary>Grid line color</summary>
</key>
<key name="netgranularity" type="u">
<default>100000</default>
<summary>Network graph granularity in bytes</summary>
</key>
<key name="swapload-color0" type="s">
<default>'#8b00c3'</default>
<summary>Graph color for user-related swap usage</summary>
Expand Down
1 change: 1 addition & 0 deletions multiload/properties.c
Expand Up @@ -613,6 +613,7 @@ fill_properties(GtkWidget *dialog, MultiloadApplet *ma)
add_color_selector(page, _("_Out"), "netload2-color1", ma);
add_color_selector (page, _("_Local"), "netload2-color2", ma);
add_color_selector(page, _("_Background"), "netload2-color3", ma);
add_color_selector(page, _("_Gridline"), "netload2-color4", ma);

page = add_page(ma->notebook, _("Swap Space"));
gtk_container_set_border_width (GTK_CONTAINER (page), 12);
Expand Down