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_MONITOR_CONVERTER_H 16 #define APP_LAUNCH_MONITOR_CONVERTER_H 17 18 #include "IAppLaunchSceneDataProcessor.h" 19 #include "IAppStartReporter.h" 20 #include "AppMonitorDataConverter.h" 21 22 const std::string COMMENT_APP_START = "APP_START"; 23 const std::string COMMENT_APP_START_SLOW = "APP_START_SLOW"; 24 25 const unsigned int APP_START_ACTION_ID = 11; 26 const unsigned int APP_START_EVENT_ID = 902500019; 27 28 using AppStartCheckPointData = IAppLaunchSceneDataProcessor::AppStartCheckPointData; 29 using AppEvtData = IAppThrExecutor::AppEvtData; 30 using AppStartMetrics = IAppLaunchSceneDataProcessor::AppStartMetrics; 31 32 class AppLaunchMonitorConverter : public AppMonitorDataConverter { 33 public: ConvertAppEvtDataToCheckPointData(const AppEvtData & appEvtData)34 static AppStartCheckPointData ConvertAppEvtDataToCheckPointData(const AppEvtData& appEvtData) 35 { 36 AppStartCheckPointData checkPointData; 37 checkPointData.time = appEvtData.time; 38 checkPointData.domain = appEvtData.domain; 39 checkPointData.eventName = appEvtData.eventName; 40 checkPointData.bundleName= appEvtData.bundleName; 41 checkPointData.abilityName = appEvtData.abilityName; 42 checkPointData.processName = appEvtData.processName; 43 checkPointData.pageUrl = appEvtData.pageUrl; 44 checkPointData.sceneId = appEvtData.sceneId; 45 checkPointData.sourceType = appEvtData.sourceType; 46 checkPointData.inputTime = appEvtData.inputTime; 47 checkPointData.animationStartTime = appEvtData.animationStartTime; 48 checkPointData.renderTime = appEvtData.renderTime; 49 checkPointData.responseLatency = appEvtData.responseLatency; 50 checkPointData.moduleName = appEvtData.moduleName; 51 checkPointData.versionCode = appEvtData.versionCode; 52 checkPointData.versionName = appEvtData.versionName; 53 checkPointData.startType = appEvtData.startType; 54 checkPointData.startupTime = appEvtData.startupTime; 55 checkPointData.startupAbilityType = appEvtData.startupAbilityType; 56 checkPointData.startupExtensionType = appEvtData.startupExtensionType; 57 checkPointData.callerBundleName = appEvtData.callerBundleName; 58 checkPointData.callerUid = appEvtData.callerUid; 59 checkPointData.callerProcessName = appEvtData.callerProcessName; 60 checkPointData.appPid = appEvtData.appPid; 61 checkPointData.appUid = appEvtData.appUid; 62 checkPointData.windowName = appEvtData.windowName; 63 checkPointData.bundleType = appEvtData.bundleType; 64 checkPointData.animationEndLatency = appEvtData.animationEndLatency; 65 checkPointData.e2eLatency = appEvtData.e2eLatency; 66 checkPointData.note = appEvtData.note; 67 checkPointData.animationStartLatency = appEvtData.animationStartLatency; 68 69 return checkPointData; 70 } 71 ConvertMetricToReportEvent(IAppLaunchSceneDataProcessor::AppStartMetrics metrics)72 static AppStartReportEvent ConvertMetricToReportEvent(IAppLaunchSceneDataProcessor::AppStartMetrics metrics) 73 { 74 AppStartReportEvent reportEvent; 75 reportEvent.appPid = metrics.appPid; 76 reportEvent.versionCode = metrics.versionCode; 77 reportEvent.versionName = metrics.versionName; 78 reportEvent.processName = metrics.processName; 79 reportEvent.bundleName = metrics.bundleName; 80 reportEvent.abilityName = metrics.abilityName; 81 reportEvent.pageUrl = metrics.pageUrl; 82 reportEvent.sceneId = metrics.sceneId; 83 reportEvent.startType = metrics.startType; 84 reportEvent.sourceType = metrics.sourceType; 85 reportEvent.inputTime = metrics.inputTime; 86 reportEvent.responseLatency = metrics.responseLatency; 87 reportEvent.launcherToAmsStartAbilityDur = metrics.launcherToAmsStartAbilityDur; 88 reportEvent.amsStartAbilityToProcessStartDuration = metrics.amsStartAbilityToProcessStartDuration; 89 reportEvent.amsProcessStartToAppAttachDuration = metrics.amsProcessStartToAppAttachDuration; 90 reportEvent.amsAppAttachToAppForegroundDuration = metrics.amsAppAttachToAppForegroundDuration; 91 reportEvent.amsStartAbilityToAppForegroundDuration = metrics.amsStartAbilityToAppForegroundDuration; 92 reportEvent.amsAppFgToAbilityFgDur = metrics.amsAppFgToAbilityFgDur; 93 reportEvent.amsAbilityFgToWmsStartWinDur = metrics.amsAbilityFgToWmsStartWinDur; 94 reportEvent.drawnLatency = metrics.drawnLatency; 95 reportEvent.firstFrameDrawnLatency = metrics.firstFrameDrawnLatency; 96 reportEvent.animationEndLatency = metrics.animationEndLatency; 97 reportEvent.animationLatency = metrics.animationLatency; 98 reportEvent.e2eLatency = metrics.e2eLatency; 99 reportEvent.happenTime = metrics.happenTime; 100 101 reportEvent.actionId = APP_START_ACTION_ID; 102 reportEvent.eventId = APP_START_EVENT_ID; 103 return reportEvent; 104 } 105 }; 106 #endif