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 #ifndef LOCK_FREQUENCY_H 16 #define LOCK_FREQUENCY_H 17 #include "sp_profiler.h" 18 #include <string> 19 #include <map> 20 #include <thread> 21 22 namespace OHOS { 23 namespace SmartPerf { 24 using ReportDataFunc = int (*)(const std::vector<int32_t>& resId, const std::vector<int64_t>& value, 25 const std::vector<int64_t>& endTime, const std::string& msgStr); 26 using PerfScenarioFunc = int (*)(const std::string& msgStr); 27 class LockFrequency : public SpProfiler { 28 public: GetInstance()29 static LockFrequency &GetInstance() 30 { 31 static LockFrequency instance; 32 return instance; 33 } 34 std::map<std::string, std::string> ItemData() override; 35 void StartExecutionOnce(bool isPause) override; 36 void FinishtExecutionOnce(bool isPause) override; 37 void LockingThread(); 38 void SetIsCollecting(bool state); 39 40 private: LockFrequency()41 LockFrequency() {}; 42 LockFrequency(const LockFrequency &); 43 LockFrequency &operator = (const LockFrequency &); 44 45 bool isCollecting = false; 46 const std::string lockFunction = "FrequencyLockPlugin"; 47 ReportDataFunc reportFunc_ = nullptr; 48 PerfScenarioFunc scenarioFunc_ = nullptr; 49 std::thread th_; 50 }; 51 } 52 } 53 #endif