mirror of https://github.com/xzeldon/htop.git
nicer display for large numbers
This commit is contained in:
parent
6382e03b68
commit
9b3514062f
54
Process.c
54
Process.c
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
htop - Process.c
|
htop - Process.c
|
||||||
(C) 2004-2010 Hisham H. Muhammad
|
(C) 2004-2011 Hisham H. Muhammad
|
||||||
Released under the GNU GPL, see the COPYING file
|
Released under the GNU GPL, see the COPYING file
|
||||||
in the source distribution for its full text.
|
in the source distribution for its full text.
|
||||||
*/
|
*/
|
||||||
|
@ -209,7 +209,7 @@ const char *Process_fieldTitles[] = {
|
||||||
"- ", "- ", "- ", "- ", "- ", "- ", "- ",
|
"- ", "- ", "- ", "- ", "- ", "- ", "- ",
|
||||||
"- ", "- ", "- ", "CPU ", " VIRT ", " RES ", " SHR ",
|
"- ", "- ", "- ", "CPU ", " VIRT ", " RES ", " SHR ",
|
||||||
" CODE ", " DATA ", " LIB ", " DIRTY ", " UID ", "CPU% ", "MEM% ",
|
" CODE ", " DATA ", " LIB ", " DIRTY ", " UID ", "CPU% ", "MEM% ",
|
||||||
"USER ", " TIME+ ", "NLWP ", " TGID ",
|
"USER ", " TIME+ ", "NLWP ", " TGID ",
|
||||||
#ifdef HAVE_OPENVZ
|
#ifdef HAVE_OPENVZ
|
||||||
" CTID ", " VPID ",
|
" CTID ", " VPID ",
|
||||||
#endif
|
#endif
|
||||||
|
@ -217,7 +217,7 @@ const char *Process_fieldTitles[] = {
|
||||||
" VXID ",
|
" VXID ",
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_TASKSTATS
|
#ifdef HAVE_TASKSTATS
|
||||||
" RD_CHAR ", " WR_CHAR ", " RD_SYSC ", " WR_SYSC ", " IO_RBYTES ", " IO_WBYTES ", " IO_CANCEL ",
|
" RD_CHAR ", " WR_CHAR ", " RD_SYSC ", " WR_SYSC ", " IO_RBYTES ", " IO_WBYTES ", " IO_CANCEL ",
|
||||||
" IORR ", " IOWR ", " IO ",
|
" IORR ", " IOWR ", " IO ",
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_CGROUP
|
#ifdef HAVE_CGROUP
|
||||||
|
@ -232,7 +232,7 @@ static int Process_getuid = -1;
|
||||||
#define ONE_M (ONE_K * ONE_K)
|
#define ONE_M (ONE_K * ONE_K)
|
||||||
#define ONE_G (ONE_M * ONE_K)
|
#define ONE_G (ONE_M * ONE_K)
|
||||||
|
|
||||||
static void Process_printLargeNumber(Process* this, RichString* str, unsigned long number) {
|
static void Process_humanNumber(Process* this, RichString* str, unsigned long number) {
|
||||||
char buffer[11];
|
char buffer[11];
|
||||||
int len;
|
int len;
|
||||||
if(number >= (10 * ONE_M)) {
|
if(number >= (10 * ONE_M)) {
|
||||||
|
@ -261,6 +261,22 @@ static void Process_printLargeNumber(Process* this, RichString* str, unsigned lo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void Process_colorNumber(Process* this, RichString* str, unsigned long long number) {
|
||||||
|
char buffer[14];
|
||||||
|
if (number > 10000000000) {
|
||||||
|
snprintf(buffer, 13, "%11lld ", number / 1000);
|
||||||
|
RichString_appendn(str, CRT_colors[LARGE_NUMBER], buffer, 5);
|
||||||
|
RichString_appendn(str, CRT_colors[PROCESS_MEGABYTES], buffer+5, 3);
|
||||||
|
RichString_appendn(str, CRT_colors[PROCESS], buffer+8, 4);
|
||||||
|
} else {
|
||||||
|
snprintf(buffer, 13, "%11lld ", number);
|
||||||
|
RichString_appendn(str, CRT_colors[LARGE_NUMBER], buffer, 2);
|
||||||
|
RichString_appendn(str, CRT_colors[PROCESS_MEGABYTES], buffer+2, 3);
|
||||||
|
RichString_appendn(str, CRT_colors[PROCESS], buffer+5, 3);
|
||||||
|
RichString_appendn(str, CRT_colors[PROCESS_SHADOW], buffer+8, 4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static double jiffy = 0.0;
|
static double jiffy = 0.0;
|
||||||
|
|
||||||
static void Process_printTime(RichString* str, unsigned long long t) {
|
static void Process_printTime(RichString* str, unsigned long long t) {
|
||||||
|
@ -312,7 +328,7 @@ static inline void Process_outputRate(Process* this, RichString* str, int attr,
|
||||||
else if (rate <= 100)
|
else if (rate <= 100)
|
||||||
snprintf(buffer, n, "%5.1f ", rate);
|
snprintf(buffer, n, "%5.1f ", rate);
|
||||||
else {
|
else {
|
||||||
Process_printLargeNumber(this, str, rate);
|
Process_humanNumber(this, str, rate);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
RichString_append(str, attr, buffer);
|
RichString_append(str, attr, buffer);
|
||||||
|
@ -386,25 +402,25 @@ static void Process_writeField(Process* this, RichString* str, ProcessField fiel
|
||||||
: attr;
|
: attr;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case M_DRS: Process_printLargeNumber(this, str, this->m_drs * PAGE_SIZE_KB); return;
|
case M_DRS: Process_humanNumber(this, str, this->m_drs * PAGE_SIZE_KB); return;
|
||||||
case M_DT: Process_printLargeNumber(this, str, this->m_dt * PAGE_SIZE_KB); return;
|
case M_DT: Process_humanNumber(this, str, this->m_dt * PAGE_SIZE_KB); return;
|
||||||
case M_LRS: Process_printLargeNumber(this, str, this->m_lrs * PAGE_SIZE_KB); return;
|
case M_LRS: Process_humanNumber(this, str, this->m_lrs * PAGE_SIZE_KB); return;
|
||||||
case M_TRS: Process_printLargeNumber(this, str, this->m_trs * PAGE_SIZE_KB); return;
|
case M_TRS: Process_humanNumber(this, str, this->m_trs * PAGE_SIZE_KB); return;
|
||||||
case M_SIZE: Process_printLargeNumber(this, str, this->m_size * PAGE_SIZE_KB); return;
|
case M_SIZE: Process_humanNumber(this, str, this->m_size * PAGE_SIZE_KB); return;
|
||||||
case M_RESIDENT: Process_printLargeNumber(this, str, this->m_resident * PAGE_SIZE_KB); return;
|
case M_RESIDENT: Process_humanNumber(this, str, this->m_resident * PAGE_SIZE_KB); return;
|
||||||
case M_SHARE: Process_printLargeNumber(this, str, this->m_share * PAGE_SIZE_KB); return;
|
case M_SHARE: Process_humanNumber(this, str, this->m_share * PAGE_SIZE_KB); return;
|
||||||
case ST_UID: snprintf(buffer, n, "%4d ", this->st_uid); break;
|
case ST_UID: snprintf(buffer, n, "%4d ", this->st_uid); break;
|
||||||
case USER: {
|
case USER: {
|
||||||
if (Process_getuid != (int) this->st_uid)
|
if (Process_getuid != (int) this->st_uid)
|
||||||
attr = CRT_colors[PROCESS_SHADOW];
|
attr = CRT_colors[PROCESS_SHADOW];
|
||||||
if (this->user) {
|
if (this->user) {
|
||||||
snprintf(buffer, n, "%-8s ", this->user);
|
snprintf(buffer, n, "%-9s ", this->user);
|
||||||
} else {
|
} else {
|
||||||
snprintf(buffer, n, "%-8d ", this->st_uid);
|
snprintf(buffer, n, "%-9d ", this->st_uid);
|
||||||
}
|
}
|
||||||
if (buffer[8] != '\0') {
|
if (buffer[9] != '\0') {
|
||||||
buffer[8] = ' ';
|
buffer[9] = ' ';
|
||||||
buffer[9] = '\0';
|
buffer[10] = '\0';
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -444,8 +460,8 @@ static void Process_writeField(Process* this, RichString* str, ProcessField fiel
|
||||||
case WCHAR: snprintf(buffer, n, "%10llu ", this->io_wchar); break;
|
case WCHAR: snprintf(buffer, n, "%10llu ", this->io_wchar); break;
|
||||||
case SYSCR: snprintf(buffer, n, "%10llu ", this->io_syscr); break;
|
case SYSCR: snprintf(buffer, n, "%10llu ", this->io_syscr); break;
|
||||||
case SYSCW: snprintf(buffer, n, "%10llu ", this->io_syscw); break;
|
case SYSCW: snprintf(buffer, n, "%10llu ", this->io_syscw); break;
|
||||||
case RBYTES: snprintf(buffer, n, "%10llu ", this->io_read_bytes); break;
|
case RBYTES: Process_colorNumber(this, str, this->io_read_bytes); return;
|
||||||
case WBYTES: snprintf(buffer, n, "%10llu ", this->io_write_bytes); break;
|
case WBYTES: Process_colorNumber(this, str, this->io_write_bytes); return;
|
||||||
case CNCLWB: snprintf(buffer, n, "%10llu ", this->io_cancelled_write_bytes); break;
|
case CNCLWB: snprintf(buffer, n, "%10llu ", this->io_cancelled_write_bytes); break;
|
||||||
case IO_READ_RATE: Process_outputRate(this, str, attr, buffer, n, this->io_rate_read_bps); return;
|
case IO_READ_RATE: Process_outputRate(this, str, attr, buffer, n, this->io_rate_read_bps); return;
|
||||||
case IO_WRITE_RATE: Process_outputRate(this, str, attr, buffer, n, this->io_rate_write_bps); return;
|
case IO_WRITE_RATE: Process_outputRate(this, str, attr, buffer, n, this->io_rate_write_bps); return;
|
||||||
|
|
Loading…
Reference in New Issue