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