system_information_sampler.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Copyright 2016 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef TOOLS_WIN_IDLEWAKEUPS_SYSTEM_INFORMATION_SAMPLER_H_
  5. #define TOOLS_WIN_IDLEWAKEUPS_SYSTEM_INFORMATION_SAMPLER_H_
  6. #include <map>
  7. #include <memory>
  8. #include <vector>
  9. #include <windows.h>
  10. // SYSTEM_PROCESS_INFORMATION and SYSTEM_THREAD_INFORMATION structures
  11. // use HANDLE for the thread / process IDs.
  12. typedef HANDLE ThreadId;
  13. typedef HANDLE ProcessId;
  14. // Contains per thread data stored in each data snapshot.
  15. struct ThreadData {
  16. ThreadId thread_id;
  17. ULONG context_switches;
  18. };
  19. typedef std::vector<ThreadData> ThreadsVector;
  20. // Contains per process data stored in each data snapshot.
  21. struct ProcessData {
  22. ULONGLONG cpu_time;
  23. ULONGLONG working_set;
  24. ThreadsVector threads;
  25. };
  26. typedef std::map<ProcessId, ProcessData> ProcessDataMap;
  27. struct ProcessDataSnapshot {
  28. ProcessDataMap processes;
  29. double timestamp;
  30. };
  31. class SystemInformationSampler {
  32. public:
  33. SystemInformationSampler(const wchar_t* process_name);
  34. ~SystemInformationSampler();
  35. std::unique_ptr<ProcessDataSnapshot> TakeSnapshot();
  36. const wchar_t* target_process_name_filter() const {
  37. return target_process_name_;
  38. }
  39. private:
  40. wchar_t target_process_name_[256] = {};
  41. LARGE_INTEGER perf_frequency_;
  42. LARGE_INTEGER initial_counter_;
  43. size_t previous_buffer_size_ = 0;
  44. SystemInformationSampler& operator=(const SystemInformationSampler&) = delete;
  45. SystemInformationSampler(const SystemInformationSampler&) = delete;
  46. };
  47. #endif // TOOLS_WIN_IDLEWAKEUPS_SYSTEM_INFORMATION_SAMPLER_H_