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_JIT_TRACKER_H_ 18 #define SRC_TRACE_PROCESSOR_IMPORTERS_PROTO_JIT_TRACKER_H_ 19 20 #include <cstdint> 21 #include <memory> 22 23 #include "perfetto/ext/base/flat_hash_map.h" 24 #include "src/trace_processor/importers/common/address_range.h" 25 #include "src/trace_processor/importers/common/stack_profile_tracker.h" 26 #include "src/trace_processor/storage/trace_storage.h" 27 #include "src/trace_processor/types/destructible.h" 28 #include "src/trace_processor/types/trace_processor_context.h" 29 30 namespace perfetto::trace_processor { 31 32 class JitCache; 33 34 // Keeps track of Jitted code. 35 class JitTracker : public Destructible { 36 public: GetOrCreate(TraceProcessorContext * context)37 static JitTracker* GetOrCreate(TraceProcessorContext* context) { 38 if (!context->jit_tracker) { 39 context->jit_tracker.reset(new JitTracker(context)); 40 } 41 return static_cast<JitTracker*>(context->jit_tracker.get()); 42 } 43 44 ~JitTracker() override; 45 46 // Creates a JitCache. Any frame interning request for the given pid in the 47 // given address range will be forwarded from the StackProfileTracker to this 48 // cache. 49 JitCache* CreateJitCache(std::string name, 50 UniquePid upid, 51 AddressRange range); 52 53 private: 54 explicit JitTracker(TraceProcessorContext* context); 55 56 FrameId InternUnknownFrame(MappingId mapping_id, uint64_t rel_pc); 57 58 TraceProcessorContext* const context_; 59 60 base::FlatHashMap<UniquePid, AddressRangeMap<std::unique_ptr<JitCache>>> 61 caches_; 62 }; 63 64 } // namespace perfetto::trace_processor 65 66 #endif // SRC_TRACE_PROCESSOR_IMPORTERS_PROTO_JIT_TRACKER_H_ 67