1 /* 2 * Copyright (C) 2019 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_COMMON_PARSER_TYPES_H_ 18 #define SRC_TRACE_PROCESSOR_IMPORTERS_COMMON_PARSER_TYPES_H_ 19 20 #include <array> 21 #include <cstdint> 22 #include <functional> 23 #include <optional> 24 #include <string> 25 #include <utility> 26 #include <variant> 27 28 #include "perfetto/trace_processor/ref_counted.h" 29 #include "perfetto/trace_processor/trace_blob_view.h" 30 #include "src/trace_processor/containers/string_pool.h" 31 #include "src/trace_processor/importers/proto/packet_sequence_state_generation.h" 32 33 namespace perfetto::trace_processor { 34 35 struct alignas(8) InlineSchedSwitch { 36 int64_t prev_state; 37 int32_t next_pid; 38 int32_t next_prio; 39 StringPool::Id next_comm; 40 }; 41 static_assert(sizeof(InlineSchedSwitch) == 24); 42 43 // We enforce the exact size as it's critical for peak-memory use when sorting 44 // data in trace processor that this struct is as small as possible. 45 static_assert(sizeof(InlineSchedSwitch) == 24); 46 47 struct alignas(8) InlineSchedWaking { 48 int32_t pid; 49 uint16_t target_cpu; 50 uint16_t prio; 51 StringPool::Id comm; 52 uint16_t common_flags; 53 }; 54 55 // We enforce the exact size as it's critical for peak-memory use when sorting 56 // data in trace processor that this struct is as small as possible. 57 static_assert(sizeof(InlineSchedWaking) == 16); 58 59 struct alignas(8) JsonEvent { 60 struct Begin {}; 61 struct End {}; 62 struct Scoped { 63 int64_t dur; 64 }; 65 struct Other {}; 66 using Type = std::variant<Begin, End, Scoped, Other>; 67 68 std::string value; 69 Type type; 70 }; 71 static_assert(sizeof(JsonEvent) % 8 == 0); 72 73 struct alignas(8) TracePacketData { 74 TraceBlobView packet; 75 RefPtr<PacketSequenceStateGeneration> sequence_state; 76 }; 77 static_assert(sizeof(TracePacketData) % 8 == 0); 78 79 struct alignas(8) TrackEventData { TrackEventDataTrackEventData80 TrackEventData(TraceBlobView pv, 81 RefPtr<PacketSequenceStateGeneration> generation) 82 : trace_packet_data{std::move(pv), std::move(generation)} {} 83 TrackEventDataTrackEventData84 explicit TrackEventData(TracePacketData tpd) 85 : trace_packet_data(std::move(tpd)) {} 86 87 static constexpr uint8_t kMaxNumExtraCounters = 8; 88 CountExtraCounterValuesTrackEventData89 uint8_t CountExtraCounterValues() const { 90 for (uint8_t i = 0; i < TrackEventData::kMaxNumExtraCounters; ++i) { 91 if (std::equal_to<double>()(extra_counter_values[i], 0)) 92 return i; 93 } 94 return TrackEventData::kMaxNumExtraCounters; 95 } 96 97 TracePacketData trace_packet_data; 98 std::optional<int64_t> thread_timestamp; 99 std::optional<int64_t> thread_instruction_count; 100 double counter_value = 0; 101 std::array<double, kMaxNumExtraCounters> extra_counter_values = {}; 102 }; 103 static_assert(sizeof(TracePacketData) % 8 == 0); 104 105 struct alignas(8) LegacyV8CpuProfileEvent { 106 uint64_t session_id; 107 uint32_t pid; 108 uint32_t tid; 109 uint32_t callsite_id; 110 }; 111 static_assert(sizeof(LegacyV8CpuProfileEvent) % 8 == 0); 112 113 } // namespace perfetto::trace_processor 114 115 #endif // SRC_TRACE_PROCESSOR_IMPORTERS_COMMON_PARSER_TYPES_H_ 116