1 /*
2  * Copyright (C) 2018 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_TYPES_TRACE_PROCESSOR_CONTEXT_H_
18 #define SRC_TRACE_PROCESSOR_TYPES_TRACE_PROCESSOR_CONTEXT_H_
19 
20 #include <memory>
21 #include <vector>
22 
23 #include "perfetto/trace_processor/basic_types.h"
24 #include "src/trace_processor/types/destructible.h"
25 
26 namespace perfetto {
27 namespace trace_processor {
28 
29 class ArgsTracker;
30 class AsyncTrackSetTracker;
31 class AndroidProbesTracker;
32 class ChunkedTraceReader;
33 class ClockTracker;
34 class EventTracker;
35 class ForwardingTraceParser;
36 class FtraceModule;
37 class GlobalArgsTracker;
38 class GlobalStackProfileTracker;
39 class HeapGraphTracker;
40 class HeapProfileTracker;
41 class MetadataTracker;
42 class ProtoImporterModule;
43 class ProcessTracker;
44 class SliceTracker;
45 class FlowTracker;
46 class TraceParser;
47 class TraceSorter;
48 class TraceStorage;
49 class TrackTracker;
50 class JsonTracker;
51 class ProtoToArgsTable;
52 
53 class TraceProcessorContext {
54  public:
55   TraceProcessorContext();
56   ~TraceProcessorContext();
57 
58   Config config;
59 
60   std::unique_ptr<TraceStorage> storage;
61 
62   std::unique_ptr<ChunkedTraceReader> chunk_reader;
63   std::unique_ptr<TraceSorter> sorter;
64 
65   // Keep the global tracker before the args tracker as we access the global
66   // tracker in the destructor of the args tracker. Also keep it before other
67   // trackers, as they may own ArgsTrackers themselves.
68   std::unique_ptr<GlobalArgsTracker> global_args_tracker;
69   std::unique_ptr<ArgsTracker> args_tracker;
70 
71   std::unique_ptr<TrackTracker> track_tracker;
72   std::unique_ptr<AsyncTrackSetTracker> async_track_set_tracker;
73   std::unique_ptr<SliceTracker> slice_tracker;
74   std::unique_ptr<FlowTracker> flow_tracker;
75   std::unique_ptr<ProcessTracker> process_tracker;
76   std::unique_ptr<EventTracker> event_tracker;
77   std::unique_ptr<ClockTracker> clock_tracker;
78   std::unique_ptr<HeapProfileTracker> heap_profile_tracker;
79   std::unique_ptr<GlobalStackProfileTracker> global_stack_profile_tracker;
80   std::unique_ptr<MetadataTracker> metadata_tracker;
81 
82   // These fields are stored as pointers to Destructible objects rather than
83   // their actual type (a subclass of Destructible), as the concrete subclass
84   // type is only available in storage_full target. To access these fields use
85   // the GetOrCreate() method on their subclass type, e.g.
86   // SyscallTracker::GetOrCreate(context)
87   std::unique_ptr<Destructible> android_probes_tracker;  // AndroidProbesTracker
88   std::unique_ptr<Destructible> syscall_tracker;         // SyscallTracker
89   std::unique_ptr<Destructible> sched_tracker;           // SchedEventTracker
90   std::unique_ptr<Destructible> binder_tracker;          // BinderTracker
91   std::unique_ptr<Destructible> systrace_parser;         // SystraceParser
92   std::unique_ptr<Destructible> heap_graph_tracker;      // HeapGraphTracker
93   std::unique_ptr<Destructible> json_tracker;            // JsonTracker
94   std::unique_ptr<Destructible> system_info_tracker;     // SystemInfoTracker
95 
96   // These fields are trace readers which will be called by |forwarding_parser|
97   // once the format of the trace is discovered. They are placed here as they
98   // are only available in the storage_full target.
99   std::unique_ptr<ChunkedTraceReader> json_trace_tokenizer;
100   std::unique_ptr<ChunkedTraceReader> fuchsia_trace_tokenizer;
101   std::unique_ptr<ChunkedTraceReader> systrace_trace_parser;
102   std::unique_ptr<ChunkedTraceReader> gzip_trace_parser;
103 
104   // These fields are trace parsers which will be called by |forwarding_parser|
105   // once the format of the trace is discovered. They are placed here as they
106   // are only available in the storage_full target.
107   std::unique_ptr<TraceParser> json_trace_parser;
108   std::unique_ptr<TraceParser> fuchsia_trace_parser;
109 
110   // Reflection-based proto parser used to convert TrackEvent fields into SQL.
111   std::unique_ptr<ProtoToArgsTable> proto_to_args_table_;
112 
113   // The module at the index N is registered to handle field id N in
114   // TracePacket.
115   std::vector<ProtoImporterModule*> modules_by_field;
116   std::vector<std::unique_ptr<ProtoImporterModule>> modules;
117   FtraceModule* ftrace_module = nullptr;
118 };
119 
120 }  // namespace trace_processor
121 }  // namespace perfetto
122 
123 #endif  // SRC_TRACE_PROCESSOR_TYPES_TRACE_PROCESSOR_CONTEXT_H_
124