Merge pull request #73 from raboof/dontRemoveProcessesWhenViewingCumulativelyMerged
Don't time out processes in a cumulative view (fixes #39)
This commit is contained in:
98
src/cui.cpp
98
src/cui.cpp
@@ -348,85 +348,49 @@ void do_refresh() {
|
|||||||
refreshconninode();
|
refreshconninode();
|
||||||
refreshcount++;
|
refreshcount++;
|
||||||
|
|
||||||
ProcList *curproc = processes;
|
if (viewMode == VIEWMODE_KBPS) {
|
||||||
ProcList *previousproc = NULL;
|
remove_timed_out_processes();
|
||||||
int nproc = processes->size();
|
}
|
||||||
/* initialise to null pointers */
|
|
||||||
Line *lines[nproc];
|
|
||||||
int n = 0;
|
|
||||||
|
|
||||||
#ifndef NDEBUG
|
ProcList *curproc = processes;
|
||||||
// initialise to null pointers
|
int nproc = processes->size();
|
||||||
|
|
||||||
|
/* initialize to null pointers */
|
||||||
|
Line *lines[nproc];
|
||||||
for (int i = 0; i < nproc; i++)
|
for (int i = 0; i < nproc; i++)
|
||||||
lines[i] = NULL;
|
lines[i] = NULL;
|
||||||
#endif
|
|
||||||
|
int n = 0;
|
||||||
|
|
||||||
while (curproc != NULL) {
|
while (curproc != NULL) {
|
||||||
// walk though its connections, summing up their data, and
|
// walk though its connections, summing up their data, and
|
||||||
// throwing away connections that haven't received a package
|
// throwing away connections that haven't received a package
|
||||||
// in the last PROCESSTIMEOUT seconds.
|
// in the last CONNTIMEOUT seconds.
|
||||||
assert(curproc != NULL);
|
|
||||||
assert(curproc->getVal() != NULL);
|
assert(curproc->getVal() != NULL);
|
||||||
assert(nproc == processes->size());
|
assert(nproc == processes->size());
|
||||||
|
|
||||||
/* remove timed-out processes (unless it's one of the the unknown process)
|
float value_sent = 0, value_recv = 0;
|
||||||
*/
|
|
||||||
if ((curproc->getVal()->getLastPacket() + PROCESSTIMEOUT <=
|
if (viewMode == VIEWMODE_KBPS) {
|
||||||
curtime.tv_sec) &&
|
curproc->getVal()->getkbps(&value_recv, &value_sent);
|
||||||
(curproc->getVal() != unknowntcp) &&
|
} else if (viewMode == VIEWMODE_TOTAL_KB) {
|
||||||
(curproc->getVal() != unknownudp) && (curproc->getVal() != unknownip)) {
|
curproc->getVal()->gettotalkb(&value_recv, &value_sent);
|
||||||
if (DEBUG)
|
} else if (viewMode == VIEWMODE_TOTAL_MB) {
|
||||||
std::cout << "PROC: Deleting process\n";
|
curproc->getVal()->gettotalmb(&value_recv, &value_sent);
|
||||||
ProcList *todelete = curproc;
|
} else if (viewMode == VIEWMODE_TOTAL_B) {
|
||||||
Process *p_todelete = curproc->getVal();
|
curproc->getVal()->gettotalb(&value_recv, &value_sent);
|
||||||
if (previousproc) {
|
|
||||||
previousproc->next = curproc->next;
|
|
||||||
curproc = curproc->next;
|
|
||||||
} else {
|
|
||||||
processes = curproc->getNext();
|
|
||||||
curproc = processes;
|
|
||||||
}
|
|
||||||
delete todelete;
|
|
||||||
delete p_todelete;
|
|
||||||
nproc--;
|
|
||||||
// continue;
|
|
||||||
} else {
|
} else {
|
||||||
// add a non-timed-out process to the list of stuff to show
|
forceExit(false, "Invalid viewMode: %d", viewMode);
|
||||||
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);
|
|
||||||
}
|
|
||||||
uid_t uid = curproc->getVal()->getUid();
|
|
||||||
assert(curproc->getVal()->pid >= 0);
|
|
||||||
assert(n < nproc);
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
uid_t uid = curproc->getVal()->getUid();
|
||||||
|
assert(curproc->getVal()->pid >= 0);
|
||||||
|
assert(n < nproc);
|
||||||
|
|
||||||
|
lines[n] =
|
||||||
|
new Line(curproc->getVal()->name, value_recv, value_sent,
|
||||||
|
curproc->getVal()->pid, uid, curproc->getVal()->devicename);
|
||||||
|
curproc = curproc->next;
|
||||||
|
n++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* sort the accumulated lines */
|
/* sort the accumulated lines */
|
||||||
|
|||||||
@@ -346,3 +346,29 @@ void procclean() {
|
|||||||
// delete conninode;
|
// delete conninode;
|
||||||
prg_cache_clear();
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -129,4 +129,6 @@ void refreshconninode();
|
|||||||
|
|
||||||
void procclean();
|
void procclean();
|
||||||
|
|
||||||
|
void remove_timed_out_processes();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user