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