diff --git a/doc/nethogs.8 b/doc/nethogs.8 index 1c33a81..928fad7 100644 --- a/doc/nethogs.8 +++ b/doc/nethogs.8 @@ -41,7 +41,7 @@ bughunt mode - implies tracemode. delay for update refresh rate in seconds. default is 1. .TP \fB-v\fP -view mode (0 = kB/s, 1 = total kB, 2 = total bytes, 3 = total MB, 4 = MB/s, 5 = GB/s). default is 0. +view mode (0 = kB/s, 1 = total kB, 2 = total bytes, 3 = total MB, 4 = MB/s, 5 = GB/s, 6 = B/s). default is 0. kB: 2e10 bytes, MB: 2e20 bytes, GB: 2e30 bytes .TP diff --git a/src/cui.cpp b/src/cui.cpp index 73eeae0..e975d2f 100644 --- a/src/cui.cpp +++ b/src/cui.cpp @@ -70,7 +70,7 @@ const char *COLUMN_FORMAT_RECEIVED = "%11.3f"; // All descriptions are padded to 6 characters in length with spaces const char *const desc_view_mode[VIEWMODE_COUNT] = { - "kB/s ", "kB ", "bytes ", "MB ", "MB/s ", "GB/s "}; + "kB/s ", "kB ", "bytes ", "MB ", "MB/s ", "GB/s ", "B/s "}; constexpr char FILE_SEPARATOR = '/'; @@ -503,6 +503,8 @@ void do_refresh() { curproc->getVal()->gettotalmb(&value_recv, &value_sent); } else if (viewMode == VIEWMODE_TOTAL_B) { curproc->getVal()->gettotalb(&value_recv, &value_sent); + } else if (viewMode == VIEWMODE_BPS) { + curproc->getVal()->getbps(&value_recv, &value_sent); } else { forceExit(false, "Invalid viewMode: %d", viewMode); } diff --git a/src/main.cpp b/src/main.cpp index 4c77e27..5cc9316 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -39,7 +39,7 @@ static void help(bool iserror) { output << " -d : delay for update refresh rate in seconds. default " "is 1.\n"; output << " -v : view mode (0 = kB/s, 1 = total kB, 2 = " - "total bytes, 3 = total MB, 4 = MB/s, 5 = GB/s). default is 0.\n"; + "total bytes, 3 = total MB, 4 = MB/s, 5 = GB/s, 6 = B/s). default is 0.\n"; output << " -c : number of updates. default is 0 (unlimited).\n"; output << " -t : tracemode.\n"; // output << " -f : format of packets on interface, default is diff --git a/src/nethogs.h b/src/nethogs.h index 3e5829a..dff4477 100644 --- a/src/nethogs.h +++ b/src/nethogs.h @@ -70,6 +70,7 @@ enum { VIEWMODE_TOTAL_MB, VIEWMODE_MBPS, VIEWMODE_GBPS, + VIEWMODE_BPS, VIEWMODE_COUNT }; diff --git a/src/process.cpp b/src/process.cpp index bf61efd..5f42d26 100644 --- a/src/process.cpp +++ b/src/process.cpp @@ -127,6 +127,16 @@ static void sum_active_connections(Process *process_ptr, u_int64_t &sum_sent, } } +/** Get the b/s values for this process */ +void Process::getbps(float *recvd, float *sent) { + u_int64_t sum_sent = 0, sum_recv = 0; + + sum_active_connections(this, sum_sent, sum_recv); + *recvd = sum_recv; + *sent = sum_sent; +} + + /** Get the kb/s values for this process */ void Process::getkbps(float *recvd, float *sent) { u_int64_t sum_sent = 0, sum_recv = 0; diff --git a/src/process.h b/src/process.h index f20638a..7130bb1 100644 --- a/src/process.h +++ b/src/process.h @@ -91,6 +91,7 @@ public: int getLastPacket(); void gettotal(u_int64_t *recvd, u_int64_t *sent); + void getbps(float *recvd, float *sent); void getkbps(float *recvd, float *sent); void getmbps(float *recvd, float *sent); void getgbps(float *recvd, float *sent);