src/hotspot/os/windows/os_perf_windows.cpp
changeset 58282 03fce7b04b42
parent 58084 cddef3bde924
child 58679 9c3209ff7550
child 59122 5d73255c2d52
equal deleted inserted replaced
58281:49836127542b 58282:03fce7b04b42
   192 template <typename QueryP>
   192 template <typename QueryP>
   193 static int open_query(QueryP query) {
   193 static int open_query(QueryP query) {
   194   return open_query(&query->query);
   194   return open_query(&query->query);
   195 }
   195 }
   196 
   196 
   197 static int allocate_counters(MultiCounterQueryP query, size_t nofCounters) {
   197 static void allocate_counters(MultiCounterQueryP query, size_t nofCounters) {
   198   assert(query != NULL, "invariant");
   198   assert(query != NULL, "invariant");
   199   assert(!query->initialized, "invariant");
   199   assert(!query->initialized, "invariant");
   200   assert(0 == query->noOfCounters, "invariant");
   200   assert(0 == query->noOfCounters, "invariant");
   201   assert(query->counters == NULL, "invariant");
   201   assert(query->counters == NULL, "invariant");
   202   query->counters = NEW_C_HEAP_ARRAY(HCOUNTER, nofCounters, mtInternal);
   202   query->counters = NEW_C_HEAP_ARRAY(HCOUNTER, nofCounters, mtInternal);
   203   if (query->counters == NULL) {
       
   204     return OS_ERR;
       
   205   }
       
   206   memset(query->counters, 0, nofCounters * sizeof(HCOUNTER));
   203   memset(query->counters, 0, nofCounters * sizeof(HCOUNTER));
   207   query->noOfCounters = (int)nofCounters;
   204   query->noOfCounters = (int)nofCounters;
   208   return OS_OK;
   205 }
   209 }
   206 
   210 
   207 static void allocate_counters(MultiCounterQuerySetP query_set, size_t nofCounters) {
   211 static int allocate_counters(MultiCounterQuerySetP query_set, size_t nofCounters) {
       
   212   assert(query_set != NULL, "invariant");
   208   assert(query_set != NULL, "invariant");
   213   assert(!query_set->initialized, "invariant");
   209   assert(!query_set->initialized, "invariant");
   214   for (int i = 0; i < query_set->size; ++i) {
   210   for (int i = 0; i < query_set->size; ++i) {
   215     if (allocate_counters(&query_set->queries[i], nofCounters) != OS_OK) {
   211     allocate_counters(&query_set->queries[i], nofCounters);
   216       return OS_ERR;
   212   }
   217     }
   213 }
   218   }
   214 
   219   return OS_OK;
   215 static void allocate_counters(ProcessQueryP process_query, size_t nofCounters) {
   220 }
       
   221 
       
   222 static int allocate_counters(ProcessQueryP process_query, size_t nofCounters) {
       
   223   assert(process_query != NULL, "invariant");
   216   assert(process_query != NULL, "invariant");
   224   return allocate_counters(&process_query->set, nofCounters);
   217   allocate_counters(&process_query->set, nofCounters);
   225 }
   218 }
   226 
   219 
   227 static void deallocate_counters(MultiCounterQueryP query) {
   220 static void deallocate_counters(MultiCounterQueryP query) {
   228   FREE_C_HEAP_ARRAY(char, query->counters);
   221   FREE_C_HEAP_ARRAY(char, query->counters);
   229   query->counters = NULL;
   222   query->counters = NULL;
   598 }
   591 }
   599 
   592 
   600 static const char* copy_string_to_c_heap(const char* string) {
   593 static const char* copy_string_to_c_heap(const char* string) {
   601   assert(string != NULL, "invariant");
   594   assert(string != NULL, "invariant");
   602   const size_t len = strlen(string);
   595   const size_t len = strlen(string);
   603   char* const cheap_allocated_string = NEW_C_HEAP_ARRAY(char, len + 1, mtInternal);
   596   char* const cheap_allocated_string = NEW_C_HEAP_ARRAY_RETURN_NULL(char, len + 1, mtInternal);
   604   if (NULL == cheap_allocated_string) {
   597   if (NULL == cheap_allocated_string) {
   605     return NULL;
   598     return NULL;
   606   }
   599   }
   607   strncpy(cheap_allocated_string, string, len + 1);
   600   strncpy(cheap_allocated_string, string, len + 1);
   608   return cheap_allocated_string;
   601   return cheap_allocated_string;
   847   assert(cpu_query != NULL, "invariant");
   840   assert(cpu_query != NULL, "invariant");
   848   assert(!cpu_query->initialized, "invariant");
   841   assert(!cpu_query->initialized, "invariant");
   849   const int logical_cpu_count = number_of_logical_cpus();
   842   const int logical_cpu_count = number_of_logical_cpus();
   850   assert(logical_cpu_count >= os::processor_count(), "invariant");
   843   assert(logical_cpu_count >= os::processor_count(), "invariant");
   851   // we also add another counter for instance "_Total"
   844   // we also add another counter for instance "_Total"
   852   if (allocate_counters(cpu_query, logical_cpu_count + 1) != OS_OK) {
   845   allocate_counters(cpu_query, logical_cpu_count + 1);
   853     return OS_ERR;
       
   854   }
       
   855   assert(cpu_query->noOfCounters == logical_cpu_count + 1, "invariant");
   846   assert(cpu_query->noOfCounters == logical_cpu_count + 1, "invariant");
   856   return initialize_cpu_query_counters(cpu_query, pdh_counter_idx);
   847   return initialize_cpu_query_counters(cpu_query, pdh_counter_idx);
   857 }
   848 }
   858 
   849 
   859 static int initialize_process_counter(ProcessQueryP process_query, int slot_index, DWORD pdh_counter_index) {
   850 static int initialize_process_counter(ProcessQueryP process_query, int slot_index, DWORD pdh_counter_index) {
  1015   _context_switches = create_counter_query(PDH_SYSTEM_IDX, PDH_CONTEXT_SWITCH_RATE_IDX);
  1006   _context_switches = create_counter_query(PDH_SYSTEM_IDX, PDH_CONTEXT_SWITCH_RATE_IDX);
  1016   _process_cpu_load = create_process_query();
  1007   _process_cpu_load = create_process_query();
  1017   if (_process_cpu_load == NULL) {
  1008   if (_process_cpu_load == NULL) {
  1018     return true;
  1009     return true;
  1019   }
  1010   }
  1020   if (allocate_counters(_process_cpu_load, 2) != OS_OK) {
  1011   allocate_counters(_process_cpu_load, 2);
  1021     return true;
       
  1022   }
       
  1023   if (initialize_process_counter(_process_cpu_load, 0, PDH_PROCESSOR_TIME_IDX) != OS_OK) {
  1012   if (initialize_process_counter(_process_cpu_load, 0, PDH_PROCESSOR_TIME_IDX) != OS_OK) {
  1024     return true;
  1013     return true;
  1025   }
  1014   }
  1026   if (initialize_process_counter(_process_cpu_load, 1, PDH_PRIV_PROCESSOR_TIME_IDX) != OS_OK) {
  1015   if (initialize_process_counter(_process_cpu_load, 1, PDH_PRIV_PROCESSOR_TIME_IDX) != OS_OK) {
  1027     return true;
  1016     return true;
  1055   _impl = NULL;
  1044   _impl = NULL;
  1056 }
  1045 }
  1057 
  1046 
  1058 bool CPUPerformanceInterface::initialize() {
  1047 bool CPUPerformanceInterface::initialize() {
  1059   _impl = new CPUPerformanceInterface::CPUPerformance();
  1048   _impl = new CPUPerformanceInterface::CPUPerformance();
  1060   return _impl != NULL && _impl->initialize();
  1049   return _impl->initialize();
  1061 }
  1050 }
  1062 
  1051 
  1063 CPUPerformanceInterface::~CPUPerformanceInterface() {
  1052 CPUPerformanceInterface::~CPUPerformanceInterface() {
  1064   if (_impl != NULL) {
  1053   if (_impl != NULL) {
  1065     delete _impl;
  1054     delete _impl;
  1261   _iterator = NULL;
  1250   _iterator = NULL;
  1262 }
  1251 }
  1263 
  1252 
  1264 bool SystemProcessInterface::SystemProcesses::initialize() {
  1253 bool SystemProcessInterface::SystemProcesses::initialize() {
  1265   _iterator = new SystemProcessInterface::SystemProcesses::ProcessIterator();
  1254   _iterator = new SystemProcessInterface::SystemProcesses::ProcessIterator();
  1266   return _iterator != NULL && _iterator->initialize();
  1255   return _iterator->initialize();
  1267 }
  1256 }
  1268 
  1257 
  1269 SystemProcessInterface::SystemProcesses::~SystemProcesses() {
  1258 SystemProcessInterface::SystemProcesses::~SystemProcesses() {
  1270   if (_iterator != NULL) {
  1259   if (_iterator != NULL) {
  1271     delete _iterator;
  1260     delete _iterator;
  1316   _impl = NULL;
  1305   _impl = NULL;
  1317 }
  1306 }
  1318 
  1307 
  1319 bool SystemProcessInterface::initialize() {
  1308 bool SystemProcessInterface::initialize() {
  1320   _impl = new SystemProcessInterface::SystemProcesses();
  1309   _impl = new SystemProcessInterface::SystemProcesses();
  1321   return _impl != NULL && _impl->initialize();
  1310   return _impl->initialize();
  1322 }
  1311 }
  1323 
  1312 
  1324 SystemProcessInterface::~SystemProcessInterface() {
  1313 SystemProcessInterface::~SystemProcessInterface() {
  1325   if (_impl != NULL) {
  1314   if (_impl != NULL) {
  1326     delete _impl;
  1315     delete _impl;
  1331   _cpu_info = NULL;
  1320   _cpu_info = NULL;
  1332 }
  1321 }
  1333 
  1322 
  1334 bool CPUInformationInterface::initialize() {
  1323 bool CPUInformationInterface::initialize() {
  1335   _cpu_info = new CPUInformation();
  1324   _cpu_info = new CPUInformation();
  1336   if (NULL == _cpu_info) {
       
  1337     return false;
       
  1338   }
       
  1339   _cpu_info->set_number_of_hardware_threads(VM_Version_Ext::number_of_threads());
  1325   _cpu_info->set_number_of_hardware_threads(VM_Version_Ext::number_of_threads());
  1340   _cpu_info->set_number_of_cores(VM_Version_Ext::number_of_cores());
  1326   _cpu_info->set_number_of_cores(VM_Version_Ext::number_of_cores());
  1341   _cpu_info->set_number_of_sockets(VM_Version_Ext::number_of_sockets());
  1327   _cpu_info->set_number_of_sockets(VM_Version_Ext::number_of_sockets());
  1342   _cpu_info->set_cpu_name(VM_Version_Ext::cpu_name());
  1328   _cpu_info->set_cpu_name(VM_Version_Ext::cpu_name());
  1343   _cpu_info->set_cpu_description(VM_Version_Ext::cpu_description());
  1329   _cpu_info->set_cpu_description(VM_Version_Ext::cpu_description());
  1429   }
  1415   }
  1430 }
  1416 }
  1431 
  1417 
  1432 bool NetworkPerformanceInterface::initialize() {
  1418 bool NetworkPerformanceInterface::initialize() {
  1433   _impl = new NetworkPerformanceInterface::NetworkPerformance();
  1419   _impl = new NetworkPerformanceInterface::NetworkPerformance();
  1434   return _impl != NULL && _impl->initialize();
  1420   return _impl->initialize();
  1435 }
  1421 }
  1436 
  1422 
  1437 int NetworkPerformanceInterface::network_utilization(NetworkInterface** network_interfaces) const {
  1423 int NetworkPerformanceInterface::network_utilization(NetworkInterface** network_interfaces) const {
  1438   return _impl->network_utilization(network_interfaces);
  1424   return _impl->network_utilization(network_interfaces);
  1439 }
  1425 }