• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 "record_cost_time_util.h"
17 
18 #include "hilog_tag_wrapper.h"
19 
20 namespace OHOS {
21 namespace AAFwk {
22 namespace {
23 constexpr int64_t MAX_MILLISECONDS = 500;
24 }
25 
RecordCostTimeUtil(const std::string & name)26 RecordCostTimeUtil::RecordCostTimeUtil(const std::string &name)
27     : funcName_(name), timeStart_(std::chrono::steady_clock::now())
28 {}
29 
~RecordCostTimeUtil()30 RecordCostTimeUtil::~RecordCostTimeUtil()
31 {
32     auto costTime =
33         std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - timeStart_);
34     if (costTime > std::chrono::milliseconds(MAX_MILLISECONDS)) {
35         TAG_LOGE(AAFwkTag::ABILITYMGR, "a_cost_time:%{public}s, name:%{public}s",
36             std::to_string(costTime.count()).c_str(), funcName_.c_str());
37     }
38 }
39 }  // namespace AAFwk
40 }  // namespace OHOS
41