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)27 int GetMemoryInfoByPid(int pid, StringMatrix data)
28 {
29 std::unique_ptr<OHOS::HiviewDFX::MemoryInfo> memoryInfo = std::make_unique<OHOS::HiviewDFX::MemoryInfo>();
30 if (!memoryInfo->GetMemoryInfoByPid(pid, data)) {
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
ShowMemorySmapsByPid(int pid,StringMatrix data,bool isShowSmapsInfo)44 int ShowMemorySmapsByPid(int pid, StringMatrix data, bool isShowSmapsInfo)
45 {
46 std::unique_ptr<OHOS::HiviewDFX::SmapsMemoryInfo> smapsMemoryInfo =
47 std::make_unique<OHOS::HiviewDFX::SmapsMemoryInfo>();
48 if (!smapsMemoryInfo->ShowMemorySmapsByPid(pid, data, isShowSmapsInfo)) {
49 DUMPER_HILOGE(MODULE_SERVICE, "ShowMemorySmapsByPid error, pid:%{public}d", pid);
50 return OHOS::HiviewDFX::DumpStatus::DUMP_FAIL;
51 }
52 return OHOS::HiviewDFX::DumpStatus::DUMP_OK;
53 }
54
55 #ifdef __cplusplus
56 }
57 #endif