1 /* 2 * Copyright (c) 2021-2022 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 panda { 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 &file_name, 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 #define ADD_PROFILE_CLASS_ITEM(...) Runtime::GetCurrent()->GetRelayoutProfiler()->AddProfileClassItem(__VA_ARGS__) 43 #define ADD_PROFILE_STRING_ITEM(...) \ 44 Runtime::GetCurrent()->GetRelayoutProfiler()->AddProfileItem(__VA_ARGS__, \ 45 RelayoutProfiler::RelayoutItemType::STRING_ITEM) 46 #define ADD_PROFILE_CODE_ITEM(...) Runtime::GetCurrent()->GetRelayoutProfiler()->AddProfileCodeItem(__VA_ARGS__) 47 #define WRITE_RELAYOUT_PROFILE_DATA() Runtime::GetCurrent()->GetRelayoutProfiler()->WriteProfileData() 48 #else 49 #define ADD_PROFILE_CLASS_ITEM(...) 50 #define ADD_PROFILE_STRING_ITEM(...) 51 #define ADD_PROFILE_CODE_ITEM(...) 52 #define WRITE_RELAYOUT_PROFILE_DATA() 53 #endif 54 55 using ProfileDataType = 56 PandaUnorderedMap<PandaString, 57 PandaUnorderedMap<RelayoutProfiler::RelayoutItemType, PandaSet<PandaString>, std::hash<int>>>; 58 } // namespace panda 59 #endif // PANDA_RUNTIME_RELAYOUT_PROFILER_H 60