1 /*
2  * Copyright (C) 2018 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 #pragma once
18 
19 #include <unordered_map>
20 #include <vector>
21 
22 namespace android {
23 namespace bpf {
24 
25 bool isTrackingUidTimesSupported();
26 bool startTrackingUidTimes();
27 std::optional<std::vector<std::vector<uint64_t>>> getTotalCpuFreqTimes();
28 std::optional<std::vector<std::vector<uint64_t>>> getUidCpuFreqTimes(uint32_t uid);
29 std::optional<std::unordered_map<uint32_t, std::vector<std::vector<uint64_t>>>>
30     getUidsCpuFreqTimes();
31 std::optional<std::unordered_map<uint32_t, std::vector<std::vector<uint64_t>>>>
32     getUidsUpdatedCpuFreqTimes(uint64_t *lastUpdate);
33 std::optional<std::vector<std::vector<uint32_t>>> getCpuFreqs();
34 
35 struct concurrent_time_t {
36     std::vector<uint64_t> active;
37     std::vector<std::vector<uint64_t>> policy;
38 };
39 
40 std::optional<concurrent_time_t> getUidConcurrentTimes(uint32_t uid, bool retry = true);
41 std::optional<std::unordered_map<uint32_t, concurrent_time_t>> getUidsConcurrentTimes();
42 std::optional<std::unordered_map<uint32_t, concurrent_time_t>>
43     getUidsUpdatedConcurrentTimes(uint64_t *lastUpdate);
44 bool clearUidTimes(unsigned int uid);
45 
46 bool startTrackingProcessCpuTimes(pid_t pid);
47 bool startAggregatingTaskCpuTimes(pid_t pid, uint16_t aggregationKey);
48 std::optional<std::unordered_map<uint16_t, std::vector<std::vector<uint64_t>>>>
49 getAggregatedTaskCpuFreqTimes(pid_t pid, const std::vector<uint16_t> &aggregationKeys);
50 
51 } // namespace bpf
52 } // namespace android
53