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
ac38daf5
Commit
ac38daf5
authored
Jan 14, 2018
by
Hisham Muhammad
Browse files
Darwin: reorganize process reading loop
parent
66909bf5
Changes
2
Hide whitespace changes
Inline
Side-by-side
darwin/DarwinProcess.c
View file @
ac38daf5
...
@@ -60,11 +60,6 @@ void Process_delete(Object* cast) {
...
@@ -60,11 +60,6 @@ void Process_delete(Object* cast) {
free
(
this
);
free
(
this
);
}
}
bool
Process_isThread
(
Process
*
this
)
{
(
void
)
this
;
return
false
;
}
void
DarwinProcess_setStartTime
(
Process
*
proc
,
struct
extern_proc
*
ep
,
time_t
now
)
{
void
DarwinProcess_setStartTime
(
Process
*
proc
,
struct
extern_proc
*
ep
,
time_t
now
)
{
struct
tm
date
;
struct
tm
date
;
...
@@ -361,3 +356,12 @@ void DarwinProcess_scanThreads(DarwinProcess *dp) {
...
@@ -361,3 +356,12 @@ void DarwinProcess_scanThreads(DarwinProcess *dp) {
}
}
proc
->
state
=
state
;
proc
->
state
=
state
;
}
}
bool
Process_update
(
Process
*
proc
,
bool
isNew
,
ProcessList
*
pl
,
ProcessScanData
*
psd
)
{
DarwinProcess_setFromKInfoProc
(
&
proc
->
super
,
ps
->
kinfo
,
tv
.
tv_sec
,
preExisting
);
DarwinProcess_setFromLibprocPidinfo
(
proc
,
dpl
);
DarwinProcess_scanThreads
(
proc
);
if
(
isNew
)
{
proc
->
super
.
user
=
UsersTable_getRef
(
super
->
usersTable
,
proc
->
super
.
st_uid
);
}
}
darwin/DarwinProcessList.c
View file @
ac38daf5
...
@@ -36,6 +36,11 @@ typedef struct DarwinProcessList_ {
...
@@ -36,6 +36,11 @@ typedef struct DarwinProcessList_ {
uint64_t global_diff;
uint64_t global_diff;
} DarwinProcessList;
} DarwinProcessList;
typedef struct DarwinProcessScanData_ {
time_t nowSec;
struct kinfo_proc* kinfo;
} DarwinProcessScanData;
}*/
}*/
void
ProcessList_getHostInfo
(
host_basic_info_data_t
*
p
)
{
void
ProcessList_getHostInfo
(
host_basic_info_data_t
*
p
)
{
...
@@ -69,10 +74,10 @@ unsigned ProcessList_allocateCPULoadInfo(processor_cpu_load_info_t *p) {
...
@@ -69,10 +74,10 @@ unsigned ProcessList_allocateCPULoadInfo(processor_cpu_load_info_t *p) {
}
}
void
ProcessList_getVMStats
(
vm_statistics_t
p
)
{
void
ProcessList_getVMStats
(
vm_statistics_t
p
)
{
mach_msg_type_number_t
info_size
=
HOST_VM_INFO_COUNT
;
mach_msg_type_number_t
info_size
=
HOST_VM_INFO_COUNT
;
if
(
host_statistics
(
mach_host_self
(),
HOST_VM_INFO
,
(
host_info_t
)
p
,
&
info_size
)
!=
0
)
if
(
host_statistics
(
mach_host_self
(),
HOST_VM_INFO
,
(
host_info_t
)
p
,
&
info_size
)
!=
0
)
CRT_fatalError
(
"Unable to retrieve VM statistics
\n
"
);
CRT_fatalError
(
"Unable to retrieve VM statistics
\n
"
);
}
}
struct
kinfo_proc
*
ProcessList_getKInfoProcs
(
size_t
*
count
)
{
struct
kinfo_proc
*
ProcessList_getKInfoProcs
(
size_t
*
count
)
{
...
@@ -127,60 +132,40 @@ void ProcessList_delete(ProcessList* this) {
...
@@ -127,60 +132,40 @@ void ProcessList_delete(ProcessList* this) {
}
}
void
ProcessList_goThroughEntries
(
ProcessList
*
super
)
{
void
ProcessList_goThroughEntries
(
ProcessList
*
super
)
{
DarwinProcessList
*
dpl
=
(
DarwinProcessList
*
)
super
;
DarwinProcessList
*
dpl
=
(
DarwinProcessList
*
)
super
;
DarwinProcess
*
proc
;
struct
timeval
tv
;
struct
timeval
tv
;
gettimeofday
(
&
tv
,
NULL
);
/* Start processing time */
gettimeofday
(
&
tv
,
NULL
);
/* Start processing time */
/* Update the global data (CPU times and VM stats) */
/* Update the global data (CPU times and VM stats) */
ProcessList_freeCPULoadInfo
(
&
dpl
->
prev_load
);
ProcessList_freeCPULoadInfo
(
&
dpl
->
prev_load
);
dpl
->
prev_load
=
dpl
->
curr_load
;
dpl
->
prev_load
=
dpl
->
curr_load
;
ProcessList_allocateCPULoadInfo
(
&
dpl
->
curr_load
);
ProcessList_allocateCPULoadInfo
(
&
dpl
->
curr_load
);
ProcessList_getVMStats
(
&
dpl
->
vm_stats
);
ProcessList_getVMStats
(
&
dpl
->
vm_stats
);
/* Get the time difference */
/* Get the time difference */
dpl
->
global_diff
=
0
;
dpl
->
global_diff
=
0
;
for
(
int
i
=
0
;
i
<
dpl
->
super
.
cpuCount
;
++
i
)
{
for
(
int
i
=
0
;
i
<
dpl
->
super
.
cpuCount
;
++
i
)
{
for
(
size_t
j
=
0
;
j
<
CPU_STATE_MAX
;
++
j
)
{
for
(
size_t
j
=
0
;
j
<
CPU_STATE_MAX
;
++
j
)
{
dpl
->
global_diff
+=
dpl
->
curr_load
[
i
].
cpu_ticks
[
j
]
-
dpl
->
prev_load
[
i
].
cpu_ticks
[
j
];
dpl
->
global_diff
+=
dpl
->
curr_load
[
i
].
cpu_ticks
[
j
]
-
dpl
->
prev_load
[
i
].
cpu_ticks
[
j
];
}
}
/* Clear the thread counts */
super
->
kernelThreads
=
0
;
super
->
userlandThreads
=
0
;
super
->
totalTasks
=
0
;
super
->
runningTasks
=
0
;
/* We use kinfo_procs for initial data since :
*
* 1) They always succeed.
* 2) The contain the basic information.
*
* We attempt to fill-in additional information with libproc.
*/
size_t
count
;
struct
kinfo_proc
*
ps
=
ProcessList_getKInfoProcs
(
&
count
);
for
(
size_t
i
=
0
;
i
<
count
;
++
i
)
{
bool
preExisting
=
true
;
proc
=
(
DarwinProcess
*
)
ProcessList_getProcess
(
super
,
ps
[
i
].
kp_proc
.
p_pid
,
&
preExisting
,
(
Process_New
)
DarwinProcess_new
);
DarwinProcess_setFromKInfoProc
(
&
proc
->
super
,
&
ps
[
i
],
tv
.
tv_sec
,
preExisting
);
DarwinProcess_setFromLibprocPidinfo
(
proc
,
dpl
);
DarwinProcess_scanThreads
(
proc
);
super
->
totalTasks
+=
1
;
if
(
!
preExisting
)
{
proc
->
super
.
user
=
UsersTable_getRef
(
super
->
usersTable
,
proc
->
super
.
st_uid
);
ProcessList_add
(
super
,
&
proc
->
super
);
}
}
}
}
DarwinProcessScanData
psd
;
psd
.
nowSec
=
tv
.
tv_sec
;
free
(
ps
);
/* We use kinfo_procs for initial data since :
*
* 1) They always succeed.
* 2) The contain the basic information.
*
* We attempt to fill-in additional information with libproc.
*/
size_t
count
;
struct
kinfo_proc
*
ps
=
ProcessList_getKInfoProcs
(
&
count
);
for
(
size_t
i
=
0
;
i
<
count
;
++
i
)
{
psd
.
kinfo
=
ps
[
i
];
ProcessList_scanProcess
(
super
,
ps
[
i
].
kp_proc
.
p_pid
,
(
ProcessScanData
*
)
psd
);
}
free
(
ps
);
}
}
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