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 "display_buffer_dfx.h"
17 #include <hdf_log.h>
18 #include <cinttypes>
19
20 #define TIME_1000 1000
21 #define TIME_10 10
22 #define HICOLLIE_TIMEOUT 10
23
24 namespace OHOS {
25 namespace HDI {
26 namespace Display {
27 namespace Buffer {
28 namespace V1_0 {
DisplayBufferDfx(const std::string & name)29 DisplayBufferDfx::DisplayBufferDfx(const std::string& name)
30 : dfxName_(name),
31 timeId_(0),
32 flag_(false),
33 startTimeStamp({0, 0}),
34 stopTimeStamp({0, 0})
35 {
36 }
37
~DisplayBufferDfx()38 DisplayBufferDfx::~DisplayBufferDfx()
39 {
40 if (timeId_ != 0) {
41 CancelTimer();
42 }
43 if (flag_) {
44 StopTimeStamp();
45 }
46 }
47
SetTimer()48 void DisplayBufferDfx::SetTimer()
49 {
50 #ifdef DISPLAY_HICOLLIE_ENABLE
51 timeId_ = HiviewDFX::XCollie::GetInstance().SetTimer(dfxName_, HICOLLIE_TIMEOUT, nullptr, nullptr,
52 HiviewDFX::XCOLLIE_FLAG_LOG | HiviewDFX::XCOLLIE_FLAG_RECOVERY);
53 #endif
54 }
55
CancelTimer()56 void DisplayBufferDfx::CancelTimer()
57 {
58 #ifdef DISPLAY_HICOLLIE_ENABLE
59 HiviewDFX::XCollie::GetInstance().CancelTimer(timeId_);
60 #endif
61 }
62
StartTimeStamp()63 void DisplayBufferDfx::StartTimeStamp()
64 {
65 gettimeofday(&startTimeStamp, nullptr);
66 flag_ = true;
67 }
68
StopTimeStamp()69 void DisplayBufferDfx::StopTimeStamp()
70 {
71 gettimeofday(&stopTimeStamp, nullptr);
72 int64_t runTime = (stopTimeStamp.tv_sec - startTimeStamp.tv_sec) * TIME_1000 +
73 (stopTimeStamp.tv_usec - startTimeStamp.tv_usec) / TIME_1000;
74 if (runTime > TIME_10) {
75 HDF_LOGW("run %{public}s over time, [%{public}" PRId64 "]ms", dfxName_.c_str(), runTime);
76 }
77 flag_ = false;
78 }
79 } // namespace V1_0
80 } // namespace Buffer
81 } // namespace Display
82 } // namespace HDI
83 } // namespace OHOS