Don't time out processes in a cumulative view (fixes #39)

This commit is contained in:
Arnout Engelen
2016-04-14 20:00:30 +02:00
parent 8b245e1be0
commit 3facf4f34b
3 changed files with 59 additions and 67 deletions

View File

@@ -348,63 +348,36 @@ void do_refresh() {
refreshconninode();
refreshcount++;
ProcList *curproc = processes;
ProcList *previousproc = NULL;
int nproc = processes->size();
/* initialise to null pointers */
Line *lines[nproc];
int n = 0;
if (viewMode == VIEWMODE_KBPS) {
remove_timed_out_processes();
}
#ifndef NDEBUG
// initialise to null pointers
ProcList *curproc = processes;
int nproc = processes->size();
/* initialize to null pointers */
Line *lines[nproc];
for (int i = 0; i < nproc; i++)
lines[i] = NULL;
#endif
int n = 0;
while (curproc != NULL) {
// walk though its connections, summing up their data, and
// throwing away connections that haven't received a package
// in the last PROCESSTIMEOUT seconds.
assert(curproc != NULL);
// in the last CONNTIMEOUT seconds.
assert(curproc->getVal() != NULL);
assert(nproc == processes->size());
/* remove timed-out processes (unless it's one of the the unknown process)
*/
if ((curproc->getVal()->getLastPacket() + PROCESSTIMEOUT <=
curtime.tv_sec) &&
(curproc->getVal() != unknowntcp) &&
(curproc->getVal() != unknownudp) && (curproc->getVal() != unknownip)) {
if (DEBUG)
std::cout << "PROC: Deleting process\n";
ProcList *todelete = curproc;
Process *p_todelete = curproc->getVal();
if (previousproc) {
previousproc->next = curproc->next;
curproc = curproc->next;
} else {
processes = curproc->getNext();
curproc = processes;
}
delete todelete;
delete p_todelete;
nproc--;
// continue;
} else {
// add a non-timed-out process to the list of stuff to show
float value_sent = 0, value_recv = 0;
if (viewMode == VIEWMODE_KBPS) {
// std::cout << "kbps viemode" << std::endl;
curproc->getVal()->getkbps(&value_recv, &value_sent);
} else if (viewMode == VIEWMODE_TOTAL_KB) {
// std::cout << "total viemode" << std::endl;
curproc->getVal()->gettotalkb(&value_recv, &value_sent);
} else if (viewMode == VIEWMODE_TOTAL_MB) {
// std::cout << "total viemode" << std::endl;
curproc->getVal()->gettotalmb(&value_recv, &value_sent);
} else if (viewMode == VIEWMODE_TOTAL_B) {
// std::cout << "total viemode" << std::endl;
curproc->getVal()->gettotalb(&value_recv, &value_sent);
} else {
forceExit(false, "Invalid viewMode: %d", viewMode);
@@ -416,17 +389,8 @@ void do_refresh() {
lines[n] =
new Line(curproc->getVal()->name, value_recv, value_sent,
curproc->getVal()->pid, uid, curproc->getVal()->devicename);
previousproc = curproc;
curproc = curproc->next;
n++;
#ifndef NDEBUG
assert(nproc == processes->size());
if (curproc == NULL)
assert(n - 1 < nproc);
else
assert(n < nproc);
#endif
}
}
/* sort the accumulated lines */

View File

@@ -346,3 +346,29 @@ void procclean() {
// delete conninode;
prg_cache_clear();
}
void remove_timed_out_processes() {
ProcList *previousproc = NULL;
for (ProcList *curproc = processes; curproc != NULL; curproc = curproc->next) {
if ((curproc->getVal()->getLastPacket() + PROCESSTIMEOUT <=
curtime.tv_sec) &&
(curproc->getVal() != unknowntcp) &&
(curproc->getVal() != unknownudp) && (curproc->getVal() != unknownip)) {
if (DEBUG)
std::cout << "PROC: Deleting process\n";
ProcList *todelete = curproc;
Process *p_todelete = curproc->getVal();
if (previousproc) {
previousproc->next = curproc->next;
curproc = curproc->next;
} else {
processes = curproc->getNext();
curproc = processes;
}
delete todelete;
delete p_todelete;
}
previousproc = curproc;
}
}

View File

@@ -129,4 +129,6 @@ void refreshconninode();
void procclean();
void remove_timed_out_processes();
#endif