mirror of https://github.com/xzeldon/htop.git
Linux: update IO fields
- fix header width of IO_READ_RATE - save data in bytes (not kilobytes) to better compute rate - fix rate data: multiply with 1000 to compensate time difference in milliseconds - rename unit less variable now into realtimeMs - use Process_printBytes(..., data * pageSize, ...) instead of Process_printKBytes(..., data * pageSizeKB, ...) to avoid wrapper
This commit is contained in:
parent
b41e4d9c54
commit
323d7e73aa
|
@ -81,7 +81,7 @@ const ProcessFieldData Process_fields[LAST_PROCESSFIELD] = {
|
|||
[RBYTES] = { .name = "RBYTES", .title = " IO_R ", .description = "Bytes of read(2) I/O for the process", .flags = PROCESS_FLAG_IO, .defaultSortDesc = true, },
|
||||
[WBYTES] = { .name = "WBYTES", .title = " IO_W ", .description = "Bytes of write(2) I/O for the process", .flags = PROCESS_FLAG_IO, .defaultSortDesc = true, },
|
||||
[CNCLWB] = { .name = "CNCLWB", .title = " IO_C ", .description = "Bytes of cancelled write(2) I/O", .flags = PROCESS_FLAG_IO, .defaultSortDesc = true, },
|
||||
[IO_READ_RATE] = { .name = "IO_READ_RATE", .title = " DISK READ ", .description = "The I/O rate of read(2) in bytes per second for the process", .flags = PROCESS_FLAG_IO, .defaultSortDesc = true, },
|
||||
[IO_READ_RATE] = { .name = "IO_READ_RATE", .title = " DISK READ ", .description = "The I/O rate of read(2) in bytes per second for the process", .flags = PROCESS_FLAG_IO, .defaultSortDesc = true, },
|
||||
[IO_WRITE_RATE] = { .name = "IO_WRITE_RATE", .title = " DISK WRITE ", .description = "The I/O rate of write(2) in bytes per second for the process", .flags = PROCESS_FLAG_IO, .defaultSortDesc = true, },
|
||||
[IO_RATE] = { .name = "IO_RATE", .title = " DISK R/W ", .description = "Total I/O rate in bytes per second", .flags = PROCESS_FLAG_IO, .defaultSortDesc = true, },
|
||||
[CGROUP] = { .name = "CGROUP", .title = " CGROUP ", .description = "Which cgroup the process is in", .flags = PROCESS_FLAG_LINUX_CGROUP, },
|
||||
|
@ -611,19 +611,19 @@ static void LinuxProcess_writeField(const Process* this, RichString* str, Proces
|
|||
switch (field) {
|
||||
case CMINFLT: Process_printCount(str, lp->cminflt, coloring); return;
|
||||
case CMAJFLT: Process_printCount(str, lp->cmajflt, coloring); return;
|
||||
case M_DRS: Process_printKBytes(str, lp->m_drs * pageSizeKB, coloring); return;
|
||||
case M_DT: Process_printKBytes(str, lp->m_dt * pageSizeKB, coloring); return;
|
||||
case M_DRS: Process_printBytes(str, lp->m_drs * pageSize, coloring); return;
|
||||
case M_DT: Process_printBytes(str, lp->m_dt * pageSize, coloring); return;
|
||||
case M_LRS:
|
||||
if (lp->m_lrs) {
|
||||
Process_printKBytes(str, lp->m_lrs * pageSizeKB, coloring);
|
||||
Process_printBytes(str, lp->m_lrs * pageSize, coloring);
|
||||
return;
|
||||
}
|
||||
|
||||
attr = CRT_colors[PROCESS_SHADOW];
|
||||
xSnprintf(buffer, n, " N/A ");
|
||||
break;
|
||||
case M_TRS: Process_printKBytes(str, lp->m_trs * pageSizeKB, coloring); return;
|
||||
case M_SHARE: Process_printKBytes(str, lp->m_share * pageSizeKB, coloring); return;
|
||||
case M_TRS: Process_printBytes(str, lp->m_trs * pageSize, coloring); return;
|
||||
case M_SHARE: Process_printBytes(str, lp->m_share * pageSize, coloring); return;
|
||||
case M_PSS: Process_printKBytes(str, lp->m_pss, coloring); return;
|
||||
case M_SWAP: Process_printKBytes(str, lp->m_swap, coloring); return;
|
||||
case M_PSSWP: Process_printKBytes(str, lp->m_psswp, coloring); return;
|
||||
|
@ -631,13 +631,13 @@ static void LinuxProcess_writeField(const Process* this, RichString* str, Proces
|
|||
case STIME: Process_printTime(str, lp->stime, coloring); return;
|
||||
case CUTIME: Process_printTime(str, lp->cutime, coloring); return;
|
||||
case CSTIME: Process_printTime(str, lp->cstime, coloring); return;
|
||||
case RCHAR: Process_printKBytes(str, lp->io_rchar, coloring); return;
|
||||
case WCHAR: Process_printKBytes(str, lp->io_wchar, coloring); return;
|
||||
case RCHAR: Process_printBytes(str, lp->io_rchar, coloring); return;
|
||||
case WCHAR: Process_printBytes(str, lp->io_wchar, coloring); return;
|
||||
case SYSCR: Process_printCount(str, lp->io_syscr, coloring); return;
|
||||
case SYSCW: Process_printCount(str, lp->io_syscw, coloring); return;
|
||||
case RBYTES: Process_printKBytes(str, lp->io_read_bytes, coloring); return;
|
||||
case WBYTES: Process_printKBytes(str, lp->io_write_bytes, coloring); return;
|
||||
case CNCLWB: Process_printKBytes(str, lp->io_cancelled_write_bytes, coloring); return;
|
||||
case RBYTES: Process_printBytes(str, lp->io_read_bytes, coloring); return;
|
||||
case WBYTES: Process_printBytes(str, lp->io_write_bytes, coloring); return;
|
||||
case CNCLWB: Process_printBytes(str, lp->io_cancelled_write_bytes, coloring); return;
|
||||
case IO_READ_RATE: Process_printRate(str, lp->io_rate_read_bps, coloring); return;
|
||||
case IO_WRITE_RATE: Process_printRate(str, lp->io_rate_write_bps, coloring); return;
|
||||
case IO_RATE: {
|
||||
|
|
|
@ -82,10 +82,10 @@ typedef struct LinuxProcess_ {
|
|||
long m_lrs;
|
||||
long m_dt;
|
||||
|
||||
/* Data read (in kilobytes) */
|
||||
/* Data read (in bytes) */
|
||||
unsigned long long io_rchar;
|
||||
|
||||
/* Data written (in kilobytes) */
|
||||
/* Data written (in bytes) */
|
||||
unsigned long long io_wchar;
|
||||
|
||||
/* Number of read(2) syscalls */
|
||||
|
@ -94,20 +94,24 @@ typedef struct LinuxProcess_ {
|
|||
/* Number of write(2) syscalls */
|
||||
unsigned long long io_syscw;
|
||||
|
||||
/* Storage data read (in kilobytes) */
|
||||
/* Storage data read (in bytes) */
|
||||
unsigned long long io_read_bytes;
|
||||
|
||||
/* Storage data written (in kilobytes) */
|
||||
/* Storage data written (in bytes) */
|
||||
unsigned long long io_write_bytes;
|
||||
|
||||
/* Storage data cancelled (in kilobytes) */
|
||||
/* Storage data cancelled (in bytes) */
|
||||
unsigned long long io_cancelled_write_bytes;
|
||||
|
||||
/* Point in time of last io scan (in seconds elapsed since the Epoch) */
|
||||
unsigned long long io_last_scan_time;
|
||||
/* Point in time of last io scan (in milliseconds elapsed since the Epoch) */
|
||||
unsigned long long io_last_scan_time_ms;
|
||||
|
||||
/* Storage data read (in bytes per second) */
|
||||
double io_rate_read_bps;
|
||||
|
||||
/* Storage data written (in bytes per second) */
|
||||
double io_rate_write_bps;
|
||||
|
||||
#ifdef HAVE_OPENVZ
|
||||
char* ctid;
|
||||
pid_t vpid;
|
||||
|
|
|
@ -398,7 +398,7 @@ static bool LinuxProcessList_statProcessDir(Process* process, openat_arg_t procF
|
|||
return true;
|
||||
}
|
||||
|
||||
static void LinuxProcessList_readIoFile(LinuxProcess* process, openat_arg_t procFd, unsigned long long now) {
|
||||
static void LinuxProcessList_readIoFile(LinuxProcess* process, openat_arg_t procFd, unsigned long long realtimeMs) {
|
||||
char buffer[1024];
|
||||
ssize_t r = xReadfileat(procFd, "io", buffer, sizeof(buffer));
|
||||
if (r < 0) {
|
||||
|
@ -411,7 +411,7 @@ static void LinuxProcessList_readIoFile(LinuxProcess* process, openat_arg_t proc
|
|||
process->io_read_bytes = ULLONG_MAX;
|
||||
process->io_write_bytes = ULLONG_MAX;
|
||||
process->io_cancelled_write_bytes = ULLONG_MAX;
|
||||
process->io_last_scan_time = now;
|
||||
process->io_last_scan_time_ms = realtimeMs;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -423,18 +423,18 @@ static void LinuxProcessList_readIoFile(LinuxProcess* process, openat_arg_t proc
|
|||
switch (line[0]) {
|
||||
case 'r':
|
||||
if (line[1] == 'c' && String_startsWith(line + 2, "har: ")) {
|
||||
process->io_rchar = strtoull(line + 7, NULL, 10) / ONE_K;
|
||||
process->io_rchar = strtoull(line + 7, NULL, 10);
|
||||
} else if (String_startsWith(line + 1, "ead_bytes: ")) {
|
||||
process->io_read_bytes = strtoull(line + 12, NULL, 10) / ONE_K;
|
||||
process->io_rate_read_bps = ONE_K * (process->io_read_bytes - last_read) / (now - process->io_last_scan_time);
|
||||
process->io_read_bytes = strtoull(line + 12, NULL, 10);
|
||||
process->io_rate_read_bps = (process->io_read_bytes - last_read) * /*ms to s*/1000 / (realtimeMs - process->io_last_scan_time_ms);
|
||||
}
|
||||
break;
|
||||
case 'w':
|
||||
if (line[1] == 'c' && String_startsWith(line + 2, "har: ")) {
|
||||
process->io_wchar = strtoull(line + 7, NULL, 10) / ONE_K;
|
||||
process->io_wchar = strtoull(line + 7, NULL, 10);
|
||||
} else if (String_startsWith(line + 1, "rite_bytes: ")) {
|
||||
process->io_write_bytes = strtoull(line + 13, NULL, 10) / ONE_K;
|
||||
process->io_rate_write_bps = ONE_K * (process->io_write_bytes - last_write) / (now - process->io_last_scan_time);
|
||||
process->io_write_bytes = strtoull(line + 13, NULL, 10);
|
||||
process->io_rate_write_bps = (process->io_write_bytes - last_write) * /*ms to s*/1000 / (realtimeMs - process->io_last_scan_time_ms);
|
||||
}
|
||||
break;
|
||||
case 's':
|
||||
|
@ -446,12 +446,12 @@ static void LinuxProcessList_readIoFile(LinuxProcess* process, openat_arg_t proc
|
|||
break;
|
||||
case 'c':
|
||||
if (String_startsWith(line + 1, "ancelled_write_bytes: ")) {
|
||||
process->io_cancelled_write_bytes = strtoull(line + 23, NULL, 10) / ONE_K;
|
||||
process->io_cancelled_write_bytes = strtoull(line + 23, NULL, 10);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
process->io_last_scan_time = now;
|
||||
process->io_last_scan_time_ms = realtimeMs;
|
||||
}
|
||||
|
||||
typedef struct LibraryData_ {
|
||||
|
@ -594,7 +594,7 @@ static uint64_t LinuxProcessList_calcLibSize(openat_arg_t procFd) {
|
|||
return total_size / pageSize;
|
||||
}
|
||||
|
||||
static bool LinuxProcessList_readStatmFile(LinuxProcess* process, openat_arg_t procFd, bool performLookup, unsigned long long now) {
|
||||
static bool LinuxProcessList_readStatmFile(LinuxProcess* process, openat_arg_t procFd, bool performLookup, unsigned long long realtimeMs) {
|
||||
FILE* statmfile = fopenat(procFd, "statm", "r");
|
||||
if (!statmfile)
|
||||
return false;
|
||||
|
@ -618,12 +618,12 @@ static bool LinuxProcessList_readStatmFile(LinuxProcess* process, openat_arg_t p
|
|||
process->m_lrs = tmp_m_lrs;
|
||||
} else if (performLookup) {
|
||||
// Check if we really should recalculate the M_LRS value for this process
|
||||
uint64_t passedTimeInMs = now - process->last_mlrs_calctime;
|
||||
uint64_t passedTimeInMs = realtimeMs - process->last_mlrs_calctime;
|
||||
|
||||
uint64_t recheck = ((uint64_t)rand()) % 2048;
|
||||
|
||||
if(passedTimeInMs > 2000 || passedTimeInMs > recheck) {
|
||||
process->last_mlrs_calctime = now;
|
||||
process->last_mlrs_calctime = realtimeMs;
|
||||
process->m_lrs = LinuxProcessList_calcLibSize(procFd);
|
||||
}
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue