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