Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
htop
Commits
9b351406
Commit
9b351406
authored
May 26, 2011
by
Hisham Muhammad
Browse files
nicer display for large numbers
parent
6382e03b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Process.c
View file @
9b351406
/*
htop - Process.c
(C) 2004-201
0
Hisham H. Muhammad
(C) 2004-201
1
Hisham H. Muhammad
Released under the GNU GPL, see the COPYING file
in the source distribution for its full text.
*/
...
...
@@ -209,7 +209,7 @@ const char *Process_fieldTitles[] = {
"- "
,
"- "
,
"- "
,
"- "
,
"- "
,
"- "
,
"- "
,
"- "
,
"- "
,
"- "
,
"CPU "
,
" VIRT "
,
" RES "
,
" SHR "
,
" CODE "
,
" DATA "
,
" LIB "
,
" DIRTY "
,
" UID "
,
"CPU% "
,
"MEM% "
,
"USER "
,
" TIME+ "
,
"NLWP "
,
" TGID "
,
"USER
"
,
" TIME+ "
,
"NLWP "
,
" TGID "
,
#ifdef HAVE_OPENVZ
" CTID "
,
" VPID "
,
#endif
...
...
@@ -217,7 +217,7 @@ const char *Process_fieldTitles[] = {
" VXID "
,
#endif
#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 "
,
#endif
#ifdef HAVE_CGROUP
...
...
@@ -232,7 +232,7 @@ static int Process_getuid = -1;
#define ONE_M (ONE_K * ONE_K)
#define ONE_G (ONE_M * ONE_K)
static
void
Process_
printLarge
Number
(
Process
*
this
,
RichString
*
str
,
unsigned
long
number
)
{
static
void
Process_
human
Number
(
Process
*
this
,
RichString
*
str
,
unsigned
long
number
)
{
char
buffer
[
11
];
int
len
;
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
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
)
snprintf
(
buffer
,
n
,
"%5.1f "
,
rate
);
else
{
Process_
printLarge
Number
(
this
,
str
,
rate
);
Process_
human
Number
(
this
,
str
,
rate
);
return
;
}
RichString_append
(
str
,
attr
,
buffer
);
...
...
@@ -386,25 +402,25 @@ static void Process_writeField(Process* this, RichString* str, ProcessField fiel
:
attr
;
break
;
}
case
M_DRS
:
Process_
printLarge
Number
(
this
,
str
,
this
->
m_drs
*
PAGE_SIZE_KB
);
return
;
case
M_DT
:
Process_
printLarge
Number
(
this
,
str
,
this
->
m_dt
*
PAGE_SIZE_KB
);
return
;
case
M_LRS
:
Process_
printLarge
Number
(
this
,
str
,
this
->
m_lrs
*
PAGE_SIZE_KB
);
return
;
case
M_TRS
:
Process_
printLarge
Number
(
this
,
str
,
this
->
m_trs
*
PAGE_SIZE_KB
);
return
;
case
M_SIZE
:
Process_
printLarge
Number
(
this
,
str
,
this
->
m_size
*
PAGE_SIZE_KB
);
return
;
case
M_RESIDENT
:
Process_
printLarge
Number
(
this
,
str
,
this
->
m_resident
*
PAGE_SIZE_KB
);
return
;
case
M_SHARE
:
Process_
printLarge
Number
(
this
,
str
,
this
->
m_share
*
PAGE_SIZE_KB
);
return
;
case
M_DRS
:
Process_
human
Number
(
this
,
str
,
this
->
m_drs
*
PAGE_SIZE_KB
);
return
;
case
M_DT
:
Process_
human
Number
(
this
,
str
,
this
->
m_dt
*
PAGE_SIZE_KB
);
return
;
case
M_LRS
:
Process_
human
Number
(
this
,
str
,
this
->
m_lrs
*
PAGE_SIZE_KB
);
return
;
case
M_TRS
:
Process_
human
Number
(
this
,
str
,
this
->
m_trs
*
PAGE_SIZE_KB
);
return
;
case
M_SIZE
:
Process_
human
Number
(
this
,
str
,
this
->
m_size
*
PAGE_SIZE_KB
);
return
;
case
M_RESIDENT
:
Process_
human
Number
(
this
,
str
,
this
->
m_resident
*
PAGE_SIZE_KB
);
return
;
case
M_SHARE
:
Process_
human
Number
(
this
,
str
,
this
->
m_share
*
PAGE_SIZE_KB
);
return
;
case
ST_UID
:
snprintf
(
buffer
,
n
,
"%4d "
,
this
->
st_uid
);
break
;
case
USER
:
{
if
(
Process_getuid
!=
(
int
)
this
->
st_uid
)
attr
=
CRT_colors
[
PROCESS_SHADOW
];
if
(
this
->
user
)
{
snprintf
(
buffer
,
n
,
"%-
8
s "
,
this
->
user
);
snprintf
(
buffer
,
n
,
"%-
9
s "
,
this
->
user
);
}
else
{
snprintf
(
buffer
,
n
,
"%-
8
d "
,
this
->
st_uid
);
snprintf
(
buffer
,
n
,
"%-
9
d "
,
this
->
st_uid
);
}
if
(
buffer
[
8
]
!=
'\0'
)
{
buffer
[
8
]
=
' '
;
buffer
[
9
]
=
'\0'
;
if
(
buffer
[
9
]
!=
'\0'
)
{
buffer
[
9
]
=
' '
;
buffer
[
10
]
=
'\0'
;
}
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
SYSCR
:
snprintf
(
buffer
,
n
,
"%10llu "
,
this
->
io_syscr
);
break
;
case
SYSCW
:
snprintf
(
buffer
,
n
,
"%10llu "
,
this
->
io_syscw
);
break
;
case
RBYTES
:
snprintf
(
buffer
,
n
,
"%10llu "
,
this
->
io_read_bytes
);
b
re
ak
;
case
WBYTES
:
snprintf
(
buffer
,
n
,
"%10llu "
,
this
->
io_write_bytes
);
b
re
ak
;
case
RBYTES
:
Process_colorNumber
(
this
,
str
,
this
->
io_read_bytes
);
re
turn
;
case
WBYTES
:
Process_colorNumber
(
this
,
str
,
this
->
io_write_bytes
);
re
turn
;
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_WRITE_RATE
:
Process_outputRate
(
this
,
str
,
attr
,
buffer
,
n
,
this
->
io_rate_write_bps
);
return
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment