Skip to content

Commit

Permalink
formatting request from monsta
Browse files Browse the repository at this point in the history
  • Loading branch information
marosg42 committed Feb 3, 2018
1 parent 6deda9e commit 7f1413c
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 82 deletions.
145 changes: 74 additions & 71 deletions multiload/linux-proc.c
Expand Up @@ -64,11 +64,10 @@ GetLoad (int Maximum, int data [5], LoadGraph *g)
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];
Expand Down Expand Up @@ -306,90 +305,94 @@ 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;

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

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

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

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

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

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

g_return_if_fail((netload.flags & needed_netload_flags) == needed_netload_flags);
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;
}

if (!(netload.if_flags & (1L << GLIBTOP_IF_FLAGS_UP)))
continue;
/*
* 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_LOOPBACK)) {
/* for loopback in and out are identical, so only count in */
present[LOCAL_COUNT] += netload.bytes_in;
continue;
present[IN_COUNT] += netload.bytes_in;
present[OUT_COUNT] += netload.bytes_out;
}

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

memcpy(past, present, sizeof past);
//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);
}
22 changes: 11 additions & 11 deletions multiload/load-graph.c
Expand Up @@ -429,30 +429,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);
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

0 comments on commit 7f1413c

Please sign in to comment.