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
6463ea29
Commit
6463ea29
authored
Jul 13, 2015
by
David Hunt
Committed by
Hisham Muhammad
Aug 19, 2015
Browse files
Fixed CPU updating
parent
7f3faa27
Changes
3
Hide whitespace changes
Inline
Side-by-side
darwin/DarwinProcessList.c
View file @
6463ea29
...
...
@@ -25,7 +25,8 @@ typedef struct DarwinProcessList_ {
ProcessList super;
host_basic_info_data_t host_info;
processor_cpu_load_info_t cpu_load;
processor_cpu_load_info_t prev_load;
processor_cpu_load_info_t curr_load;
} DarwinProcessList;
}*/
...
...
@@ -39,17 +40,21 @@ void ProcessList_getHostInfo(host_basic_info_data_t *p) {
}
}
unsigned
ProcessList_updateCPULoadInfo
(
processor_cpu_load_info_t
*
p
)
{
mach_msg_type_number_t
info_size
=
sizeof
(
processor_cpu_load_info_t
);
unsigned
cpu_count
;
if
(
NULL
!=
p
)
{
void
ProcessList_freeCPULoadInfo
(
processor_cpu_load_info_t
*
p
)
{
if
(
NULL
!=
p
&&
NULL
!=
*
p
)
{
if
(
0
!=
munmap
(
*
p
,
vm_page_size
))
{
fprintf
(
stderr
,
"Unable to free old CPU load information
\n
"
);
exit
(
8
);
}
}
*
p
=
NULL
;
}
unsigned
ProcessList_allocateCPULoadInfo
(
processor_cpu_load_info_t
*
p
)
{
mach_msg_type_number_t
info_size
=
sizeof
(
processor_cpu_load_info_t
);
unsigned
cpu_count
;
if
(
0
!=
host_processor_info
(
mach_host_self
(),
PROCESSOR_CPU_LOAD_INFO
,
&
cpu_count
,
(
processor_info_array_t
*
)
p
,
&
info_size
))
{
fprintf
(
stderr
,
"Unable to retrieve CPU info
\n
"
);
exit
(
4
);
...
...
@@ -95,9 +100,9 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, ui
ProcessList_init
(
&
this
->
super
,
Class
(
Process
),
usersTable
,
pidWhiteList
,
userId
);
/* Initialize the previous information */
this
->
cpu_load
=
NULL
;
this
->
super
.
cpuCount
=
ProcessList_updateCPULoadInfo
(
&
this
->
cpu_load
);
this
->
super
.
cpuCount
=
ProcessList_allocateCPULoadInfo
(
&
this
->
prev_load
);
ProcessList_getHostInfo
(
&
this
->
host_info
);
ProcessList_allocateCPULoadInfo
(
&
this
->
curr_load
);
return
&
this
->
super
;
}
...
...
@@ -118,7 +123,9 @@ void ProcessList_goThroughEntries(ProcessList* super) {
gettimeofday
(
&
tv
,
NULL
);
/* Start processing time */
/* Update the global data (CPU times) */
ProcessList_updateCPULoadInfo
(
&
dpl
->
cpu_load
);
ProcessList_freeCPULoadInfo
(
&
dpl
->
prev_load
);
dpl
->
prev_load
=
dpl
->
curr_load
;
ProcessList_allocateCPULoadInfo
(
&
dpl
->
curr_load
);
/* We use kinfo_procs for initial data since :
*
...
...
darwin/DarwinProcessList.h
View file @
6463ea29
...
...
@@ -16,13 +16,16 @@ typedef struct DarwinProcessList_ {
ProcessList
super
;
host_basic_info_data_t
host_info
;
processor_cpu_load_info_t
cpu_load
;
processor_cpu_load_info_t
prev_load
;
processor_cpu_load_info_t
curr_load
;
}
DarwinProcessList
;
void
ProcessList_getHostInfo
(
host_basic_info_data_t
*
p
);
unsigned
ProcessList_updateCPULoadInfo
(
processor_cpu_load_info_t
*
p
);
void
ProcessList_freeCPULoadInfo
(
processor_cpu_load_info_t
*
p
);
unsigned
ProcessList_allocateCPULoadInfo
(
processor_cpu_load_info_t
*
p
);
struct
kinfo_proc
*
ProcessList_getKInfoProcs
(
size_t
*
count
);
...
...
darwin/Platform.c
View file @
6463ea29
...
...
@@ -139,17 +139,21 @@ double Platform_setCPUValues(Meter* mtr, int cpu) {
static
const
int
CPU_METER_KERNEL
=
2
;
DarwinProcessList
*
dpl
=
(
DarwinProcessList
*
)
mtr
->
pl
;
processor_cpu_load_info_t
ticks
=
&
dpl
->
cpu_load
[
cpu
-
1
];
processor_cpu_load_info_t
prev
=
&
dpl
->
prev_load
[
cpu
-
1
];
processor_cpu_load_info_t
curr
=
&
dpl
->
curr_load
[
cpu
-
1
];
double
total
=
0
;
/* Take the sums */
for
(
size_t
i
=
0
;
i
<
CPU_STATE_MAX
;
++
i
)
{
total
+=
(
double
)
ticks
->
cpu_ticks
[
i
];
total
+=
(
double
)
curr
->
cpu_ticks
[
i
]
-
(
double
)
prev
->
cpu_ticks
[
i
];
}
mtr
->
values
[
CPU_METER_NICE
]
=
(
double
)
ticks
->
cpu_ticks
[
CPU_STATE_NICE
]
*
100
.
0
/
total
;
mtr
->
values
[
CPU_METER_NORMAL
]
=
(
double
)
ticks
->
cpu_ticks
[
CPU_STATE_USER
]
*
100
.
0
/
total
;
mtr
->
values
[
CPU_METER_KERNEL
]
=
(
double
)
ticks
->
cpu_ticks
[
CPU_STATE_SYSTEM
]
*
100
.
0
/
total
;
mtr
->
values
[
CPU_METER_NICE
]
=
((
double
)
curr
->
cpu_ticks
[
CPU_STATE_NICE
]
-
(
double
)
prev
->
cpu_ticks
[
CPU_STATE_NICE
])
*
100
.
0
/
total
;
mtr
->
values
[
CPU_METER_NORMAL
]
=
((
double
)
curr
->
cpu_ticks
[
CPU_STATE_USER
]
-
(
double
)
prev
->
cpu_ticks
[
CPU_STATE_USER
])
*
100
.
0
/
total
;
mtr
->
values
[
CPU_METER_KERNEL
]
=
((
double
)
curr
->
cpu_ticks
[
CPU_STATE_SYSTEM
]
-
(
double
)
prev
->
cpu_ticks
[
CPU_STATE_SYSTEM
])
*
100
.
0
/
total
;
Meter_setItems
(
mtr
,
3
);
...
...
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