1 /* 2 * Copyright (C) 2021 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 HIPERF_H 17 #define HIPERF_H 18 #include "common.h" 19 #include <string> 20 #include "mutex" 21 #include "vector" 22 #include <map> 23 #include "sp_profiler.h" 24 #include "sp_utils.h" 25 namespace OHOS { 26 namespace SmartPerf { 27 class Hiperf : public SpProfiler { 28 public: 29 std::map<std::string, std::string> ItemData() override; GetInstance()30 static Hiperf &GetInstance() 31 { 32 static Hiperf instance; 33 return instance; 34 } 35 void StartExecutionOnce(bool isPause) override; 36 void FinishtExecutionOnce(bool isPause) override; 37 void SetProcessId(const std::string &pid); 38 void PrepareHiperf(); 39 void StartHiperf(); 40 void StopHiperf(); 41 void GetHiperfData(); 42 void SetDataMap(std::string &line); 43 std::string ReturnHiperfData(); 44 std::string ProcessCountData(std::string count); 45 46 private: Hiperf()47 Hiperf() {}; 48 Hiperf(const Hiperf &); 49 Hiperf &operator = (const Hiperf &); 50 const std::string savePath_ = "data/local/tmp/test.txt"; 51 std::string processId_; 52 std::mutex hiperfLock_; 53 std::map<std::string, std::string> hiperfData_ = {}; 54 const std::string cpuCycles = SPUtils::GetProductName() + "-cpu-cycles"; 55 const std::string inStructions = SPUtils::GetProductName() + "-instructions"; 56 std::vector<std::string> collectNodes_ = {cpuCycles, inStructions}; 57 bool hiperfFirstCollect_ = true; 58 }; 59 } 60 } 61 #endif // HIPERF_H 62