< prev index next >

src/hotspot/os/windows/os_perf_windows.cpp

Print this page

 208   return OS_OK;
 209 }
 210 
 211 static int allocate_counters(MultiCounterQuerySetP query_set, size_t nofCounters) {
 212   assert(query_set != NULL, "invariant");
 213   assert(!query_set->initialized, "invariant");
 214   for (int i = 0; i < query_set->size; ++i) {
 215     if (allocate_counters(&query_set->queries[i], nofCounters) != OS_OK) {
 216       return OS_ERR;
 217     }
 218   }
 219   return OS_OK;
 220 }
 221 
 222 static int allocate_counters(ProcessQueryP process_query, size_t nofCounters) {
 223   assert(process_query != NULL, "invariant");
 224   return allocate_counters(&process_query->set, nofCounters);
 225 }
 226 
 227 static void deallocate_counters(MultiCounterQueryP query) {
 228   if (query->counters != NULL) {
 229     FREE_C_HEAP_ARRAY(char, query->counters);
 230     query->counters = NULL;
 231     query->noOfCounters = 0;
 232   }
 233 }
 234 
 235 static OSReturn add_counter(UpdateQueryP query, HCOUNTER* counter, const char* path, bool first_sample_on_init) {
 236   assert(query != NULL, "invariant");
 237   assert(counter != NULL, "invariant");
 238   assert(path != NULL, "invariant");
 239   if (query->query == NULL) {
 240     if (open_query(query) != ERROR_SUCCESS) {
 241       return OS_ERR;
 242     }
 243   }
 244   assert(query->query != NULL, "invariant");
 245   PDH_STATUS status = PdhDll::PdhAddCounter(query->query, path, 0, counter);
 246   if (PDH_CSTATUS_NO_OBJECT == status || PDH_CSTATUS_NO_COUNTER == status) {
 247     return OS_ERR;
 248   }
 249   /*
 250   * According to the MSDN documentation, rate counters must be read twice:
 251   *
 252   * "Obtaining the value of rate counters such as Page faults/sec requires that

 642   char* module_name = NEW_RESOURCE_ARRAY_RETURN_NULL(char, MAX_PATH);
 643   if (NULL == module_name) {
 644     return NULL;
 645   }
 646   // Find our module name and use it to extract the image name used by PDH
 647   DWORD getmfn_return = GetModuleFileName(NULL, module_name, MAX_PATH);
 648   if (getmfn_return >= MAX_PATH || 0 == getmfn_return) {
 649     return NULL;
 650   }
 651   if (os::get_last_error() == ERROR_INSUFFICIENT_BUFFER) {
 652     return NULL;
 653   }
 654   char* process_image_name = strrchr(module_name, '\\'); //drop path
 655   process_image_name++;                                  //skip slash
 656   char* dot_pos = strrchr(process_image_name, '.');      //drop .exe
 657   dot_pos[0] = '\0';
 658   return process_image_name;
 659 }
 660 
 661 static void deallocate_pdh_constants() {
 662   if (process_image_name != NULL) {
 663     FREE_C_HEAP_ARRAY(char, process_image_name);
 664     process_image_name = NULL;
 665   }
 666   if (pdh_IDProcess_counter_fmt != NULL) {
 667     FREE_C_HEAP_ARRAY(char, pdh_IDProcess_counter_fmt);
 668     pdh_IDProcess_counter_fmt = NULL;
 669   }
 670 }
 671 
 672 static int allocate_pdh_constants() {
 673   assert(process_image_name == NULL, "invariant");
 674   const char* pdh_image_name = pdh_process_image_name();
 675   if (pdh_image_name == NULL) {
 676     return OS_ERR;
 677   }
 678   process_image_name = copy_string_to_c_heap(pdh_image_name);
 679 
 680   const char* pdh_localized_process_object = pdh_localized_artifact(PDH_PROCESS_IDX);
 681   if (pdh_localized_process_object == NULL) {
 682     return OS_ERR;
 683   }
 684 
 685   const char* pdh_localized_IDProcess_counter = pdh_localized_artifact(PDH_ID_PROCESS_IDX);
 686   if (pdh_localized_IDProcess_counter == NULL) {
 687     return OS_ERR;
 688   }
 689 

1335 
1336 CPUInformationInterface::CPUInformationInterface() {
1337   _cpu_info = NULL;
1338 }
1339 
1340 bool CPUInformationInterface::initialize() {
1341   _cpu_info = new CPUInformation();
1342   if (NULL == _cpu_info) {
1343     return false;
1344   }
1345   _cpu_info->set_number_of_hardware_threads(VM_Version_Ext::number_of_threads());
1346   _cpu_info->set_number_of_cores(VM_Version_Ext::number_of_cores());
1347   _cpu_info->set_number_of_sockets(VM_Version_Ext::number_of_sockets());
1348   _cpu_info->set_cpu_name(VM_Version_Ext::cpu_name());
1349   _cpu_info->set_cpu_description(VM_Version_Ext::cpu_description());
1350   return true;
1351 }
1352 
1353 CPUInformationInterface::~CPUInformationInterface() {
1354   if (_cpu_info != NULL) {
1355     const char* cpu_name = _cpu_info->cpu_name();
1356     if (cpu_name != NULL) {
1357       FREE_C_HEAP_ARRAY(char, cpu_name);
1358       _cpu_info->set_cpu_name(NULL);
1359     }
1360     const char* cpu_desc = _cpu_info->cpu_description();
1361     if (cpu_desc != NULL) {
1362       FREE_C_HEAP_ARRAY(char, cpu_desc);
1363       _cpu_info->set_cpu_description(NULL);
1364     }
1365     delete _cpu_info;
1366     _cpu_info = NULL;
1367   }
1368 }
1369 
1370 int CPUInformationInterface::cpu_information(CPUInformation& cpu_info) {
1371   if (NULL == _cpu_info) {
1372     return OS_ERR;
1373   }
1374   cpu_info = *_cpu_info; // shallow copy assignment
1375   return OS_OK;
1376 }
1377 
1378 class NetworkPerformanceInterface::NetworkPerformance : public CHeapObj<mtInternal> {
1379   friend class NetworkPerformanceInterface;
1380  private:
1381   bool _iphlp_attached;
1382 
1383   NetworkPerformance();
1384   NetworkPerformance(const NetworkPerformance& rhs); // no impl

 208   return OS_OK;
 209 }
 210 
 211 static int allocate_counters(MultiCounterQuerySetP query_set, size_t nofCounters) {
 212   assert(query_set != NULL, "invariant");
 213   assert(!query_set->initialized, "invariant");
 214   for (int i = 0; i < query_set->size; ++i) {
 215     if (allocate_counters(&query_set->queries[i], nofCounters) != OS_OK) {
 216       return OS_ERR;
 217     }
 218   }
 219   return OS_OK;
 220 }
 221 
 222 static int allocate_counters(ProcessQueryP process_query, size_t nofCounters) {
 223   assert(process_query != NULL, "invariant");
 224   return allocate_counters(&process_query->set, nofCounters);
 225 }
 226 
 227 static void deallocate_counters(MultiCounterQueryP query) {

 228     FREE_C_HEAP_ARRAY(char, query->counters);
 229     query->counters = NULL;
 230     query->noOfCounters = 0;

 231 }
 232 
 233 static OSReturn add_counter(UpdateQueryP query, HCOUNTER* counter, const char* path, bool first_sample_on_init) {
 234   assert(query != NULL, "invariant");
 235   assert(counter != NULL, "invariant");
 236   assert(path != NULL, "invariant");
 237   if (query->query == NULL) {
 238     if (open_query(query) != ERROR_SUCCESS) {
 239       return OS_ERR;
 240     }
 241   }
 242   assert(query->query != NULL, "invariant");
 243   PDH_STATUS status = PdhDll::PdhAddCounter(query->query, path, 0, counter);
 244   if (PDH_CSTATUS_NO_OBJECT == status || PDH_CSTATUS_NO_COUNTER == status) {
 245     return OS_ERR;
 246   }
 247   /*
 248   * According to the MSDN documentation, rate counters must be read twice:
 249   *
 250   * "Obtaining the value of rate counters such as Page faults/sec requires that

 640   char* module_name = NEW_RESOURCE_ARRAY_RETURN_NULL(char, MAX_PATH);
 641   if (NULL == module_name) {
 642     return NULL;
 643   }
 644   // Find our module name and use it to extract the image name used by PDH
 645   DWORD getmfn_return = GetModuleFileName(NULL, module_name, MAX_PATH);
 646   if (getmfn_return >= MAX_PATH || 0 == getmfn_return) {
 647     return NULL;
 648   }
 649   if (os::get_last_error() == ERROR_INSUFFICIENT_BUFFER) {
 650     return NULL;
 651   }
 652   char* process_image_name = strrchr(module_name, '\\'); //drop path
 653   process_image_name++;                                  //skip slash
 654   char* dot_pos = strrchr(process_image_name, '.');      //drop .exe
 655   dot_pos[0] = '\0';
 656   return process_image_name;
 657 }
 658 
 659 static void deallocate_pdh_constants() {
 660   FREE_C_HEAP_ARRAY(char, process_image_name);
 661   process_image_name = NULL;
 662   FREE_C_HEAP_ARRAY(char, pdh_IDProcess_counter_fmt);
 663   pdh_IDProcess_counter_fmt = NULL;




 664 }
 665 
 666 static int allocate_pdh_constants() {
 667   assert(process_image_name == NULL, "invariant");
 668   const char* pdh_image_name = pdh_process_image_name();
 669   if (pdh_image_name == NULL) {
 670     return OS_ERR;
 671   }
 672   process_image_name = copy_string_to_c_heap(pdh_image_name);
 673 
 674   const char* pdh_localized_process_object = pdh_localized_artifact(PDH_PROCESS_IDX);
 675   if (pdh_localized_process_object == NULL) {
 676     return OS_ERR;
 677   }
 678 
 679   const char* pdh_localized_IDProcess_counter = pdh_localized_artifact(PDH_ID_PROCESS_IDX);
 680   if (pdh_localized_IDProcess_counter == NULL) {
 681     return OS_ERR;
 682   }
 683 

1329 
1330 CPUInformationInterface::CPUInformationInterface() {
1331   _cpu_info = NULL;
1332 }
1333 
1334 bool CPUInformationInterface::initialize() {
1335   _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());
1340   _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());
1342   _cpu_info->set_cpu_name(VM_Version_Ext::cpu_name());
1343   _cpu_info->set_cpu_description(VM_Version_Ext::cpu_description());
1344   return true;
1345 }
1346 
1347 CPUInformationInterface::~CPUInformationInterface() {
1348   if (_cpu_info != NULL) {
1349     FREE_C_HEAP_ARRAY(char, _cpu_info->cpu_name());
1350     _cpu_info->set_cpu_name(NULL);
1351     FREE_C_HEAP_ARRAY(char, _cpu_info->cpu_description());
1352     _cpu_info->set_cpu_description(NULL);






1353     delete _cpu_info;
1354     _cpu_info = NULL;
1355   }
1356 }
1357 
1358 int CPUInformationInterface::cpu_information(CPUInformation& cpu_info) {
1359   if (NULL == _cpu_info) {
1360     return OS_ERR;
1361   }
1362   cpu_info = *_cpu_info; // shallow copy assignment
1363   return OS_OK;
1364 }
1365 
1366 class NetworkPerformanceInterface::NetworkPerformance : public CHeapObj<mtInternal> {
1367   friend class NetworkPerformanceInterface;
1368  private:
1369   bool _iphlp_attached;
1370 
1371   NetworkPerformance();
1372   NetworkPerformance(const NetworkPerformance& rhs); // no impl
< prev index next >