| 1517 | #endif |
| 1518 | |
| 1519 | SystemStatistics getSystemStatistics(std::string const& dataFolder, |
| 1520 | const IPAddress* ip, |
| 1521 | SystemStatisticsState** statState, |
| 1522 | bool logDetails) { |
| 1523 | if ((*statState) == nullptr) |
| 1524 | (*statState) = new SystemStatisticsState(); |
| 1525 | SystemStatistics returnStats; |
| 1526 | |
| 1527 | double nowTime = timer(); |
| 1528 | double nowClockProcess = getProcessorTimeProcess(); |
| 1529 | double nowClockThread = getProcessorTimeThread(); |
| 1530 | returnStats.elapsed = nowTime - (*statState)->lastTime; |
| 1531 | |
| 1532 | returnStats.initialized = (*statState)->lastTime != 0; |
| 1533 | if (returnStats.initialized) { |
| 1534 | returnStats.processCPUSeconds = (nowClockProcess - (*statState)->lastClockProcess); |
| 1535 | returnStats.mainThreadCPUSeconds = (nowClockThread - (*statState)->lastClockThread); |
| 1536 | } |
| 1537 | |
| 1538 | returnStats.processMemory = getMemoryUsage(); |
| 1539 | returnStats.processResidentMemory = getResidentMemoryUsage(); |
| 1540 | |
| 1541 | MachineRAMInfo memInfo; |
| 1542 | getMachineRAMInfo(memInfo); |
| 1543 | returnStats.machineTotalRAM = memInfo.total; |
| 1544 | returnStats.machineCommittedRAM = memInfo.committed; |
| 1545 | returnStats.machineAvailableRAM = memInfo.available; |
| 1546 | |
| 1547 | if (dataFolder != "") { |
| 1548 | int64_t diskTotal, diskFree; |
| 1549 | getDiskBytes(dataFolder, diskFree, diskTotal); |
| 1550 | returnStats.processDiskTotalBytes = diskTotal; |
| 1551 | returnStats.processDiskFreeBytes = diskFree; |
| 1552 | } |
| 1553 | |
| 1554 | #if defined(_WIN32) |
| 1555 | if ((*statState)->Query == nullptr) { |
| 1556 | initPdhStrings(*statState, dataFolder); |
| 1557 | |
| 1558 | TraceEvent("SetupQuery").log(); |
| 1559 | handlePdhStatus(PdhOpenQuery(nullptr, NULL, &(*statState)->Query), "PdhOpenQuery"); |
| 1560 | |
| 1561 | if (!(*statState)->pdhStrings.diskDevice.empty()) { |
| 1562 | handlePdhStatus( |
| 1563 | PdhAddCounter((*statState)->Query, |
| 1564 | ("\\" + (*statState)->pdhStrings.physicalDisk + "(" + |
| 1565 | (*statState)->pdhStrings.diskDevice + ")\\" + (*statState)->pdhStrings.pctIdle) |
| 1566 | .c_str(), |
| 1567 | 0, |
| 1568 | &(*statState)->DiskTimeCounter), |
| 1569 | "PdhAddCounter"); |
| 1570 | handlePdhStatus( |
| 1571 | PdhAddCounter((*statState)->Query, |
| 1572 | ("\\" + (*statState)->pdhStrings.physicalDisk + "(" + |
| 1573 | (*statState)->pdhStrings.diskDevice + ")\\" + (*statState)->pdhStrings.diskQueueLength) |
| 1574 | .c_str(), |
| 1575 | 0, |
| 1576 | &(*statState)->QueueLengthCounter), |
nothing calls this directly
no test coverage detected