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
80f594f3
Commit
80f594f3
authored
Dec 13, 2015
by
Martin "eto" Misuth
Browse files
added CPU% for processes in process list
parent
c2769985
Changes
1
Hide whitespace changes
Inline
Side-by-side
freebsd/FreeBSDProcessList.c
View file @
80f594f3
...
...
@@ -63,7 +63,7 @@ static int MIB_kern_cp_time[2];
static
int
MIB_kern_cp_times
[
2
];
static
int
pageSizeKb
;
static
int
kernelFScale
;
ProcessList
*
ProcessList_new
(
UsersTable
*
usersTable
,
Hashtable
*
pidWhiteList
,
uid_t
userId
)
{
FreeBSDProcessList
*
fpl
=
calloc
(
1
,
sizeof
(
FreeBSDProcessList
));
...
...
@@ -79,6 +79,12 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, ui
fpl
->
kd
=
kvm_open
(
NULL
,
"/dev/null"
,
NULL
,
0
,
NULL
);
assert
(
fpl
->
kd
);
size_t
sizeof_kernelFScale
=
sizeof
(
kernelFScale
);
if
(
sysctlbyname
(
"kern.fscale"
,
&
kernelFScale
,
&
sizeof_kernelFScale
,
NULL
,
0
)
==
-
1
)
{
//sane default on x86 machines, in case this sysctl call failed
kernelFScale
=
2048
;
}
int
smp
=
0
;
size_t
sizeof_smp
=
sizeof
(
smp
);
...
...
@@ -322,6 +328,7 @@ void ProcessList_goThroughEntries(ProcessList* this) {
FreeBSDProcessList_scanMemoryInfo
(
this
);
FreeBSDProcessList_scanCPUTime
(
this
);
int
cpus
=
this
->
cpuCount
;
int
count
=
0
;
struct
kinfo_proc
*
kprocs
=
kvm_getprocs
(
fpl
->
kd
,
KERN_PROC_ALL
,
0
,
&
count
);
...
...
@@ -379,6 +386,15 @@ void ProcessList_goThroughEntries(ProcessList* this) {
proc
->
nlwp
=
kproc
->
ki_numthreads
;
proc
->
time
=
(
kproc
->
ki_runtime
+
5000
)
/
10000
;
proc
->
percent_cpu
=
100
.
0
*
((
double
)
kproc
->
ki_pctcpu
/
(
double
)
kernelFScale
);
if
(
cpus
>
1
)
{
proc
->
percent_cpu
=
proc
->
percent_cpu
/
(
double
)
cpus
;
}
if
(
proc
->
percent_cpu
>=
99
.
8
)
{
// don't break formatting
proc
->
percent_cpu
=
99
.
8
;
}
proc
->
priority
=
kproc
->
ki_pri
.
pri_level
-
PZERO
;
if
(
strcmp
(
"intr"
,
kproc
->
ki_comm
)
==
0
&&
kproc
->
ki_flag
&
P_SYSTEM
)
{
...
...
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