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
201 changes: 100 additions & 101 deletions multiload/linux-proc.c
Expand Up @@ -49,47 +49,48 @@ static const unsigned needed_netload_flags =
void
GetLoad (int Maximum, int data [5], LoadGraph *g)
{
int usr, nice, sys, iowait, free;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we use 2 spaces instead of 4 everywhere...?

int total;
int usr, nice, sys, iowait, free;
int total;

glibtop_cpu cpu;
glibtop_cpu cpu;

glibtop_get_cpu (&cpu);
glibtop_get_cpu (&cpu);

g_return_if_fail ((cpu.flags & needed_cpu_flags) == needed_cpu_flags);
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;
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;

if (!g->cpu_initialized) {
memcpy (g->cpu_last, g->cpu_time, sizeof (g->cpu_last));
g->cpu_initialized = 1;
}
if (!g->cpu_initialized)
{
memcpy (g->cpu_last, g->cpu_time, sizeof (g->cpu_last));
g->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 = 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];

total = usr + nice + sys + free + iowait;
total = usr + nice + sys + free + iowait;

memcpy(g->cpu_last, g->cpu_time, sizeof g->cpu_last);
memcpy(g->cpu_last, g->cpu_time, sizeof g->cpu_last);

usr = rint (Maximum * (float)(usr) / total);
nice = rint (Maximum * (float)(nice) / total);
sys = rint (Maximum * (float)(sys) / total);
iowait = rint (Maximum * (float)(iowait) / total);
free = Maximum - usr - nice - sys - iowait;
usr = rint (Maximum * (float)(usr) / total);
nice = rint (Maximum * (float)(nice) / total);
sys = rint (Maximum * (float)(sys) / total);
iowait = rint (Maximum * (float)(iowait) / total);
free = Maximum - usr - nice - sys - iowait;

data [0] = usr;
data [1] = sys;
data [2] = nice;
data [3] = iowait;
data [4] = free;
data [0] = usr;
data [1] = sys;
data [2] = nice;
data [3] = iowait;
data [4] = free;
}

void
Expand Down Expand Up @@ -305,92 +306,90 @@ is_net_device_virtual(char *device)
void
GetNet (int Maximum, int data [4], LoadGraph *g)
{
enum Types {
IN_COUNT = 0,
OUT_COUNT = 1,
LOCAL_COUNT = 2,
COUNT_TYPES = 3
};
enum Types {
IN_COUNT = 0,
OUT_COUNT = 1,
LOCAL_COUNT = 2,
COUNT_TYPES = 3
};

static int ticks = 0;
static gulong past[COUNT_TYPES] = {0};
static AutoScaler scaler;
static int ticks = 0;
static gulong past[COUNT_TYPES] = {0};
static AutoScaler scaler;

gulong present[COUNT_TYPES] = {0};
gulong present[COUNT_TYPES] = {0};

guint i;
gchar **devices;
glibtop_netlist netlist;
guint i;
gchar **devices;
glibtop_netlist netlist;

if(ticks == 0)
{
autoscaler_init(&scaler, 60, 501);
}

if(ticks == 0)
{
autoscaler_init(&scaler, 60, 501);
}
devices = glibtop_get_netlist(&netlist);

for(i = 0; i < netlist.number; ++i)
{
int index;
glibtop_netload netload;

devices = glibtop_get_netlist(&netlist);

for(i = 0; i < netlist.number; ++i)
{
int index;
glibtop_netload netload;
glibtop_get_netload(&netload, devices[i]);

glibtop_get_netload(&netload, devices[i]);

g_return_if_fail((netload.flags & needed_netload_flags) == needed_netload_flags);

if (!(netload.if_flags & (1L << GLIBTOP_IF_FLAGS_UP)))
continue;

if (netload.if_flags & (1L << GLIBTOP_IF_FLAGS_LOOPBACK)) {
/* for loopback in and out are identical, so only count in */
present[LOCAL_COUNT] += netload.bytes_in;
continue;
}
g_return_if_fail((netload.flags & needed_netload_flags) == needed_netload_flags);

/*
* Do not include virtual devices (VPN, PPPOE...) to avoid
* counting the same throughput several times.
*/
if (is_net_device_virtual(devices[i]))
continue;
if (!(netload.if_flags & (1L << GLIBTOP_IF_FLAGS_UP)))
continue;

present[IN_COUNT] += netload.bytes_in;
present[OUT_COUNT] += netload.bytes_out;
if (netload.if_flags & (1L << GLIBTOP_IF_FLAGS_LOOPBACK)) {
/* for loopback in and out are identical, so only count in */
present[LOCAL_COUNT] += netload.bytes_in;
continue;
}

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 */
/*
* Do not include virtual devices (VPN, PPPOE...) to avoid
* counting the same throughput several times.
*/
if (is_net_device_virtual(devices[i]))
continue;

present[IN_COUNT] += netload.bytes_in;
present[OUT_COUNT] += netload.bytes_out;
}

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++;
memset(data, 0, COUNT_TYPES * sizeof data[0]);
}
else
{
int delta[COUNT_TYPES];
int max;
int total = 0;

for (i = 0; i < COUNT_TYPES; i++)
{
ticks++;
memset(data, 0, COUNT_TYPES * sizeof data[0]);
/* protect against weirdness */
if (present[i] >= past[i])
delta[i] = (present[i] - past[i]);
else
delta[i] = 0;
total += delta[i];
}
else
{
int delta[COUNT_TYPES];
int max;
int total = 0;

for (i = 0; i < COUNT_TYPES; i++)
{
/* protect against weirdness */
if (present[i] >= past[i])
delta[i] = (present[i] - past[i]);
else
delta[i] = 0;
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]);
}
for (i = 0; i < COUNT_TYPES; i++) {
data[i] = rint (delta[i]);
}
}

