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