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 "power_log.h"
17 #include "power_xcollie.h"
18 #include "xcollie/xcollie.h"
19
20 namespace OHOS {
21 namespace PowerMgr {
PowerXCollie(const std::string & logTag,bool isRecovery)22 PowerXCollie::PowerXCollie(const std::string &logTag, bool isRecovery)
23 {
24 logTag_ = logTag;
25 isCanceled_ = false;
26 const int DFX_DELAY_S = 60;
27 unsigned int flag = HiviewDFX::XCOLLIE_FLAG_LOG;
28 if (isRecovery) {
29 flag = HiviewDFX::XCOLLIE_FLAG_LOG | HiviewDFX::XCOLLIE_FLAG_RECOVERY;
30 }
31 id_ = HiviewDFX::XCollie::GetInstance().SetTimer(logTag_, DFX_DELAY_S, nullptr, nullptr, flag);
32 POWER_HILOGD(FEATURE_UTIL, "Start PowerXCollie, id:%{public}d, tag:%{public}s, timeout(s):%{public}u", id_,
33 logTag_.c_str(), DFX_DELAY_S);
34 }
35
~PowerXCollie()36 PowerXCollie::~PowerXCollie()
37 {
38 CancelPowerXCollie();
39 }
40
CancelPowerXCollie()41 void PowerXCollie::CancelPowerXCollie()
42 {
43 if (!isCanceled_) {
44 HiviewDFX::XCollie::GetInstance().CancelTimer(id_);
45 isCanceled_ = true;
46 POWER_HILOGD(FEATURE_UTIL, "Cancel PowerXCollie, id:%{public}d, tag:%{public}s", id_, logTag_.c_str());
47 }
48 }
49
50 } // namespace PowerMgr
51 } // namespace OHOS