fix for cpu systctl failing on 64 bit OpenBSD
On 64bit system KERN_CPTIME systctl gets returned as 64bit uint. On 32bit system it's returned as 32bit uint. This is not documented anywhere (or maybe I've missed it). I've added preprocessor test for 64bit system.
This commit is contained in:
parent
d21be2b87c
commit
80d70b7a4d
@ -73,7 +73,7 @@ std::string cpu_string( unsigned int cpu_usage_delay, unsigned int graph_lines,
|
||||
|
||||
if( graph_lines > 0)
|
||||
{
|
||||
oss << "[";
|
||||
oss << " [";
|
||||
oss << get_graph_by_percentage( unsigned( percentage ), graph_lines );
|
||||
oss << "]";
|
||||
}
|
||||
@ -173,7 +173,7 @@ int main( int argc, char** argv )
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
std::cout << mem_string( use_colors ) << ' '
|
||||
std::cout << mem_string( use_colors )
|
||||
<< cpu_string( cpu_usage_delay, graph_lines, use_colors ) << ' '
|
||||
<< load_string( use_colors );
|
||||
|
||||
|
@ -42,8 +42,18 @@ float cpu_percentage( unsigned int cpu_usage_delay )
|
||||
{
|
||||
int cpu_ctl[] = { CTL_KERN, KERN_CPTIME };
|
||||
|
||||
// on 64bit systems KERN_CPTIME gets reported as 64bit
|
||||
// uint. Detect 64bit system and define array to hold the
|
||||
// stats accordingly.
|
||||
// NOTE: the following test may need to be extended to cover
|
||||
// more 64bit platforms.
|
||||
#if __x86_64__ || __ppc64__
|
||||
u_int64_t load1[CPUSTATES];
|
||||
u_int64_t load2[CPUSTATES];
|
||||
#else
|
||||
u_int32_t load1[CPUSTATES];
|
||||
u_int32_t load2[CPUSTATES];
|
||||
#endif
|
||||
|
||||
size_t size = sizeof( load1 );
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user