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
|
@ -611,19 +611,19 @@ static void LinuxProcess_writeField(const Process* this, RichString* str, Proces
|
||||||
switch (field) {
|
switch (field) {
|
||||||
case CMINFLT: Process_printCount(str, lp->cminflt, coloring); return;
|
case CMINFLT: Process_printCount(str, lp->cminflt, coloring); return;
|
||||||
case CMAJFLT: Process_printCount(str, lp->cmajflt, 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_DRS: Process_printBytes(str, lp->m_drs * pageSize, coloring); return;
|
||||||
case M_DT: Process_printKBytes(str, lp->m_dt * pageSizeKB, coloring); return;
|
case M_DT: Process_printBytes(str, lp->m_dt * pageSize, coloring); return;
|
||||||
case M_LRS:
|
case M_LRS:
|
||||||
if (lp->m_lrs) {
|
if (lp->m_lrs) {
|
||||||
Process_printKBytes(str, lp->m_lrs * pageSizeKB, coloring);
|
Process_printBytes(str, lp->m_lrs * pageSize, coloring);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
attr = CRT_colors[PROCESS_SHADOW];
|
attr = CRT_colors[PROCESS_SHADOW];
|
||||||
xSnprintf(buffer, n, " N/A ");
|
xSnprintf(buffer, n, " N/A ");
|
||||||
break;
|
break;
|
||||||
case M_TRS: Process_printKBytes(str, lp->m_trs * pageSizeKB, coloring); return;
|
case M_TRS: Process_printBytes(str, lp->m_trs * pageSize, coloring); return;
|
||||||
case M_SHARE: Process_printKBytes(str, lp->m_share * pageSizeKB, 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_PSS: Process_printKBytes(str, lp->m_pss, coloring); return;
|
||||||
case M_SWAP: Process_printKBytes(str, lp->m_swap, coloring); return;
|
case M_SWAP: Process_printKBytes(str, lp->m_swap, coloring); return;
|
||||||
case M_PSSWP: Process_printKBytes(str, lp->m_psswp, 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 STIME: Process_printTime(str, lp->stime, coloring); return;
|
||||||
case CUTIME: Process_printTime(str, lp->cutime, coloring); return;
|
case CUTIME: Process_printTime(str, lp->cutime, coloring); return;
|
||||||
case CSTIME: Process_printTime(str, lp->cstime, coloring); return;
|
case CSTIME: Process_printTime(str, lp->cstime, coloring); return;
|
||||||
case RCHAR: Process_printKBytes(str, lp->io_rchar, coloring); return;
|
case RCHAR: Process_printBytes(str, lp->io_rchar, coloring); return;
|
||||||
case WCHAR: Process_printKBytes(str, lp->io_wchar, coloring); return;
|
case WCHAR: Process_printBytes(str, lp->io_wchar, coloring); return;
|
||||||
case SYSCR: Process_printCount(str, lp->io_syscr, coloring); return;
|
case SYSCR: Process_printCount(str, lp->io_syscr, coloring); return;
|
||||||
case SYSCW: Process_printCount(str, lp->io_syscw, coloring); return;
|
case SYSCW: Process_printCount(str, lp->io_syscw, coloring); return;
|
||||||
case RBYTES: Process_printKBytes(str, lp->io_read_bytes, coloring); return;
|
case RBYTES: Process_printBytes(str, lp->io_read_bytes, coloring); return;
|
||||||
case WBYTES: Process_printKBytes(str, lp->io_write_bytes, coloring); return;
|
case WBYTES: Process_printBytes(str, lp->io_write_bytes, coloring); return;
|
||||||
case CNCLWB: Process_printKBytes(str, lp->io_cancelled_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_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_WRITE_RATE: Process_printRate(str, lp->io_rate_write_bps, coloring); return;
|
||||||
case IO_RATE: {
|
case IO_RATE: {
|
||||||
|
|
|
@ -82,10 +82,10 @@ typedef struct LinuxProcess_ {
|
||||||
long m_lrs;
|
long m_lrs;
|
||||||
long m_dt;
|
long m_dt;
|
||||||
|
|
||||||
/* Data read (in kilobytes) */
|
/* Data read (in bytes) */
|
||||||
unsigned long long io_rchar;
|
unsigned long long io_rchar;
|
||||||
|
|
||||||
/* Data written (in kilobytes) */
|
/* Data written (in bytes) */
|
||||||
unsigned long long io_wchar;
|
unsigned long long io_wchar;
|
||||||
|
|
||||||
/* Number of read(2) syscalls */
|
/* Number of read(2) syscalls */
|
||||||
|
@ -94,20 +94,24 @@ typedef struct LinuxProcess_ {
|
||||||
/* Number of write(2) syscalls */
|
/* Number of write(2) syscalls */
|
||||||
unsigned long long io_syscw;
|
unsigned long long io_syscw;
|
||||||
|
|
||||||
/* Storage data read (in kilobytes) */
|
/* Storage data read (in bytes) */
|
||||||
unsigned long long io_read_bytes;
|
unsigned long long io_read_bytes;
|
||||||
|
|
||||||
/* Storage data written (in kilobytes) */
|
/* Storage data written (in bytes) */
|
||||||
unsigned long long io_write_bytes;
|
unsigned long long io_write_bytes;
|
||||||
|
|
||||||
/* Storage data cancelled (in kilobytes) */
|
/* Storage data cancelled (in bytes) */
|
||||||
unsigned long long io_cancelled_write_bytes;
|
unsigned long long io_cancelled_write_bytes;
|
||||||
|
|
||||||
/* Point in time of last io scan (in seconds elapsed since the Epoch) */
|
/* Point in time of last io scan (in milliseconds elapsed since the Epoch) */
|
||||||
unsigned long long io_last_scan_time;
|
unsigned long long io_last_scan_time_ms;
|
||||||
|
|
||||||
|
/* Storage data read (in bytes per second) */
|
||||||
double io_rate_read_bps;
|
double io_rate_read_bps;
|
||||||
|
|
||||||
|
/* Storage data written (in bytes per second) */
|
||||||
double io_rate_write_bps;
|
double io_rate_write_bps;
|
||||||
|
|
||||||
#ifdef HAVE_OPENVZ
|
#ifdef HAVE_OPENVZ
|
||||||
char* ctid;
|
char* ctid;
|
||||||
pid_t vpid;
|
pid_t vpid;
|
||||||
|
|
|
@ -398,7 +398,7 @@ static bool LinuxProcessList_statProcessDir(Process* process, openat_arg_t procF
|
||||||
return true;
|
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];
|
char buffer[1024];
|
||||||
ssize_t r = xReadfileat(procFd, "io", buffer, sizeof(buffer));
|
ssize_t r = xReadfileat(procFd, "io", buffer, sizeof(buffer));
|
||||||
if (r < 0) {
|
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_read_bytes = ULLONG_MAX;
|
||||||
process->io_write_bytes = ULLONG_MAX;
|
process->io_write_bytes = ULLONG_MAX;
|
||||||
process->io_cancelled_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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -423,18 +423,18 @@ static void LinuxProcessList_readIoFile(LinuxProcess* process, openat_arg_t proc
|
||||||
switch (line[0]) {
|
switch (line[0]) {
|
||||||
case 'r':
|
case 'r':
|
||||||
if (line[1] == 'c' && String_startsWith(line + 2, "har: ")) {
|
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: ")) {
|
} else if (String_startsWith(line + 1, "ead_bytes: ")) {
|
||||||
process->io_read_bytes = strtoull(line + 12, NULL, 10) / ONE_K;
|
process->io_read_bytes = strtoull(line + 12, NULL, 10);
|
||||||
process->io_rate_read_bps = ONE_K * (process->io_read_bytes - last_read) / (now - process->io_last_scan_time);
|
process->io_rate_read_bps = (process->io_read_bytes - last_read) * /*ms to s*/1000 / (realtimeMs - process->io_last_scan_time_ms);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'w':
|
case 'w':
|
||||||
if (line[1] == 'c' && String_startsWith(line + 2, "har: ")) {
|
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: ")) {
|
} else if (String_startsWith(line + 1, "rite_bytes: ")) {
|
||||||
process->io_write_bytes = strtoull(line + 13, NULL, 10) / ONE_K;
|
process->io_write_bytes = strtoull(line + 13, NULL, 10);
|
||||||
process->io_rate_write_bps = ONE_K * (process->io_write_bytes - last_write) / (now - process->io_last_scan_time);
|
process->io_rate_write_bps = (process->io_write_bytes - last_write) * /*ms to s*/1000 / (realtimeMs - process->io_last_scan_time_ms);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
|
@ -446,12 +446,12 @@ static void LinuxProcessList_readIoFile(LinuxProcess* process, openat_arg_t proc
|
||||||
break;
|
break;
|
||||||
case 'c':
|
case 'c':
|
||||||
if (String_startsWith(line + 1, "ancelled_write_bytes: ")) {
|
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_ {
|
typedef struct LibraryData_ {
|
||||||
|
@ -594,7 +594,7 @@ static uint64_t LinuxProcessList_calcLibSize(openat_arg_t procFd) {
|
||||||
return total_size / pageSize;
|
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");
|
FILE* statmfile = fopenat(procFd, "statm", "r");
|
||||||
if (!statmfile)
|
if (!statmfile)
|
||||||
return false;
|
return false;
|
||||||
|
@ -618,12 +618,12 @@ static bool LinuxProcessList_readStatmFile(LinuxProcess* process, openat_arg_t p
|
||||||
process->m_lrs = tmp_m_lrs;
|
process->m_lrs = tmp_m_lrs;
|
||||||
} else if (performLookup) {
|
} else if (performLookup) {
|
||||||
// Check if we really should recalculate the M_LRS value for this process
|
// 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;
|
uint64_t recheck = ((uint64_t)rand()) % 2048;
|
||||||
|
|
||||||
if(passedTimeInMs > 2000 || passedTimeInMs > recheck) {
|
if(passedTimeInMs > 2000 || passedTimeInMs > recheck) {
|
||||||
process->last_mlrs_calctime = now;
|
process->last_mlrs_calctime = realtimeMs;
|
||||||
process->m_lrs = LinuxProcessList_calcLibSize(procFd);
|
process->m_lrs = LinuxProcessList_calcLibSize(procFd);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue