• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_PROFILING_PERF_COMMON_TYPES_H_
18 #define SRC_PROFILING_PERF_COMMON_TYPES_H_
19 
20 #include <memory>
21 #include <vector>
22 
23 #include <linux/perf_event.h>
24 #include <stdint.h>
25 
26 #include <unwindstack/Error.h>
27 #include <unwindstack/Regs.h>
28 
29 #include "src/profiling/common/unwind_support.h"
30 
31 namespace perfetto {
32 namespace profiling {
33 
34 // Data present in all types of samples.
35 struct CommonSampleData {
36   uint16_t cpu_mode = PERF_RECORD_MISC_CPUMODE_UNKNOWN;
37   uint32_t cpu = 0;
38   pid_t pid = 0;
39   pid_t tid = 0;
40   uint64_t timestamp = 0;
41   uint64_t timebase_count = 0;
42 };
43 
44 // A parsed perf sample record (PERF_RECORD_SAMPLE from the kernel buffer).
45 // Self-contained, used as as input to the callstack unwinding.
46 struct ParsedSample {
47   // move-only
48   ParsedSample() = default;
49   ParsedSample(const ParsedSample&) = delete;
50   ParsedSample& operator=(const ParsedSample&) = delete;
51   ParsedSample(ParsedSample&&) noexcept = default;
52   ParsedSample& operator=(ParsedSample&&) noexcept = default;
53 
54   CommonSampleData common;
55   std::unique_ptr<unwindstack::Regs> regs;
56   std::vector<char> stack;
57   bool stack_maxed = false;
58   std::vector<uint64_t> kernel_ips;
59 };
60 
61 // Entry in an unwinding queue. Either a sample that requires unwinding, or a
62 // tombstoned entry (valid == false).
63 struct UnwindEntry {
InvalidUnwindEntry64   static UnwindEntry Invalid() { return UnwindEntry{}; }
65 
66   UnwindEntry() = default;  // for initial unwinding queue entries' state
67 
UnwindEntryUnwindEntry68   UnwindEntry(uint64_t _data_source_id, ParsedSample _sample)
69       : valid(true),
70         data_source_id(_data_source_id),
71         sample(std::move(_sample)) {}
72 
73   bool valid = false;
74   uint64_t data_source_id = 0;
75   ParsedSample sample;
76 };
77 
78 // Fully processed sample that is ready for output.
79 struct CompletedSample {
80   // move-only
81   CompletedSample() = default;
82   CompletedSample(const CompletedSample&) = delete;
83   CompletedSample& operator=(const CompletedSample&) = delete;
84   CompletedSample(CompletedSample&&) noexcept = default;
85   CompletedSample& operator=(CompletedSample&&) noexcept = default;
86 
87   CommonSampleData common;
88   std::vector<unwindstack::FrameData> frames;
89   std::vector<std::string> build_ids;
90   unwindstack::ErrorCode unwind_error = unwindstack::ERROR_NONE;
91 };
92 
93 }  // namespace profiling
94 }  // namespace perfetto
95 
96 #endif  // SRC_PROFILING_PERF_COMMON_TYPES_H_
97