Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. #include "CPUSnapshot.h"
  2.  
  3. #include <chrono>
  4. #include <thread>
  5. #include <iostream>
  6.  
  7. int main()
  8. {
  9. CPUSnapshot previousSnap;
  10. std::this_thread::sleep_for(std::chrono::milliseconds(1000));
  11. CPUSnapshot curSnap;
  12.  
  13. const float ACTIVE_TIME = curSnap.GetActiveTimeTotal() - previousSnap.GetActiveTimeTotal();
  14. const float IDLE_TIME = curSnap.GetIdleTimeTotal() - previousSnap.GetIdleTimeTotal();
  15. const float TOTAL_TIME = ACTIVE_TIME + IDLE_TIME;
  16. int usage = 100.f * ACTIVE_TIME / TOTAL_TIME;
  17. std::cout << "total cpu usage: " << usage << std::endl;
  18. }
  19.  
  20. g++ -std=c++11 -o CPUUsage main.cpp CPUSnapshot.cpp CPUData.cpp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement