• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
22 namespace OHOS {
23 namespace SmartPerf {
ItemData()24     std::map<std::string, std::string> LockFrequency::ItemData()
25     {
26         return std::map<std::string, std::string>();
27     }
LockingThread()28     void LockFrequency::LockingThread()
29     {
30         LOGD("Lock frequency thread create");
31         const int loopLockTime = 4000;
32         char soFilePathChar[PATH_MAX] = {0x00};
33         if ((realpath(pluginSoPath.c_str(), soFilePathChar) == nullptr)) {
34             LOGE("%s is not exist.", pluginSoPath.c_str());
35             return;
36         }
37         void* handle = dlopen(soFilePathChar, RTLD_LAZY);
38         if (!handle) {
39             LOGE("open TestServerPlugin so file error.");
40             return;
41         }
42         typedef int32_t (*GetLockFreq)();
43         GetLockFreq testServerPlugin = (GetLockFreq)dlsym(handle, lockFunction.c_str());
44         if (!testServerPlugin) {
45             LOGE("testServerPlugin Error loading symbol");
46             return;
47         }
48         while (isCollecting) {
49             testServerPlugin();
50             std::this_thread::sleep_for(std::chrono::milliseconds(loopLockTime));
51         }
52 
53         LOGD("Lock frequency thread end");
54     }
55 
SetIsCollecting(bool state)56     void LockFrequency::SetIsCollecting(bool state)
57     {
58         isCollecting = state;
59     }
60 }
61 }
62