• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <unordered_map>
23 
24 #include "src/trace_processor/storage/trace_storage.h"
25 
26 namespace perfetto {
27 namespace protos {
28 namespace pbzero {
29 class TracePacketDefaults_Decoder;
30 }  // namespace pbzero
31 }  // namespace protos
32 namespace trace_processor {
33 class TraceProcessorContext;
34 
35 class PerfSampleTracker {
36  public:
37   struct SamplingStreamInfo {
38     uint32_t perf_session_id = 0;
39     TrackId timebase_track_id = kInvalidTrackId;
40 
SamplingStreamInfoSamplingStreamInfo41     SamplingStreamInfo(uint32_t _perf_session_id, TrackId _timebase_track_id)
42         : perf_session_id(_perf_session_id),
43           timebase_track_id(_timebase_track_id) {}
44   };
45 
PerfSampleTracker(TraceProcessorContext * context)46   explicit PerfSampleTracker(TraceProcessorContext* context)
47       : context_(context) {}
48 
49   SamplingStreamInfo GetSamplingStreamInfo(
50       uint32_t seq_id,
51       uint32_t cpu,
52       protos::pbzero::TracePacketDefaults_Decoder* nullable_defaults);
53 
54  private:
55   struct CpuSequenceState {
56     TrackId timebase_track_id = kInvalidTrackId;
57 
CpuSequenceStateCpuSequenceState58     CpuSequenceState(TrackId _timebase_track_id)
59         : timebase_track_id(_timebase_track_id) {}
60   };
61 
62   struct SequenceState {
63     uint32_t perf_session_id = 0;
64     std::unordered_map<uint32_t, CpuSequenceState> per_cpu;
65 
SequenceStateSequenceState66     SequenceState(uint32_t _perf_session_id)
67         : perf_session_id(_perf_session_id) {}
68   };
69 
70   std::unordered_map<uint32_t, SequenceState> seq_state_;
71   uint32_t next_perf_session_id_ = 0;
72 
73   TraceProcessorContext* const context_;
74 };
75 
76 }  // namespace trace_processor
77 }  // namespace perfetto
78 
79 #endif  // SRC_TRACE_PROCESSOR_IMPORTERS_PROTO_PERF_SAMPLE_TRACKER_H_
80