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