1 /* 2 * Copyright (C) 2024 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_TRACE_PROCESSOR_IMPORTERS_PERF_SAMPLE_H_ 18 #define SRC_TRACE_PROCESSOR_IMPORTERS_PERF_SAMPLE_H_ 19 20 #include <cstdint> 21 #include <optional> 22 #include <vector> 23 24 #include "perfetto/base/status.h" 25 #include "perfetto/trace_processor/ref_counted.h" 26 #include "protos/perfetto/trace/profiling/profile_packet.pbzero.h" 27 #include "src/trace_processor/importers/perf/perf_event_attr.h" 28 #include "src/trace_processor/importers/perf/perf_session.h" 29 30 namespace perfetto::trace_processor::perf_importer { 31 32 struct Record; 33 34 struct Sample { 35 struct Frame { 36 protos::pbzero::Profiling::CpuMode cpu_mode; 37 uint64_t ip; 38 }; 39 40 struct PidTid { 41 uint32_t pid; 42 uint32_t tid; 43 }; 44 45 struct ReadGroup { 46 std::optional<uint64_t> event_id; 47 uint64_t value; 48 }; 49 50 int64_t trace_ts; 51 protos::pbzero::Profiling::CpuMode cpu_mode; 52 RefPtr<PerfSession> perf_session; 53 RefPtr<PerfEventAttr> attr; 54 55 std::optional<uint64_t> ip; 56 std::optional<PidTid> pid_tid; 57 std::optional<uint64_t> time; 58 std::optional<uint64_t> addr; 59 std::optional<uint64_t> id; 60 std::optional<uint64_t> stream_id; 61 std::optional<uint32_t> cpu; 62 std::optional<uint64_t> period; 63 std::vector<ReadGroup> read_groups; 64 std::vector<Frame> callchain; 65 66 base::Status Parse(int64_t trace_ts, const Record& record); 67 }; 68 69 } // namespace perfetto::trace_processor::perf_importer 70 71 #endif // SRC_TRACE_PROCESSOR_IMPORTERS_PERF_SAMPLE_H_ 72