• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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 #include "executor/memory/memory_info_wrapper.h"
16 #include <dlfcn.h>
17 #include <vector>
18 #include <string>
19 #include "hilog_wrapper.h"
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 using StringMatrix = std::shared_ptr<std::vector<std::vector<std::string>>>;
26 
GetMemoryInfoByPid(int pid,StringMatrix data,bool showAshmem,bool showDmaBuf)27 int GetMemoryInfoByPid(int pid, StringMatrix data, bool showAshmem, bool showDmaBuf)
28 {
29     std::unique_ptr<OHOS::HiviewDFX::MemoryInfo> memoryInfo = std::make_unique<OHOS::HiviewDFX::MemoryInfo>();
30     if (!memoryInfo->GetMemoryInfoByPid(pid, data, showAshmem, showDmaBuf)) {
31         DUMPER_HILOGE(MODULE_SERVICE, "GetMemoryInfoByPid error, pid:%{public}d", pid);
32         return OHOS::HiviewDFX::DumpStatus::DUMP_FAIL;
33     }
34     return OHOS::HiviewDFX::DumpStatus::DUMP_OK;
35 }
36 
GetMemoryInfoNoPid(int fd,StringMatrix data)37 int GetMemoryInfoNoPid(int fd, StringMatrix data)
38 {
39     std::unique_ptr<OHOS::HiviewDFX::MemoryInfo> memoryInfo = std::make_unique<OHOS::HiviewDFX::MemoryInfo>();
40     int ret = memoryInfo->GetMemoryInfoNoPid(fd, data);
41     return ret;
42 }
43 
GetMemoryInfoPrune(int fd,StringMatrix data)44 int GetMemoryInfoPrune(int fd, StringMatrix data)
45 {
46     std::unique_ptr<OHOS::HiviewDFX::MemoryInfo> memoryInfo = std::make_unique<OHOS::HiviewDFX::MemoryInfo>();
47     int ret = memoryInfo->GetMemoryInfoPrune(fd, data);
48     return ret;
49 }
50 
ShowMemorySmapsByPid(int pid,StringMatrix data,bool isShowSmapsInfo)51 int ShowMemorySmapsByPid(int pid, StringMatrix data, bool isShowSmapsInfo)
52 {
53     std::unique_ptr<OHOS::HiviewDFX::SmapsMemoryInfo> smapsMemoryInfo =
54         std::make_unique<OHOS::HiviewDFX::SmapsMemoryInfo>();
55     if (!smapsMemoryInfo->ShowMemorySmapsByPid(pid, data, isShowSmapsInfo)) {
56         DUMPER_HILOGE(MODULE_SERVICE, "ShowMemorySmapsByPid error, pid:%{public}d", pid);
57         return OHOS::HiviewDFX::DumpStatus::DUMP_FAIL;
58     }
59     return OHOS::HiviewDFX::DumpStatus::DUMP_OK;
60 }
61 
GetMemoryInfoByTimeInterval(int fd,int pid,int timeInterval)62 void GetMemoryInfoByTimeInterval(int fd, int pid, int timeInterval)
63 {
64     std::unique_ptr<OHOS::HiviewDFX::MemoryInfo> memoryInfo = std::make_unique<OHOS::HiviewDFX::MemoryInfo>();
65     memoryInfo->GetMemoryInfoByTimeInterval(fd, pid, timeInterval);
66 }
67 
SetReceivedSigInt(bool isReceivedSigInt)68 void SetReceivedSigInt(bool isReceivedSigInt)
69 {
70     std::unique_ptr<OHOS::HiviewDFX::MemoryInfo> memoryInfo = std::make_unique<OHOS::HiviewDFX::MemoryInfo>();
71     memoryInfo->SetReceivedSigInt(isReceivedSigInt);
72 }
73 
74 #ifdef __cplusplus
75 }
76 #endif