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 <stdint.h> 21 22 #include <cstdint> 23 #include <unordered_map> 24 25 #include "src/trace_processor/storage/trace_storage.h" 26 #include "src/trace_processor/tables/profiler_tables_py.h" 27 28 namespace perfetto { 29 namespace protos { 30 namespace pbzero { 31 class TracePacketDefaults_Decoder; 32 } // namespace pbzero 33 } // namespace protos 34 namespace trace_processor { 35 class TraceProcessorContext; 36 37 class PerfSampleTracker { 38 public: 39 struct SamplingStreamInfo { 40 tables::PerfSessionTable::Id perf_session_id; 41 TrackId timebase_track_id = kInvalidTrackId; 42 SamplingStreamInfoSamplingStreamInfo43 SamplingStreamInfo(tables::PerfSessionTable::Id _perf_session_id, 44 TrackId _timebase_track_id) 45 : perf_session_id(_perf_session_id), 46 timebase_track_id(_timebase_track_id) {} 47 }; 48 PerfSampleTracker(TraceProcessorContext * context)49 explicit PerfSampleTracker(TraceProcessorContext* context) 50 : context_(context) {} 51 52 SamplingStreamInfo GetSamplingStreamInfo( 53 uint32_t seq_id, 54 uint32_t cpu, 55 protos::pbzero::TracePacketDefaults_Decoder* nullable_defaults); 56 57 private: 58 struct CpuSequenceState { 59 TrackId timebase_track_id = kInvalidTrackId; 60 CpuSequenceStateCpuSequenceState61 CpuSequenceState(TrackId _timebase_track_id) 62 : timebase_track_id(_timebase_track_id) {} 63 }; 64 65 struct SequenceState { 66 tables::PerfSessionTable::Id perf_session_id; 67 std::unordered_map<uint32_t, CpuSequenceState> per_cpu; 68 SequenceStateSequenceState69 explicit SequenceState(tables::PerfSessionTable::Id _perf_session_id) 70 : perf_session_id(_perf_session_id) {} 71 }; 72 73 tables::PerfSessionTable::Id CreatePerfSession(); 74 75 std::unordered_map<uint32_t, SequenceState> seq_state_; 76 77 TraceProcessorContext* const context_; 78 }; 79 80 } // namespace trace_processor 81 } // namespace perfetto 82 83 #endif // SRC_TRACE_PROCESSOR_IMPORTERS_PROTO_PERF_SAMPLE_TRACKER_H_ 84