1 /* 2 * Copyright (c) 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 16 #ifndef OHOS_ROSEN_WM_UTILS_PERFORM_REPORTER_H 17 #define OHOS_ROSEN_WM_UTILS_PERFORM_REPORTER_H 18 19 #include <atomic> 20 #include <chrono> 21 #include <string> 22 #include <vector> 23 #include <map> 24 #include <mutex> 25 #include "wm_single_instance.h" 26 27 namespace OHOS { 28 namespace Rosen { 29 class PerformReporter { 30 public: 31 PerformReporter(const std::string& tag, const std::vector<int64_t>& timeSpiltsMs, uint32_t reportInterval = 50); 32 void start(); 33 void end(); 34 35 private: 36 void count(int64_t costTime); 37 bool report(); 38 void clear(); 39 40 std::string tag_; 41 std::atomic<uint32_t> totalCount_; 42 std::map<int64_t, std::atomic<uint32_t>> timeSplitCount_; 43 std::chrono::steady_clock::time_point startTime_; 44 uint32_t reportInterval_; 45 46 static constexpr auto BARRIER = std::numeric_limits<int64_t>::max(); 47 }; 48 49 // the map form : <bundleName, <abilityName, count>> 50 using FullInfoMap = std::map<std::string, std::map<std::string, uint32_t>>; 51 // the map form : <bundleName, count> 52 using BundleNameMap = std::map<std::string, uint32_t>; 53 class WindowInfoReporter { 54 WM_DECLARE_SINGLE_INSTANCE(WindowInfoReporter); 55 56 public: 57 void InsertCreateReportInfo(const std::string& bundleName); 58 void InsertShowReportInfo(const std::string& bundleName); 59 void InsertHideReportInfo(const std::string& bundleName); 60 void InsertDestroyReportInfo(const std::string& bundleName); 61 62 void InsertRecentReportInfo(const std::string& bundleName, const std::string& packageName); 63 void InsertNavigationBarReportInfo(const std::string& bundleName, const std::string& packageName); 64 65 void ReportBackButtonInfoImmediately(); 66 void ReportZeroOpacityInfoImmediately(const std::string& bundleName, const std::string& packageName); 67 void ReportRecordedInfos(); 68 69 private: 70 void UpdateReportInfo(FullInfoMap& infoMap, const std::string& bundleName, 71 const std::string& packageName); 72 void UpdateReportInfo(BundleNameMap& infoMap, const std::string& bundleName); 73 std::string GetMsgString(const FullInfoMap& infoMap); 74 std::string GetMsgString(const BundleNameMap& infoMap); 75 76 void Report(const std::string& reportTag, const std::string& msg); 77 void ClearRecordedInfos(); 78 79 BundleNameMap windowCreateReportInfos_; 80 BundleNameMap windowShowReportInfos_; 81 BundleNameMap windowHideReportInfos_; 82 BundleNameMap windowDestoryReportInfos_; 83 FullInfoMap windowRecentReportInfos_; 84 FullInfoMap windowNavigationBarReportInfos_; 85 86 std::mutex mtx_; 87 }; 88 } 89 } 90 #endif