memcpy(past, present, sizeof past);
memcpy(past, present, sizeof past);
}
26 changes: 13 additions & 13 deletions multiload/load-graph.c
Expand Up @@ -200,12 +200,12 @@ static gboolean
load_graph_update (LoadGraph *g)
{
if (g->data == NULL)
return TRUE;
return TRUE;

shift_right(g);

if (g->tooltip_update)
multiload_applet_tooltip_update(g);
multiload_applet_tooltip_update(g);

g->get_data (g->draw_height, g->data [0], g);

Expand Down Expand Up @@ -399,30 +399,30 @@ load_graph_new (MultiloadApplet *ma, guint n, const gchar *label,
case MATE_PANEL_APPLET_ORIENT_UP:
case MATE_PANEL_APPLET_ORIENT_DOWN:
{
g->orient = FALSE;
break;
g->orient = FALSE;
break;
}
case MATE_PANEL_APPLET_ORIENT_LEFT:
case MATE_PANEL_APPLET_ORIENT_RIGHT:
{
g->orient = TRUE;
break;
g->orient = TRUE;
break;
}
default:
g_assert_not_reached ();
g_assert_not_reached ();
}

if (g->show_frame)
{
g->frame = gtk_frame_new (NULL);
Copy link
Contributor

Choose a reason for hiding this comment

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

Corrected some of these tab/space mix cases in master - you'll probably need to rebase

gtk_frame_set_shadow_type (GTK_FRAME (g->frame), GTK_SHADOW_IN);
gtk_container_add (GTK_CONTAINER (g->frame), g->box);
gtk_box_pack_start (GTK_BOX (g->main_widget), g->frame, TRUE, TRUE, 0);
g->frame = gtk_frame_new (NULL);
gtk_frame_set_shadow_type (GTK_FRAME (g->frame), GTK_SHADOW_IN);
gtk_container_add (GTK_CONTAINER (g->frame), g->box);
gtk_box_pack_start (GTK_BOX (g->main_widget), g->frame, TRUE, TRUE, 0);
}
else
{
g->frame = NULL;
gtk_box_pack_start (GTK_BOX (g->main_widget), g->box, TRUE, TRUE, 0);
g->frame = NULL;
gtk_box_pack_start (GTK_BOX (g->main_widget), g->box, TRUE, TRUE, 0);
}

load_graph_load_config (g);
Expand Down