1 /* 2 * Copyright (c) 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 APP_LAUNCH_SCENE_DATA_PROCESSOR_H 16 #define APP_LAUNCH_SCENE_DATA_PROCESSOR_H 17 18 #include <string> 19 #include <map> 20 #include "IAppLaunchSceneDataProcessor.h" 21 #include "IAppLaunchSceneDb.h" 22 #include "SceneDataMapDbAdapter.h" 23 #include "ITimeoutExecutor.h" 24 #include "IAppTimer.h" 25 26 namespace OHOS { 27 namespace HiviewDFX { 28 using AppStartRecord = IAppLaunchSceneDb::AppStartRecord; 29 using InteractionResponse = IAppLaunchSceneDb::InteractionResponse; 30 using StartAbility = IAppLaunchSceneDb::StartAbility; 31 using AppStartupType = IAppLaunchSceneDb::AppStartupType; 32 using ProcessStart = IAppLaunchSceneDb::ProcessStart; 33 using AppAttach = IAppLaunchSceneDb::AppAttach; 34 using AppForeground = IAppLaunchSceneDb::AppForeground; 35 using AbilityForeground = IAppLaunchSceneDb::AbilityForeground; 36 using StartWindow = IAppLaunchSceneDb::StartWindow; 37 using DrawnCompleted = IAppLaunchSceneDb::DrawnCompleted; 38 using FirstFrameDrawn = IAppLaunchSceneDb::FirstFrameDrawn; 39 using InteractionCompleted = IAppLaunchSceneDb::InteractionCompleted; 40 using AppStartMetrics = IAppLaunchSceneDataProcessor::AppStartMetrics; 41 using ITimeoutHandler = ITimeoutExecutor::ITimeoutHandler; 42 43 class AppLaunchSceneDataProcessor : public IAppLaunchSceneDataProcessor, public IAppTimer::ICb, public ITimeoutHandler, 44 public SceneDataMapDbAdapter { 45 public: 46 AppLaunchSceneDataProcessor(IAppLaunchSceneDb* db, ITimeoutExecutor* exec, 47 IAppLaunchSceneDataProcessor::MetricReporter* metricReporter, 48 IAppTimer* timer); 49 AppLaunchSceneDataProcessor(IAppLaunchSceneDb* db, ITimeoutExecutor* exec, IAppTimer* timer); 50 void ProcessSceneData(const AppStartCheckPointData& data) override; 51 void SetMetricReporter(MetricReporter* metricReporter) override; 52 void Expired(std::string key) override; 53 void HandleTimeoutInMainThr(std::string name) override; 54 private: 55 IAppLaunchSceneDataProcessor::MetricReporter* metricReporter; 56 IAppLaunchSceneDb* db; 57 ITimeoutExecutor* exec; 58 IAppTimer* timer; 59 60 bool CheckValidCheckPoint(const AppStartCheckPointData& data); 61 void ValidateDuplication(const AppStartCheckPointData& data); 62 void SaveCheckPoint(const std::string& bundleName, const AppStartCheckPointData& data); 63 void SaveCheckPoint(AppStartRecord& record, const AppStartCheckPointData& data); 64 bool IsStartPoint(const AppStartCheckPointData& data); 65 bool AllPointsReceived(const std::string& bundleName); 66 AppStartMetrics CalcMetrics(const std::string& bundleName); 67 void Report(const AppStartMetrics& metrics); 68 bool ReportConditionMet(const std::string& bundleName); 69 void CreateRecord(const AppStartCheckPointData& data); 70 void CreateRecord(const std::string& bundleName, const AppStartCheckPointData& data); 71 AppStartRecord GetRecord(const std::string& bundleName); 72 void DeleteRecord(const std::string& bundleName); 73 bool RecordExist(const std::string& bundleName); 74 void StartTimer(std::string bundle); 75 void StopTimer(std::string bundle); 76 bool HaveStartPoint(const AppStartRecord& record); 77 bool HaveAllEndPoints(const AppStartRecord& record); 78 bool HaveEndPoint(const AppStartRecord& record); 79 bool HaveResponseOrCompletedPoint(const AppStartRecord& record); 80 std::string GetProcessName(const AppStartRecord& record); 81 int32_t GetAppPid(const AppStartRecord& record); 82 uint64_t GetInputTime(const AppStartRecord& record); 83 std::string GetBundleName(const AppStartCheckPointData& data); 84 // The second application starts settlement points that already exist. 85 void CheckOutExistStartPoint(const AppStartCheckPointData& data); 86 void CalcLatency(AppStartMetrics& appStartMetrics, const AppStartRecord& record, const uint64_t inputTime); 87 }; 88 } // HiviewDFX 89 } // OHOS 90 #endif