xref: /aosp_15_r20/external/perfetto/src/trace_processor/importers/proto/jit_tracker.cc (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 #include "src/trace_processor/importers/proto/jit_tracker.h"
18 
19 #include <memory>
20 #include <string>
21 #include <utility>
22 
23 #include "perfetto/base/logging.h"
24 #include "src/trace_processor/importers/common/address_range.h"
25 #include "src/trace_processor/importers/common/jit_cache.h"
26 #include "src/trace_processor/importers/common/mapping_tracker.h"
27 #include "src/trace_processor/importers/common/stack_profile_tracker.h"
28 #include "src/trace_processor/storage/trace_storage.h"
29 #include "src/trace_processor/types/trace_processor_context.h"
30 
31 namespace perfetto::trace_processor {
32 
JitTracker(TraceProcessorContext * context)33 JitTracker::JitTracker(TraceProcessorContext* context) : context_(context) {}
34 JitTracker::~JitTracker() = default;
35 
CreateJitCache(std::string name,UniquePid upid,AddressRange range)36 JitCache* JitTracker::CreateJitCache(std::string name,
37                                      UniquePid upid,
38                                      AddressRange range) {
39   auto cache =
40       std::make_unique<JitCache>(context_, std::move(name), upid, range);
41   JitCache* cache_ptr = cache.get();
42   // Dealing with overlaps is complicated. Do we delete the entire range, only
43   // the overlap, how do we deal with requests to the old JitCache. And it
44   // doesn't really happen in practice (e.g. for v8 you would need to delete an
45   // isolate and recreate it.), so just make sure our assumption (this never
46   // happens) is correct with a check.
47   PERFETTO_CHECK(caches_[upid].Emplace(range, std::move(cache)));
48   context_->mapping_tracker->AddJitRange(upid, range, cache_ptr);
49   return cache_ptr;
50 }
51 
52 }  // namespace perfetto::trace_processor
53