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 #include "AppStartReporterAdapter.h"
16 #include "hiview_logger.h"
17 
18 namespace OHOS {
19 namespace HiviewDFX {
20 DEFINE_LOG_LABEL(0xD002D66, "Hiview-XPerformance");
21 
AppStartReporterAdapter(IAppStartReportInfrastructure* impl, IAppStartEventPoster* poster)22 AppStartReporterAdapter::AppStartReporterAdapter(IAppStartReportInfrastructure* impl, IAppStartEventPoster* poster)
23     : SimpleAppStartReporterAdapter(impl)
24 {
25     this->eventPoster = poster;
26 }
27 
ReportNormal(const AppStartReportEvent& event)28 void AppStartReporterAdapter::ReportNormal(const AppStartReportEvent& event)
29 {
30     try {
31         AppStartReportData data = ConvertReportEventToData(event);
32         reporter->ReportNormal(data);
33 
34         AppStartEventInfo evt = ConvertReportEventToEventInfo(event);
35         HIVIEW_LOGD("[AppStartReporterAdapter::ReportNormal] PostAppStartEvent begin");
36         eventPoster->PostAppStartEvent(evt);
37         HIVIEW_LOGD("[AppStartReporterAdapter::ReportNormal] PostAppStartEvent end");
38     } catch (std::logic_error& ex) {
39         HIVIEW_LOGE("[AppStartReporterAdapter::ReportNormal] exception:%{public}s", ex.what());
40     }
41 }
42 
ConvertReportEventToEventInfo(const AppStartReportEvent& event)43 AppStartEventInfo AppStartReporterAdapter::ConvertReportEventToEventInfo(const AppStartReportEvent& event)
44 {
45     AppStartEventInfo info;
46     info.appPid = event.appPid;
47     info.versionCode = event.versionCode;
48     info.versionName = event.versionName;
49     info.processName = event.processName;
50     info.bundleName = event.bundleName;
51     info.abilityName = event.abilityName;
52     info.pageUrl = event.pageUrl;
53     info.sceneId = event.sceneId;
54     info.startType = event.startType;
55     info.sourceType = event.sourceType;
56     info.inputTime = event.inputTime;
57     info.responseLatency = event.responseLatency;
58     info.launcherToAmsStartAbilityDur = event.launcherToAmsStartAbilityDur;
59     info.amsStartAbilityToProcessStartDuration = event.amsStartAbilityToProcessStartDuration;
60     info.amsProcessStartToAppAttachDuration = event.amsProcessStartToAppAttachDuration;
61     info.amsAppAttachToAppForegroundDuration = event.amsAppAttachToAppForegroundDuration;
62     info.amsStartAbilityToAppForegroundDuration = event.amsStartAbilityToAppForegroundDuration;
63     info.amsAppFgToAbilityFgDur = event.amsAppFgToAbilityFgDur;
64     info.amsAbilityFgToWmsStartWinDur = event.amsAbilityFgToWmsStartWinDur;
65     info.drawnLatency = event.drawnLatency;
66     info.firstFrameDrawnLatency = event.firstFrameDrawnLatency;
67     info.animationLatency = event.animationLatency;
68     info.e2eLatency = event.e2eLatency;
69     info.actionId = event.actionId;
70     info.eventId = event.eventId;
71     info.traceFileName = event.traceFileName;
72     info.infoFileName = event.infoFileName;
73     info.happenTime = event.happenTime;
74     return info;
75 }
76 } // HiviewDFX
77 } // OHOS