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 #include "src/traced/probes/common/cpu_freq_info_for_testing.h"
18
19 #include <memory>
20
21 namespace perfetto {
22
23 namespace {
24
25 const char kCpuFrequenciesAndroidLittleCore[] =
26 "300000 576000 748800 998400 1209600 1324800 1516800 1612800 1708800 \n";
27
28 const char kCpuBoostFrequenciesAndroidLittleCore[] = "\n";
29
30 const char kCpuFrequenciesAndroidBigCore[] =
31 "300000 652800 825600 979200 1132800 1363200 1536000 1747200 1843200 "
32 "1996800 \n";
33
34 const char kCpuBoostFrequenciesAndroidBigCore[] = "2803200 \n";
35
36 } // namespace
37
CpuFreqInfoForTesting()38 CpuFreqInfoForTesting::CpuFreqInfoForTesting() {
39 // Create a subset of /sys/devices/system/cpu.
40 tmpdir_.AddDir("cpuidle");
41 tmpdir_.AddDir("cpu0");
42 tmpdir_.AddDir("cpu0/cpufreq");
43 tmpdir_.AddFile("cpu0/cpufreq/scaling_available_frequencies",
44 kCpuFrequenciesAndroidLittleCore);
45 tmpdir_.AddFile("cpu0/cpufreq/scaling_boost_frequencies",
46 kCpuBoostFrequenciesAndroidLittleCore);
47 tmpdir_.AddFile("cpu0/cpufreq/scaling_cur_freq", "2650000");
48 tmpdir_.AddDir("cpufreq");
49 tmpdir_.AddDir("cpu1");
50 tmpdir_.AddDir("cpu1/cpufreq");
51 tmpdir_.AddFile("cpu1/cpufreq/scaling_available_frequencies",
52 kCpuFrequenciesAndroidBigCore);
53 tmpdir_.AddFile("cpu1/cpufreq/scaling_boost_frequencies",
54 kCpuBoostFrequenciesAndroidBigCore);
55 tmpdir_.AddFile("cpu1/cpufreq/scaling_cur_freq", "3698200");
56 tmpdir_.AddDir("power");
57 }
58
GetInstance()59 std::unique_ptr<CpuFreqInfo> CpuFreqInfoForTesting::GetInstance() {
60 return std::unique_ptr<CpuFreqInfo>(new CpuFreqInfo(tmpdir_.path()));
61 }
62
63 } // namespace perfetto
64