1 /**
2 * Copyright (c) 2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "profiling_loader.h"
17 #include "libprofile/pgo_file_builder.h"
18
19 namespace ark {
LoadProfile(const PandaString & fileName)20 Expected<PandaString, PandaString> ProfilingLoader::LoadProfile(const PandaString &fileName)
21 {
22 PandaString classCtxStr;
23 auto resOrError = pgo::AotPgoFile::Load(fileName, classCtxStr, pandaFiles_);
24 if (!resOrError) {
25 return Unexpected(resOrError.Error());
26 }
27 aotProfilingData_ = std::move(*resOrError);
28 return classCtxStr;
29 }
30
CreateBranchData(void * branchesMem,Span<const pgo::AotProfilingData::AotBranchData> aotBranchData)31 Span<BranchData> ProfilingLoader::CreateBranchData(void *branchesMem,
32 Span<const pgo::AotProfilingData::AotBranchData> aotBranchData)
33 {
34 auto branchData = Span(reinterpret_cast<BranchData *>(branchesMem), aotBranchData.size());
35 for (size_t i = 0; i < aotBranchData.size(); i++) {
36 branchData[i].Init(aotBranchData[i].pc, aotBranchData[i].taken, aotBranchData[i].notTaken);
37 }
38
39 return branchData;
40 }
41
CreateThrowData(void * throwsMem,Span<const pgo::AotProfilingData::AotThrowData> aotThrowData)42 Span<ThrowData> ProfilingLoader::CreateThrowData(void *throwsMem,
43 Span<const pgo::AotProfilingData::AotThrowData> aotThrowData)
44 {
45 auto throwData = Span(reinterpret_cast<ThrowData *>(throwsMem), aotThrowData.size());
46 for (size_t i = 0; i < aotThrowData.size(); i++) {
47 throwData[i].Init(aotThrowData[i].pc, aotThrowData[i].taken);
48 }
49
50 return throwData;
51 }
52 } // namespace ark
53