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
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e3e76b1
network graph scaling
marosg42 880bd44
no code change, only corrected the most crazy formatting
marosg42 0156da0
Scaling in different steps
marosg42 6deda9e
remove GTK_CHECK_VERSION
marosg42 c9d0a22
formatting request from monsta
marosg42 1568005
Help text updated
marosg42 43036f0
after rebase
marosg42 359e5fe
Merge branch 'master' into multiload-network-scale
raveit65 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
@@ -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); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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