data_source.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Copyright 2020 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 ASH_HUD_DISPLAY_DATA_SOURCE_H_
  5. #define ASH_HUD_DISPLAY_DATA_SOURCE_H_
  6. #include <cstdint>
  7. #include <limits>
  8. #include "ash/hud_display/cpu_stats.h"
  9. namespace ash {
  10. namespace hud_display {
  11. // This is source of data to draw the HUD display.
  12. class DataSource {
  13. public:
  14. struct Snapshot {
  15. Snapshot();
  16. Snapshot(const Snapshot&);
  17. Snapshot& operator=(const Snapshot&);
  18. // All memory sizes are in bytes.
  19. // Separate non-zero-initialized members from zero-initialized.
  20. int64_t free_ram{std::numeric_limits<int64_t>::max()};
  21. int64_t physical_ram = 0; // Amount of physical RAM installed.
  22. int64_t total_ram = 0; // As reported in /proc/meminfo.
  23. // Amount of RSS Private memory used by "/android" cgroup.
  24. int64_t arc_rss = 0;
  25. // Amount of RSS Shared memory used by "/android" cgroup.
  26. int64_t arc_rss_shared = 0;
  27. // Amount of RSS Private memory used by Chrome browser process.
  28. int64_t browser_rss = 0;
  29. // Amount of RSS Shared memory used by Chrome browser process.
  30. int64_t browser_rss_shared = 0;
  31. // Amount of GPU memory used by kernel GPU driver.
  32. int64_t gpu_kernel = 0;
  33. // Amount of RSS Private memory used by Chrome GPU process.
  34. int64_t gpu_rss = 0;
  35. // Amount of RSS Shared memory used by Chrome GPU process.
  36. int64_t gpu_rss_shared = 0;
  37. // Amount of RSS Private memory used by Chrome type=renderer processes.
  38. int64_t renderers_rss = 0;
  39. // Amount of RSS Shared memory used by Chrome type=renderer processes.
  40. int64_t renderers_rss_shared = 0;
  41. // CPU stats are calculated only in GetSnapshotAndReset().
  42. // CPU usage values should sum to 1.
  43. float cpu_idle_part = 0; // Amount spent in idle state.
  44. float cpu_user_part = 0; // Amount spent in user + nice mode.
  45. float cpu_system_part = 0; // Amount spent in system mode.
  46. float cpu_other_part = 0; // Other states: irq, etc.
  47. };
  48. DataSource();
  49. DataSource(const DataSource&) = delete;
  50. DataSource& operator=(const DataSource&) = delete;
  51. ~DataSource();
  52. // This must be called on io-enabled thread.
  53. Snapshot GetSnapshotAndReset();
  54. private:
  55. void Refresh();
  56. Snapshot GetSnapshot() const;
  57. void ResetCounters();
  58. // Current system snapshot.
  59. Snapshot snapshot_;
  60. // Last CPU stats snapshot.
  61. CpuStats cpu_stats_latest_;
  62. // Last stats before Reset() to calculate delta.
  63. CpuStats cpu_stats_base_;
  64. };
  65. } // namespace hud_display
  66. } // namespace ash
  67. #endif // ASH_HUD_DISPLAY_DATA_SOURCE_H_