1 /* 2 * Copyright (C) 2021 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_PROTO_PERF_SAMPLE_TRACKER_H_ 18 #define SRC_TRACE_PROCESSOR_IMPORTERS_PROTO_PERF_SAMPLE_TRACKER_H_ 19 20 #include <cstdint> 21 #include <unordered_map> 22 #include <utility> 23 #include <vector> 24 25 #include "src/trace_processor/importers/common/args_tracker.h" 26 #include "src/trace_processor/storage/trace_storage.h" 27 #include "src/trace_processor/tables/profiler_tables_py.h" 28 29 namespace perfetto { 30 31 namespace protos::pbzero { 32 class TracePacketDefaults_Decoder; 33 } // namespace protos::pbzero 34 35 namespace trace_processor { 36 class TraceProcessorContext; 37 38 class PerfSampleTracker { 39 public: 40 struct SamplingStreamInfo { 41 tables::PerfSessionTable::Id perf_session_id; 42 TrackId timebase_track_id = kInvalidTrackId; 43 std::vector<TrackId> follower_track_ids; 44 SamplingStreamInfoSamplingStreamInfo45 SamplingStreamInfo(tables::PerfSessionTable::Id _perf_session_id, 46 TrackId _timebase_track_id, 47 std::vector<TrackId> _follower_track_ids) 48 : perf_session_id(_perf_session_id), 49 timebase_track_id(_timebase_track_id), 50 follower_track_ids(std::move(_follower_track_ids)) {} 51 }; 52 53 explicit PerfSampleTracker(TraceProcessorContext* context); 54 55 SamplingStreamInfo GetSamplingStreamInfo( 56 uint32_t seq_id, 57 uint32_t cpu, 58 protos::pbzero::TracePacketDefaults_Decoder* nullable_defaults); 59 60 private: 61 struct CpuSequenceState { 62 TrackId timebase_track_id = kInvalidTrackId; 63 std::vector<TrackId> follower_track_ids; 64 CpuSequenceStateCpuSequenceState65 CpuSequenceState(TrackId _timebase_track_id, 66 std::vector<TrackId> _follower_track_ids) 67 : timebase_track_id(_timebase_track_id), 68 follower_track_ids(std::move(_follower_track_ids)) {} 69 }; 70 71 struct SequenceState { 72 tables::PerfSessionTable::Id perf_session_id; 73 std::unordered_map<uint32_t, CpuSequenceState> per_cpu; 74 SequenceStateSequenceState75 explicit SequenceState(tables::PerfSessionTable::Id _perf_session_id) 76 : perf_session_id(_perf_session_id) {} 77 }; 78 79 tables::PerfSessionTable::Id CreatePerfSession(); 80 81 std::unordered_map<uint32_t, SequenceState> seq_state_; 82 const StringId is_timebase_id_; 83 TraceProcessorContext* const context_; 84 }; 85 86 } // namespace trace_processor 87 } // namespace perfetto 88 89 #endif // SRC_TRACE_PROCESSOR_IMPORTERS_PROTO_PERF_SAMPLE_TRACKER_H_ 90