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 #include "hiebpf_decorator.h"
16
17 namespace OHOS {
18 namespace HiviewDFX {
19 namespace UCollectUtil {
20 const std::string HIEBPF_COLLECTOR_NAME = "HiebpfCollector";
21 StatInfoWrapper HiebpfDecorator::statInfoWrapper_;
22
StartHiebpf(int duration,const std::string processName,const std::string outFile)23 CollectResult<bool> HiebpfDecorator::StartHiebpf(int duration,
24 const std::string processName,
25 const std::string outFile)
26 {
27 auto task = [this, &duration, &processName, &outFile] {
28 return hiebpfCollector_->StartHiebpf(duration, processName, outFile);
29 };
30 return Invoke(task, statInfoWrapper_, HIEBPF_COLLECTOR_NAME + UC_SEPARATOR + __func__);
31 }
32
StopHiebpf()33 CollectResult<bool> HiebpfDecorator::StopHiebpf()
34 {
35 auto task = [this] { return hiebpfCollector_->StopHiebpf(); };
36 return Invoke(task, statInfoWrapper_, HIEBPF_COLLECTOR_NAME + UC_SEPARATOR + __func__);
37 }
38
SaveStatCommonInfo()39 void HiebpfDecorator::SaveStatCommonInfo()
40 {
41 std::map<std::string, StatInfo> statInfo = statInfoWrapper_.GetStatInfo();
42 std::vector<std::string> formattedStatInfo;
43 for (const auto& record : statInfo) {
44 formattedStatInfo.push_back(record.second.ToString());
45 }
46 WriteLinesToFile(formattedStatInfo, false);
47 }
48
ResetStatInfo()49 void HiebpfDecorator::ResetStatInfo()
50 {
51 statInfoWrapper_.ResetStatInfo();
52 }
53 } // namespace UCollectUtil
54 } // namespace HiviewDFX
55 } // namespace OHOS
56