• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "hilog_decorator.h"
17 #include "decorator_util.h"
18 #include <functional>
19 
20 namespace OHOS::HiviewDFX::UCollectUtil {
21 constexpr char HILOG_COLLECTOR_NAME[] = "HilogCollector";
22 StatInfoWrapper HilogDecorator::statInfoWrapper_;
23 
CollectLastLog(uint32_t pid,uint32_t num)24 CollectResult<std::string> HilogDecorator::CollectLastLog(uint32_t pid, uint32_t num)
25 {
26     auto task = [this, &pid, &num] { return hilogCollector_->CollectLastLog(pid, num); };
27     return Invoke(task, statInfoWrapper_, std::string(HILOG_COLLECTOR_NAME) + UC_SEPARATOR + __func__);
28 }
29 
SaveStatCommonInfo()30 void HilogDecorator::SaveStatCommonInfo()
31 {
32     std::map<std::string, StatInfo> statInfo = statInfoWrapper_.GetStatInfo();
33     std::list<std::string> formattedStatInfo;
34     for (const auto& record : statInfo) {
35         formattedStatInfo.push_back(record.second.ToString());
36     }
37     WriteLinesToFile(formattedStatInfo, false, UC_STAT_LOG_PATH);
38 }
39 
ResetStatInfo()40 void HilogDecorator::ResetStatInfo()
41 {
42     statInfoWrapper_.ResetStatInfo();
43 }
44 } // namespace OHOS::HiviewDFX::UCollectUtil
45