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:
Pawel "l0ner" Soltys 2015-02-12 19:59:22 +01:00
parent d21be2b87c
commit 80d70b7a4d
2 changed files with 12 additions and 2 deletions

@ -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 );