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 // report when application startup request window 68 void ReportStartWindow(const std::string& bundleName, const std::string& windowName); 69 void ReportRecordedInfos(); 70 void ReportContainerStartBegin(int32_t missionId, const std::string& bundleName, int64_t timestamp); 71 72 private: 73 void UpdateReportInfo(FullInfoMap& infoMap, const std::string& bundleName, 74 const std::string& packageName); 75 void UpdateReportInfo(BundleNameMap& infoMap, const std::string& bundleName); 76 std::string GetMsgString(const FullInfoMap& infoMap); 77 std::string GetMsgString(const BundleNameMap& infoMap); 78 79 void Report(const std::string& reportTag, const std::string& msg); 80 void ClearRecordedInfos(); 81 82 BundleNameMap windowCreateReportInfos_; 83 BundleNameMap windowShowReportInfos_; 84 BundleNameMap windowHideReportInfos_; 85 BundleNameMap windowDestoryReportInfos_; 86 FullInfoMap windowRecentReportInfos_; 87 FullInfoMap windowNavigationBarReportInfos_; 88 89 std::mutex mtx_; 90 }; 91 } 92 } 93 #endif