• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 <dlfcn.h>
17 
18 #include "base/ressched/ressched_report.h"
19 #include <unistd.h>
20 #include <sys/syscall.h>
21 
22 namespace OHOS::Ace {
23 namespace {
24 const std::string RES_SCHED_CLIENT_SO = "libressched_client.z.so";
25 }
26 
LoadReportDataFunc()27 ReportDataFunc LoadReportDataFunc()
28 {
29     auto handle = dlopen(RES_SCHED_CLIENT_SO.c_str(), RTLD_NOW);
30     CHECK_NULL_RETURN(handle, nullptr);
31     auto func = reinterpret_cast<ReportDataFunc>(dlsym(handle, "ReportData"));
32     if (func == nullptr) {
33         LOGW("dlsym function ReportData failed!");
34         dlclose(handle);
35         return nullptr;
36     }
37     LOGI("dlsym function ReportData success.");
38     return func;
39 }
40 
LoadReportSyncEventFunc()41 ReportSyncEventFunc LoadReportSyncEventFunc()
42 {
43     auto handle = dlopen(RES_SCHED_CLIENT_SO.c_str(), RTLD_NOW);
44     CHECK_NULL_RETURN(handle, nullptr);
45     auto func = reinterpret_cast<ReportSyncEventFunc>(dlsym(handle, "ReportSyncEvent"));
46     if (func == nullptr) {
47         LOGW("dlsym function ReportSyncEvent failed!");
48         dlclose(handle);
49         return nullptr;
50     }
51     LOGI("dlsym function ReportSyncEvent success.");
52     return func;
53 }
54 
GetTid()55 int64_t ResSchedReport::GetTid()
56 {
57     return gettid();
58 }
59 
GetPid()60 int64_t ResSchedReport::GetPid()
61 {
62     return getpid();
63 }
64 
GetPthreadSelf()65 pthread_t ResSchedReport::GetPthreadSelf()
66 {
67     return pthread_self();
68 }
69 } // namespace OHOS::Ace
70