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 #include "include/lock_frequency.h" 17 #include <thread> 18 #include <chrono> 19 #include <dlfcn.h> 20 #include "include/sp_log.h" 21 #include "include/service_plugin.h" 22 23 namespace OHOS { 24 namespace SmartPerf { ItemData()25 std::map<std::string, std::string> LockFrequency::ItemData() 26 { 27 return std::map<std::string, std::string>(); 28 } LockingThread()29 void LockFrequency::LockingThread() 30 { 31 LOGD("Lock frequency thread create"); 32 const int loopLockTime = 4000; 33 34 ServicePluginHandler &servicePluginHandler = ServicePluginHandler::GetInstance(); 35 void* handle = servicePluginHandler.GetSoHandler(ServicePluginHandler::ServicePluginType::TEST_PLUGIN); 36 if (!handle) { 37 LOGE("open TestServerPlugin so file error."); 38 return; 39 } 40 41 typedef int32_t (*GetLockFreq)(); 42 GetLockFreq testServerPlugin = (GetLockFreq)dlsym(handle, lockFunction.c_str()); 43 if (!testServerPlugin) { 44 LOGE("Error loading symbol"); 45 return; 46 } 47 while (isCollecting) { 48 testServerPlugin(); 49 std::this_thread::sleep_for(std::chrono::milliseconds(loopLockTime)); 50 } 51 52 LOGD("Lock frequency thread end"); 53 } 54 SetIsCollecting(bool state)55 void LockFrequency::SetIsCollecting(bool state) 56 { 57 isCollecting = state; 58 } 59 } 60 } 61