309
310 // Get kstat cpu_stat counters for every CPU
311 // loop over kstat to find our cpu_stat(s)
312 int i = 0;
313 for (kstat_t* kstat = _counters.kstat_ctrl->kc_chain; kstat != NULL; kstat = kstat->ks_next) {
314 if (strncmp(kstat->ks_module, "cpu_stat", 8) == 0) {
315 if (kstat_read(_counters.kstat_ctrl, kstat, NULL) == OS_ERR) {
316 continue;
317 }
318 if (i == _counters.nProcs) {
319 // more cpu_stats than reported CPUs
320 break;
321 }
322 _counters.jvmTicks[i++].kstat = kstat;
323 }
324 }
325 return true;
326 }
327
328 CPUPerformanceInterface::CPUPerformance::~CPUPerformance() {
329 if (_counters.jvmTicks != NULL) {
330 FREE_C_HEAP_ARRAY(char, _counters.jvmTicks);
331 }
332 if (_counters.kstat_ctrl != NULL) {
333 kstat_close(_counters.kstat_ctrl);
334 }
335 }
336
337 int CPUPerformanceInterface::CPUPerformance::cpu_load(int which_logical_cpu, double* cpu_load) {
338 assert(cpu_load != NULL, "cpu_load pointer is NULL!");
339 double t = .0;
340 if (-1 == which_logical_cpu) {
341 for (int i = 0; i < _counters.nProcs; i++) {
342 t += get_cpu_load(i, &_counters);
343 }
344 // Cap total systemload to 1.0
345 t = MIN2<double>((t / _counters.nProcs), 1.0);
346 } else {
347 t = MIN2<double>(get_cpu_load(which_logical_cpu, &_counters), 1.0);
348 }
349
350 *cpu_load = t;
351 return OS_OK;
|
309
310 // Get kstat cpu_stat counters for every CPU
311 // loop over kstat to find our cpu_stat(s)
312 int i = 0;
313 for (kstat_t* kstat = _counters.kstat_ctrl->kc_chain; kstat != NULL; kstat = kstat->ks_next) {
314 if (strncmp(kstat->ks_module, "cpu_stat", 8) == 0) {
315 if (kstat_read(_counters.kstat_ctrl, kstat, NULL) == OS_ERR) {
316 continue;
317 }
318 if (i == _counters.nProcs) {
319 // more cpu_stats than reported CPUs
320 break;
321 }
322 _counters.jvmTicks[i++].kstat = kstat;
323 }
324 }
325 return true;
326 }
327
328 CPUPerformanceInterface::CPUPerformance::~CPUPerformance() {
329 FREE_C_HEAP_ARRAY(char, _counters.jvmTicks);
330 if (_counters.kstat_ctrl != NULL) {
331 kstat_close(_counters.kstat_ctrl);
332 }
333 }
334
335 int CPUPerformanceInterface::CPUPerformance::cpu_load(int which_logical_cpu, double* cpu_load) {
336 assert(cpu_load != NULL, "cpu_load pointer is NULL!");
337 double t = .0;
338 if (-1 == which_logical_cpu) {
339 for (int i = 0; i < _counters.nProcs; i++) {
340 t += get_cpu_load(i, &_counters);
341 }
342 // Cap total systemload to 1.0
343 t = MIN2<double>((t / _counters.nProcs), 1.0);
344 } else {
345 t = MIN2<double>(get_cpu_load(which_logical_cpu, &_counters), 1.0);
346 }
347
348 *cpu_load = t;
349 return OS_OK;
|