GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — async-profiler/src/processSampler.cpp at v4.3 · async-profiler/async-profiler Expand file tree/ Copy pathprocessSampler.cppMore file actions 79 lines (65 loc) · 2.79 KB / Copy pathprocessSampler.cppFile metadata and controls79 lines (65 loc) · 2.79 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 /* * Copyright The async-profiler authors * SPDX-License-Identifier: Apache-2.0 */ #include "processSampler.h" #include <unordered_set> const float MIN_CPU_THRESHOLD = 0.05f; // Minimum 5% cpu utilization to include results const float MIN_RSS_THRESHOLD = 0.05f; // Minimum 5% rss usage to include results u64 ProcessSampler::_last_sample_time = 0; std::unordered_map<int, ProcessHistory> ProcessSampler::_process_history; double ProcessSampler::getRssUsageRatio(const ProcessInfo& info) { const u64 ram_size = OS::getRamSize(); if (ram_size == 0 || info.vm_rss == 0) return 0.0; return (double)info.vm_rss / ram_size; } bool ProcessSampler::shouldIncludeProcess(const ProcessInfo& info) { return info.cpu_percent >= MIN_CPU_THRESHOLD || getRssUsageRatio(info) >= MIN_RSS_THRESHOLD; } bool ProcessSampler::populateCpuPercent(ProcessInfo& info, const u64 sampling_time) { const float current_cpu_total = info.cpu_user + info.cpu_system; ProcessHistory& history = _process_history[info.pid]; if (history.prev_timestamp == 0 || history.start_time != info.start_time) { history.prev_cpu_total = current_cpu_total; history.prev_timestamp = sampling_time; history.start_time = info.start_time; return false; } const float delta_cpu = current_cpu_total - history.prev_cpu_total; const u64 delta_time = sampling_time - history.prev_timestamp; info.cpu_percent = delta_cpu * 1e9f / delta_time; history.prev_cpu_total = current_cpu_total; history.prev_timestamp = sampling_time; return true; } int ProcessSampler::sample(u64 wall_time) { const int pid_count = OS::getProcessIds(_pids, MAX_PROCESSES); cleanupProcessHistory(pid_count); _last_sample_time = wall_time; return pid_count; } void ProcessSampler::cleanupProcessHistory(const int pid_count) { const std::unordered_set<int> active_pid_set(_pids, _pids + pid_count); for (auto it = _process_history.begin(); it != _process_history.end();) { if (active_pid_set.count(it->first) == 0) { it = _process_history.erase(it); } else { ++it; } } } void ProcessSampler::enable(const long sampling_interval) { if (_sampling_interval != sampling_interval) { _sampling_interval = sampling_interval; _last_sample_time = 0; _process_history.clear(); } } bool ProcessSampler::shouldSample(const u64 wall_time) const { return _sampling_interval > 0 && wall_time >= _last_sample_time + _sampling_interval; } bool ProcessSampler::getProcessInfo(int pid_index, u64 sampling_time, ProcessInfo& info) { const int pid = _pids[pid_index]; return OS::getBasicProcessInfo(pid, &info) && populateCpuPercent(info, sampling_time) && shouldIncludeProcess(info) && OS::getDetailedProcessInfo(&info); } |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |