xref: /aosp_15_r20/external/perfetto/src/trace_processor/importers/proto/v8_sequence_state.h (revision 6dbdd20afdafa5e3ca9b8809fa73465d530080dc)
1 /*
2  * Copyright (C) 2024 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_V8_SEQUENCE_STATE_H_
18 #define SRC_TRACE_PROCESSOR_IMPORTERS_PROTO_V8_SEQUENCE_STATE_H_
19 
20 #include <cstdint>
21 #include <optional>
22 
23 #include "perfetto/ext/base/flat_hash_map.h"
24 #include "src/trace_processor/importers/proto/packet_sequence_state_generation.h"
25 #include "src/trace_processor/storage/trace_storage.h"
26 #include "src/trace_processor/tables/v8_tables_py.h"
27 
28 namespace perfetto {
29 namespace trace_processor {
30 
31 class TraceProcessorContext;
32 class V8Tracker;
33 
34 // Helper class to deal with V8 related interned data.
35 class V8SequenceState final
36     : public PacketSequenceStateGeneration::CustomState {
37  public:
38   explicit V8SequenceState(TraceProcessorContext* context);
39 
40   ~V8SequenceState() override;
41 
42   std::optional<tables::V8IsolateTable::Id> GetOrInsertIsolate(uint64_t iid);
43   std::optional<tables::V8JsFunctionTable::Id> GetOrInsertJsFunction(
44       uint64_t iid,
45       tables::V8IsolateTable::Id isolate_id);
46   std::optional<tables::V8WasmScriptTable::Id> GetOrInsertWasmScript(
47       uint64_t iid,
48       tables::V8IsolateTable::Id isolate_id);
49 
50  private:
51   std::optional<tables::V8JsScriptTable::Id> GetOrInsertJsScript(
52       uint64_t iid,
53       tables::V8IsolateTable::Id isolate_id);
54   std::optional<StringId> GetOrInsertJsFunctionName(uint64_t iid);
55 
56   TraceProcessorContext* const context_;
57   V8Tracker* const v8_tracker_;
58 
59   using InterningId = uint64_t;
60   base::FlatHashMap<InterningId, std::optional<tables::V8IsolateTable::Id>>
61       isolates_;
62   base::FlatHashMap<InterningId, tables::V8JsScriptTable::Id> js_scripts_;
63   base::FlatHashMap<InterningId, tables::V8WasmScriptTable::Id> wasm_scripts_;
64   base::FlatHashMap<InterningId, tables::V8JsFunctionTable::Id> js_functions_;
65   base::FlatHashMap<InterningId, StringId> js_function_names_;
66 };
67 
68 }  // namespace trace_processor
69 }  // namespace perfetto
70 
71 #endif  // SRC_TRACE_PROCESSOR_IMPORTERS_PROTO_V8_SEQUENCE_STATE_H_
72