1 /* 2 * Copyright (c) 2023 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 #ifndef HIVIEW_FRAMEWORK_NATIVE_UNIFIED_COLLECTION_PERF_COLLECTOR_IMPL_H 17 #define HIVIEW_FRAMEWORK_NATIVE_UNIFIED_COLLECTION_PERF_COLLECTOR_IMPL_H 18 19 #include "hiperf_client.h" 20 #include "perf_collector.h" 21 22 namespace OHOS { 23 namespace HiviewDFX { 24 namespace UCollectUtil { 25 using namespace OHOS::Developtools::HiPerf::HiperfClient; 26 class PerfCollectorImpl : public PerfCollector { 27 public: 28 PerfCollectorImpl(); 29 virtual ~PerfCollectorImpl() = default; 30 virtual CollectResult<bool> StartPerf(const std::string &logDir) override; 31 void SetSelectPids(const std::vector<pid_t> &selectPids) override; 32 void SetTargetSystemWide(bool enable) override; 33 void SetTimeStopSec(int timeStopSec) override; 34 void SetFrequency(int frequency) override; 35 void SetOffCPU(bool offCPU) override; 36 void SetOutputFilename(const std::string &outputFilename) override; 37 void SetCallGraph(const std::string &sampleTypes) override; 38 void SetSelectEvents(const std::vector<std::string> &selectEvents) override; 39 void SetCpuPercent(int cpuPercent) override; 40 void SetReport(bool enable) override; 41 // for prepare recod mode 42 CollectResult<bool> Prepare(const std::string &logDir) override; 43 CollectResult<bool> StartRun() override; 44 CollectResult<bool> Pause() override; 45 CollectResult<bool> Resume() override; 46 CollectResult<bool> Stop() override; 47 private: 48 static std::atomic<uint8_t> inUseCount_; 49 static uint8_t limitUseCount_; 50 RecordOption opt_; 51 Client hiperfClient_; 52 void IncreaseUseCount(); 53 void DecreaseUseCount(); 54 CollectResult<bool> CheckUseCount(); 55 }; 56 } // namespace UCollectUtil 57 } // namespace HiviewDFX 58 } // namespace OHOS 59 #endif // HIVIEW_FRAMEWORK_NATIVE_UNIFIED_COLLECTION_PERF_COLLECTOR_IMPL_H