Add sort by PID option
This commit is contained in:
@@ -78,6 +78,9 @@ Show only processes with the specified pid(s).
|
||||
\fB-j\fP
|
||||
Output in JSON format.
|
||||
.TP
|
||||
\fB-z\fP
|
||||
Sort by PID.
|
||||
.TP
|
||||
\fB-f\fP
|
||||
EXPERIMENTAL: specify string pcap filter (like tcpdump). This may be removed or changed in a future version.
|
||||
.TP
|
||||
|
||||
11
src/cui.cpp
11
src/cui.cpp
@@ -44,6 +44,7 @@ extern Process *unknownudp;
|
||||
extern Process *unknownip;
|
||||
|
||||
extern bool sortRecv;
|
||||
extern bool sortPID;
|
||||
|
||||
extern int viewMode;
|
||||
extern bool showcommandline;
|
||||
@@ -97,8 +98,6 @@ public:
|
||||
double sent_value;
|
||||
double recv_value;
|
||||
const char *devicename;
|
||||
|
||||
private:
|
||||
const char *m_name;
|
||||
const char *m_cmdline;
|
||||
pid_t m_pid;
|
||||
@@ -300,14 +299,18 @@ int GreatestFirst(const void *ma, const void *mb) {
|
||||
Line *a = *pa;
|
||||
Line *b = *pb;
|
||||
double aValue;
|
||||
if (sortRecv) {
|
||||
if (sortPID) {
|
||||
aValue = a->m_pid;
|
||||
} else if (sortRecv) {
|
||||
aValue = a->recv_value;
|
||||
} else {
|
||||
aValue = a->sent_value;
|
||||
}
|
||||
|
||||
double bValue;
|
||||
if (sortRecv) {
|
||||
if (sortPID) {
|
||||
bValue = (double)b->m_pid;
|
||||
} else if (sortRecv) {
|
||||
bValue = b->recv_value;
|
||||
} else {
|
||||
bValue = b->sent_value;
|
||||
|
||||
@@ -70,6 +70,7 @@ static void help(bool iserror) {
|
||||
output << " m: switch between total (kB, bytes, MB) and throughput (kB/s, "
|
||||
" MB/s, GB/s) mode\n";
|
||||
output << " j: json output\n";
|
||||
output << " z: sort by PIDn";
|
||||
}
|
||||
|
||||
void quit_cb(int /* i */) {
|
||||
@@ -154,7 +155,7 @@ int main(int argc, char **argv) {
|
||||
int garbage_collection_period = 50;
|
||||
|
||||
int opt;
|
||||
while ((opt = getopt(argc, argv, "Vhxtpsd:v:c:laf:Cbg:P:j")) != -1) {
|
||||
while ((opt = getopt(argc, argv, "Vhxtpsd:v:c:laf:Cbg:P:jz")) != -1) {
|
||||
switch (opt) {
|
||||
case 'V':
|
||||
versiondisplay();
|
||||
@@ -208,6 +209,9 @@ int main(int argc, char **argv) {
|
||||
case 'j':
|
||||
output_json = true;
|
||||
break;
|
||||
case 'z':
|
||||
sortPID = true;
|
||||
break;
|
||||
default:
|
||||
help(true);
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
@@ -59,6 +59,7 @@ bool tracemode = false;
|
||||
bool bughuntmode = false;
|
||||
// sort on sent or received?
|
||||
bool sortRecv = true;
|
||||
bool sortPID = false;
|
||||
bool showcommandline = false;
|
||||
bool showBasename = false;
|
||||
// viewMode: kb/s or total
|
||||
|
||||
Reference in New Issue
Block a user