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 16 #include "adapter/ohos/osal/long_frame_report_impl.h" 17 18 #include <unistd.h> 19 20 #include "base/longframe/long_frame_report.h" 21 #include "base/ressched/ressched_report.h" 22 23 namespace OHOS::Ace { 24 namespace { 25 constexpr int32_t LONG_FRAME_EVENT_DELAY = 10000; 26 } 27 SubmitEvent()28void LongFrameReportImpl::SubmitEvent() 29 { 30 ffrtTask = ffrt::submit_h([] { 31 ResSchedReport::GetInstance().ResSchedDataReport("long_frame_start"); 32 }, {}, {}, ffrt::task_attr().delay(LONG_FRAME_EVENT_DELAY)); 33 } 34 CancelEvent()35void LongFrameReportImpl::CancelEvent() 36 { 37 if (ffrt::skip(ffrtTask)) { 38 ffrt::wait({ffrtTask}); 39 ResSchedReport::GetInstance().ResSchedDataReport("long_frame_end"); 40 } 41 } 42 ReportStartEvent()43void ILongFrame::ReportStartEvent() 44 { 45 reporter = new LongFrameReportImpl(); 46 static_cast<LongFrameReportImpl*>(reporter)->SubmitEvent(); 47 } 48 ReportEndEvent()49void ILongFrame::ReportEndEvent() 50 { 51 static_cast<LongFrameReportImpl*>(reporter)->CancelEvent(); 52 delete static_cast<LongFrameReportImpl*>(reporter); 53 } 54 } // namespace OHOS::Ace 55