1 /* 2 * Copyright (C) 2020 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef SRC_TRACED_PROBES_COMMON_CPU_FREQ_INFO_H_ 18 #define SRC_TRACED_PROBES_COMMON_CPU_FREQ_INFO_H_ 19 20 #include <map> 21 #include <string> 22 #include <vector> 23 24 #include "perfetto/ext/base/scoped_file.h" 25 26 namespace perfetto { 27 28 class CpuFreqInfo { 29 public: 30 explicit CpuFreqInfo(std::string cpu_dir_path = "/sys/devices/system/cpu"); 31 virtual ~CpuFreqInfo(); 32 33 using Range = 34 std::pair</* begin */ const uint32_t*, /* end */ const uint32_t*>; 35 Range GetFreqs(uint32_t cpu); 36 uint32_t GetCpuFreqIndex(uint32_t cpu, uint32_t freq); 37 38 const std::vector<uint32_t>& ReadCpuCurrFreq(); 39 40 private: 41 // e.g. /sys/devices/system/cpu 42 std::string sysfs_cpu_path_; 43 // All frequencies of all CPUs, ordered by CPU and frequency. Includes a guard 44 // at the end. 45 std::vector<uint32_t> frequencies_; 46 // frequencies_index_[cpu] points to first frequency in frequencies_. Includes 47 // a guard at the end. 48 std::vector<size_t> frequencies_index_; 49 // Placeholder for CPU current frequency, refresh in ReadCpuCurrFreq() 50 std::vector<uint32_t> cpu_curr_freq_; 51 52 std::string ReadFile(std::string path); 53 }; 54 55 } // namespace perfetto 56 57 #endif // SRC_TRACED_PROBES_COMMON_CPU_FREQ_INFO_H_ 58