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