21 * questions. |
21 * questions. |
22 * |
22 * |
23 */ |
23 */ |
24 |
24 |
25 #include "precompiled.hpp" |
25 #include "precompiled.hpp" |
|
26 #include "iphlp_interface.hpp" |
26 #include "logging/log.hpp" |
27 #include "logging/log.hpp" |
27 #include "memory/allocation.inline.hpp" |
28 #include "memory/allocation.inline.hpp" |
28 #include "memory/resourceArea.hpp" |
29 #include "memory/resourceArea.hpp" |
29 #include "pdh_interface.hpp" |
30 #include "pdh_interface.hpp" |
30 #include "runtime/os_perf.hpp" |
31 #include "runtime/os_perf.hpp" |
31 #include "runtime/os.hpp" |
32 #include "runtime/os.hpp" |
|
33 #include "utilities/macros.hpp" |
32 #include "vm_version_ext_x86.hpp" |
34 #include "vm_version_ext_x86.hpp" |
33 #include "utilities/macros.hpp" |
|
34 #include <math.h> |
35 #include <math.h> |
35 #include <psapi.h> |
36 #include <psapi.h> |
36 #include <TlHelp32.h> |
37 #include <TlHelp32.h> |
37 |
38 |
38 /* |
39 /* |
1378 return OS_ERR; |
1379 return OS_ERR; |
1379 } |
1380 } |
1380 cpu_info = *_cpu_info; // shallow copy assignment |
1381 cpu_info = *_cpu_info; // shallow copy assignment |
1381 return OS_OK; |
1382 return OS_OK; |
1382 } |
1383 } |
|
1384 |
|
1385 class NetworkPerformanceInterface::NetworkPerformance : public CHeapObj<mtInternal> { |
|
1386 friend class NetworkPerformanceInterface; |
|
1387 private: |
|
1388 bool _iphlp_attached; |
|
1389 |
|
1390 NetworkPerformance(); |
|
1391 NetworkPerformance(const NetworkPerformance& rhs); // no impl |
|
1392 NetworkPerformance& operator=(const NetworkPerformance& rhs); // no impl |
|
1393 bool initialize(); |
|
1394 ~NetworkPerformance(); |
|
1395 int network_utilization(NetworkInterface** network_interfaces) const; |
|
1396 }; |
|
1397 |
|
1398 NetworkPerformanceInterface::NetworkPerformance::NetworkPerformance() |
|
1399 : _iphlp_attached(false) { |
|
1400 } |
|
1401 |
|
1402 bool NetworkPerformanceInterface::NetworkPerformance::initialize() { |
|
1403 _iphlp_attached = IphlpDll::IphlpAttach(); |
|
1404 return _iphlp_attached; |
|
1405 } |
|
1406 |
|
1407 NetworkPerformanceInterface::NetworkPerformance::~NetworkPerformance() { |
|
1408 if (_iphlp_attached) { |
|
1409 IphlpDll::IphlpDetach(); |
|
1410 } |
|
1411 } |
|
1412 |
|
1413 int NetworkPerformanceInterface::NetworkPerformance::network_utilization(NetworkInterface** network_interfaces) const { |
|
1414 MIB_IF_TABLE2* table; |
|
1415 |
|
1416 if (IphlpDll::GetIfTable2(&table) != NO_ERROR) { |
|
1417 return OS_ERR; |
|
1418 } |
|
1419 |
|
1420 NetworkInterface* ret = NULL; |
|
1421 for (ULONG i = 0; i < table->NumEntries; ++i) { |
|
1422 if (table->Table[i].InterfaceAndOperStatusFlags.FilterInterface) { |
|
1423 continue; |
|
1424 } |
|
1425 |
|
1426 char buf[256]; |
|
1427 if (WideCharToMultiByte(CP_UTF8, 0, table->Table[i].Description, -1, buf, sizeof(buf), NULL, NULL) == 0) { |
|
1428 continue; |
|
1429 } |
|
1430 |
|
1431 NetworkInterface* cur = new NetworkInterface(buf, table->Table[i].InOctets, table->Table[i].OutOctets, ret); |
|
1432 ret = cur; |
|
1433 } |
|
1434 |
|
1435 IphlpDll::FreeMibTable(table); |
|
1436 *network_interfaces = ret; |
|
1437 |
|
1438 return OS_OK; |
|
1439 } |
|
1440 |
|
1441 NetworkPerformanceInterface::NetworkPerformanceInterface() { |
|
1442 _impl = NULL; |
|
1443 } |
|
1444 |
|
1445 NetworkPerformanceInterface::~NetworkPerformanceInterface() { |
|
1446 if (_impl != NULL) { |
|
1447 delete _impl; |
|
1448 } |
|
1449 } |
|
1450 |
|
1451 bool NetworkPerformanceInterface::initialize() { |
|
1452 _impl = new NetworkPerformanceInterface::NetworkPerformance(); |
|
1453 return _impl != NULL && _impl->initialize(); |
|
1454 } |
|
1455 |
|
1456 int NetworkPerformanceInterface::network_utilization(NetworkInterface** network_interfaces) const { |
|
1457 return _impl->network_utilization(network_interfaces); |
|
1458 } |