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