src/os/aix/vm/os_perf_aix.cpp

changeset 9907
35063c223567
parent 9858
b985cbb00e68
equal deleted inserted replaced
9906:0df63a32f7bb 9907:35063c223567
1 /* 1 /*
2 * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
3 * Copyright (c) 2020 SAP SE. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 5 *
5 * This code is free software; you can redistribute it and/or modify it 6 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as 7 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. 8 * published by the Free Software Foundation.
26 #include "jvm.h" 27 #include "jvm.h"
27 #include "memory/allocation.inline.hpp" 28 #include "memory/allocation.inline.hpp"
28 #include "os_aix.inline.hpp" 29 #include "os_aix.inline.hpp"
29 #include "runtime/os.hpp" 30 #include "runtime/os.hpp"
30 #include "runtime/os_perf.hpp" 31 #include "runtime/os_perf.hpp"
31 32 #include "vm_version_ext_ppc.hpp"
32 #include CPU_HEADER(vm_version_ext)
33 33
34 #include <stdio.h> 34 #include <stdio.h>
35 #include <stdarg.h> 35 #include <stdarg.h>
36 #include <unistd.h> 36 #include <unistd.h>
37 #include <errno.h> 37 #include <errno.h>
177 format: %d %s %c %d %d %d %d %d %lu %lu %lu %lu %lu %lu %lu %ld %ld %ld %ld %ld %ld %lu %lu %ld %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %d %d 177 format: %d %s %c %d %d %d %d %d %lu %lu %lu %lu %lu %lu %lu %ld %ld %ld %ld %ld %ld %lu %lu %ld %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %d %d
178 178
179 179
180 */ 180 */
181 181
182 /**
183 * For platforms that have them, when declaring
184 * a printf-style function,
185 * formatSpec is the parameter number (starting at 1)
186 * that is the format argument ("%d pid %s")
187 * params is the parameter number where the actual args to
188 * the format starts. If the args are in a va_list, this
189 * should be 0.
190 */
191 #ifndef PRINTF_ARGS
192 # define PRINTF_ARGS(formatSpec, params) ATTRIBUTE_PRINTF(formatSpec, params)
193 #endif
194
195 #ifndef SCANF_ARGS
196 # define SCANF_ARGS(formatSpec, params) ATTRIBUTE_SCANF(formatSpec, params)
197 #endif
198
199 #ifndef _PRINTFMT_
200 # define _PRINTFMT_
201 #endif
202
203 #ifndef _SCANFMT_
204 # define _SCANFMT_
205 #endif
206
207
208 struct CPUPerfTicks { 182 struct CPUPerfTicks {
209 uint64_t used; 183 uint64_t used;
210 uint64_t usedKernel; 184 uint64_t usedKernel;
211 uint64_t total; 185 uint64_t total;
212 }; 186 };
232 static double get_cpu_load(int which_logical_cpu, CPUPerfCounters* counters, double* pkernelLoad, CpuLoadTarget target); 206 static double get_cpu_load(int which_logical_cpu, CPUPerfCounters* counters, double* pkernelLoad, CpuLoadTarget target);
233 207
234 /** reads /proc/<pid>/stat data, with some checks and some skips. 208 /** reads /proc/<pid>/stat data, with some checks and some skips.
235 * Ensure that 'fmt' does _NOT_ contain the first two "%d %s" 209 * Ensure that 'fmt' does _NOT_ contain the first two "%d %s"
236 */ 210 */
237 static int SCANF_ARGS(2, 0) vread_statdata(const char* procfile, _SCANFMT_ const char* fmt, va_list args) { 211 static int vread_statdata(const char* procfile, const char* fmt, va_list args) {
238 FILE*f; 212 FILE*f;
239 int n; 213 int n;
240 char buf[2048]; 214 char buf[2048];
241 215
242 if ((f = fopen(procfile, "r")) == NULL) { 216 if ((f = fopen(procfile, "r")) == NULL) {
261 fclose(f); 235 fclose(f);
262 236
263 return n; 237 return n;
264 } 238 }
265 239
266 static int SCANF_ARGS(2, 3) read_statdata(const char* procfile, _SCANFMT_ const char* fmt, ...) { 240 static int read_statdata(const char* procfile, const char* fmt, ...) {
267 int n; 241 int n;
268 va_list args; 242 va_list args;
269 243
270 va_start(args, fmt); 244 va_start(args, fmt);
271 n = vread_statdata(procfile, fmt, args); 245 n = vread_statdata(procfile, fmt, args);
470 user_load = MIN2<double>(user_load, 1.0); 444 user_load = MIN2<double>(user_load, 1.0);
471 445
472 return user_load; 446 return user_load;
473 } 447 }
474 448
475 static int SCANF_ARGS(1, 2) parse_stat(_SCANFMT_ const char* fmt, ...) { 449 static int parse_stat(const char* fmt, ...) {
476 FILE *f; 450 FILE *f;
477 va_list args; 451 va_list args;
478 452
479 va_start(args, fmt); 453 va_start(args, fmt);
480 454
607 return true; 581 return true;
608 } 582 }
609 583
610 CPUPerformanceInterface::CPUPerformance::~CPUPerformance() { 584 CPUPerformanceInterface::CPUPerformance::~CPUPerformance() {
611 if (_counters.cpus != NULL) { 585 if (_counters.cpus != NULL) {
612 FREE_C_HEAP_ARRAY(char, _counters.cpus); 586 FREE_C_HEAP_ARRAY(char, _counters.cpus, mtInternal);
613 } 587 }
614 } 588 }
615 589
616 int CPUPerformanceInterface::CPUPerformance::cpu_load(int which_logical_cpu, double* cpu_load) { 590 int CPUPerformanceInterface::CPUPerformance::cpu_load(int which_logical_cpu, double* cpu_load) {
617 double u, s; 591 double u, s;
884 858
885 char* cmdline = NULL; 859 char* cmdline = NULL;
886 cmdline = get_cmdline(); 860 cmdline = get_cmdline();
887 if (cmdline != NULL) { 861 if (cmdline != NULL) {
888 process_info->set_command_line(allocate_string(cmdline)); 862 process_info->set_command_line(allocate_string(cmdline));
889 FREE_C_HEAP_ARRAY(char, cmdline); 863 FREE_C_HEAP_ARRAY(char, cmdline, mtInternal);
890 } 864 }
891 865
892 return OS_OK; 866 return OS_OK;
893 } 867 }
894 868
1009 983
1010 CPUInformationInterface::~CPUInformationInterface() { 984 CPUInformationInterface::~CPUInformationInterface() {
1011 if (_cpu_info != NULL) { 985 if (_cpu_info != NULL) {
1012 if (_cpu_info->cpu_name() != NULL) { 986 if (_cpu_info->cpu_name() != NULL) {
1013 const char* cpu_name = _cpu_info->cpu_name(); 987 const char* cpu_name = _cpu_info->cpu_name();
1014 FREE_C_HEAP_ARRAY(char, cpu_name); 988 FREE_C_HEAP_ARRAY(char, cpu_name, mtInternal);
1015 _cpu_info->set_cpu_name(NULL); 989 _cpu_info->set_cpu_name(NULL);
1016 } 990 }
1017 if (_cpu_info->cpu_description() != NULL) { 991 if (_cpu_info->cpu_description() != NULL) {
1018 const char* cpu_desc = _cpu_info->cpu_description(); 992 const char* cpu_desc = _cpu_info->cpu_description();
1019 FREE_C_HEAP_ARRAY(char, cpu_desc); 993 FREE_C_HEAP_ARRAY(char, cpu_desc, mtInternal);
1020 _cpu_info->set_cpu_description(NULL); 994 _cpu_info->set_cpu_description(NULL);
1021 } 995 }
1022 delete _cpu_info; 996 delete _cpu_info;
1023 } 997 }
1024 } 998 }

mercurial