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()28 void LongFrameReportImpl::SubmitEvent()
29 {
30 int64_t tid = ResSchedReport::GetInstance().GetTid();
31 ffrtTask = ffrt::submit_h([tid] {
32 ResSchedReport::GetInstance().ResSchedDataReport("long_frame_start", {}, tid);
33 }, {}, {}, ffrt::task_attr().delay(LONG_FRAME_EVENT_DELAY).qos(ffrt::qos_user_interactive));
34 }
35
CancelEvent()36 void LongFrameReportImpl::CancelEvent()
37 {
38 if (ffrt::skip(ffrtTask)) {
39 ffrt::wait({ffrtTask});
40 ResSchedReport::GetInstance().ResSchedDataReport("long_frame_end");
41 }
42 }
43
ReportStartEvent()44 void ILongFrame::ReportStartEvent()
45 {
46 reporter = new LongFrameReportImpl();
47 static_cast<LongFrameReportImpl*>(reporter)->SubmitEvent();
48 }
49
ReportEndEvent()50 void ILongFrame::ReportEndEvent()
51 {
52 static_cast<LongFrameReportImpl*>(reporter)->CancelEvent();
53 delete static_cast<LongFrameReportImpl*>(reporter);
54 }
55 } // namespace OHOS::Ace
56