#ifndef KYTY_COMMON_HOST_STATS_H_ #define KYTY_COMMON_HOST_STATS_H_ #include #include #include #include #include namespace Common { enum class MemoryPressure { Unknown, Normal, Warning, Critical }; enum class ThermalPressure { Unknown, Nominal, Moderate, Heavy, Critical }; struct ThreadUsage { std::string name; double cpu_percent = 0.0; // Of one core. }; // Host-wide and process-wide resource usage. Missing values are std::nullopt; rates are per // second since the previous sample. struct HostStats { uint32_t logical_cores = 0; // Processing. std::optional process_cpu_percent; // Share of all logical cores, 0-100. std::optional system_cpu_percent; // Whole machine, 0-100. std::optional thread_count; std::vector busiest_threads; // Busiest first. std::optional context_switches_per_s; std::optional page_faults_per_s; std::optional page_ins_per_s; // Faults that read from disk. ThermalPressure thermal_pressure = ThermalPressure::Unknown; // Emulator process memory. std::optional process_memory; // Physical footprint / resident set. std::optional process_resident; std::optional process_compressed; // Compressed or swapped out. std::optional process_file_backed; std::optional process_virtual; // Reserved address space. // System memory. std::optional system_memory_used; std::optional system_memory_total; std::optional system_wired; std::optional system_compressed; std::optional system_cached; // File cache, reclaimable. std::optional system_free; std::optional swap_used; std::optional swap_total; MemoryPressure memory_pressure = MemoryPressure::Unknown; // Disk I/O of the emulator process. std::optional disk_read_per_s; std::optional disk_write_per_s; // GPU, whole device (macOS IOAccelerator). std::string gpu_model; std::optional gpu_cores; std::optional gpu_percent; std::optional gpu_renderer_percent; std::optional gpu_tiler_percent; std::optional gpu_memory_in_use; // System memory the GPU driver has in use. std::optional gpu_memory_allocated; std::optional gpu_recoveries; // GPU resets since boot. }; // May block for a few milliseconds (thread enumeration, OS registry reads), so call it off the // render thread. The first sample has no rates. class HostStatsSampler final { public: HostStatsSampler(); ~HostStatsSampler(); HostStatsSampler(const HostStatsSampler&) = delete; HostStatsSampler& operator=(const HostStatsSampler&) = delete; [[nodiscard]] HostStats Sample(); private: struct Impl; std::unique_ptr m_impl; }; } // namespace Common #endif /* KYTY_COMMON_HOST_STATS_H_ */