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 3 commits
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
14 changes: 9 additions & 5 deletions multiload/global.h
Expand Up @@ -49,6 +49,10 @@ struct _LoadGraph {
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;
Expand All @@ -58,20 +62,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
203 changes: 99 additions & 104 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,96 +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
};

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

gulong present[COUNT_TYPES] = {0};

guint i;
gchar **devices;
glibtop_netlist netlist;

enum Types {
IN_COUNT = 0,
OUT_COUNT = 1,
LOCAL_COUNT = 2,
COUNT_TYPES = 3
};

if(ticks == 0)
{
autoscaler_init(&scaler, 60, 501);
}
static int ticks = 0;
static gulong past[COUNT_TYPES] = {0};
static AutoScaler scaler;

gulong present[COUNT_TYPES] = {0};

devices = glibtop_get_netlist(&netlist);
guint i;
gchar **devices;
glibtop_netlist netlist;

for(i = 0; i < netlist.number; ++i)
{
int index;
glibtop_netload netload;
if(ticks == 0)
{
autoscaler_init(&scaler, 60, 501);
}

glibtop_get_netload(&netload, devices[i]);
devices = glibtop_get_netlist(&netlist);

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

if (!(netload.if_flags & (1L << GLIBTOP_IF_FLAGS_UP)))
continue;
glibtop_get_netload(&netload, devices[i]);

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]);
/*
* 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;

if(ticks < 2) /* avoid initial spike */
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 (Maximum * (float)delta[i] / max);
for (i = 0; i < COUNT_TYPES; i++) {
//data[i] = rint (delta[i]);
data[i] = 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);
memcpy(past, present, sizeof past);
}