Add BPS viewMode

This commit is contained in:
2025-08-05 05:32:38 +02:00
parent 8b6c7c7bc8
commit 7ea25e917f
6 changed files with 17 additions and 3 deletions

View File

@@ -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);
}

View File

@@ -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

View File

@@ -70,6 +70,7 @@ enum {
VIEWMODE_TOTAL_MB,
VIEWMODE_MBPS,
VIEWMODE_GBPS,
VIEWMODE_BPS,
VIEWMODE_COUNT
};

View File

@@ -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;

View File

@@ -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);