• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2021-2024 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 #ifndef PANDA_RUNTIME_RELAYOUT_PROFILER_H
16 #define PANDA_RUNTIME_RELAYOUT_PROFILER_H
17 
18 #include <utility>
19 #include "runtime/include/mem/panda_containers.h"
20 #include "runtime/include/mem/panda_string.h"
21 #include "runtime/include/class.h"
22 #include "runtime/include/method.h"
23 
24 namespace ark {
25 class RelayoutProfiler {
26 public:
27     enum RelayoutItemType { CLASS_ITEM, STRING_ITEM, CODE_ITEM };
28     using ProfileDataType =
29         PandaUnorderedMap<PandaString, PandaUnorderedMap<RelayoutItemType, PandaSet<PandaString>, std::hash<int>>>;
30 
31     void WriteProfileData();
32     void AddProfileItem(const std::string &fileName, const std::string &item, RelayoutItemType type);
33     void AddProfileClassItem(Class *klass);
34     void AddProfileCodeItem(Method *method);
35     ProfileDataType *GetProfileData();
36 
37 private:
38     ProfileDataType relayoutItems_;
39 };
40 
41 #ifdef PANDA_ENABLE_RELAYOUT_PROFILE
42 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
43 #define ADD_PROFILE_CLASS_ITEM(...) Runtime::GetCurrent()->GetRelayoutProfiler()->AddProfileClassItem(__VA_ARGS__)
44 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
45 #define ADD_PROFILE_STRING_ITEM(...)                                          \
46     Runtime::GetCurrent()->GetRelayoutProfiler()->AddProfileItem(__VA_ARGS__, \
47                                                                  RelayoutProfiler::RelayoutItemType::STRING_ITEM)
48 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
49 #define ADD_PROFILE_CODE_ITEM(...) Runtime::GetCurrent()->GetRelayoutProfiler()->AddProfileCodeItem(__VA_ARGS__)
50 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
51 #define WRITE_RELAYOUT_PROFILE_DATA() Runtime::GetCurrent()->GetRelayoutProfiler()->WriteProfileData()
52 #else
53 #define ADD_PROFILE_CLASS_ITEM(...)
54 #define ADD_PROFILE_STRING_ITEM(...)
55 #define ADD_PROFILE_CODE_ITEM(...)
56 #define WRITE_RELAYOUT_PROFILE_DATA()
57 #endif
58 
59 using ProfileDataType =
60     PandaUnorderedMap<PandaString,
61                       PandaUnorderedMap<RelayoutProfiler::RelayoutItemType, PandaSet<PandaString>, std::hash<int>>>;
62 }  // namespace ark
63 #endif  // PANDA_RUNTIME_RELAYOUT_PROFILER_H
64