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 private: 39 // All frequencies of all CPUs, ordered by CPU and frequency. Includes a guard 40 // at the end. 41 std::vector<uint32_t> frequencies_; 42 // frequencies_index_[cpu] points to first frequency in frequencies_. Includes 43 // a guard at the end. 44 std::vector<size_t> frequencies_index_; 45 46 std::string ReadFile(std::string path); 47 }; 48 49 } // namespace perfetto 50 51 #endif // SRC_TRACED_PROBES_COMMON_CPU_FREQ_INFO_H_ 52