1 /*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <cstring>
18 #include <cerrno>
19 #include <sys/types.h>
20 #include <sys/stat.h>
21 #include <unistd.h>
22
23 #include <hardware/memtrack.h>
24
25 #include "memtrack_exynos.h"
26
exynos_memtrack_init(const struct memtrack_module __unused * module)27 int exynos_memtrack_init(const struct memtrack_module __unused *module)
28 {
29 return 0;
30 }
31
exynos_memtrack_get_memory(const struct memtrack_module __unused * module,pid_t pid,int type,struct memtrack_record * records,size_t * num_records)32 int exynos_memtrack_get_memory(const struct memtrack_module __unused *module,
33 pid_t pid,
34 int type,
35 struct memtrack_record *records,
36 size_t *num_records)
37 {
38 struct stat st;
39
40 switch (type) {
41 case MEMTRACK_TYPE_GL:
42 if (!stat("/d/mali/mem", &st) && S_ISDIR(st.st_mode))
43 return mali_memtrack_get_memory(pid, type, records, num_records);
44 break;
45 case MEMTRACK_TYPE_GRAPHICS:
46 if (!stat("/d/ion/clients", &st) && S_ISDIR(st.st_mode))
47 return ion_memtrack_get_memory(pid, type, records, num_records);
48 [[fallthrough]];
49 default:
50 return dmabuf_memtrack_get_memory(pid, type, records, num_records);
51 }
52
53 return -ENODEV;
54 }
55
56 static struct hw_module_methods_t memtrack_module_methods = {
57 .open = NULL,
58 };
59
60 struct memtrack_module HAL_MODULE_INFO_SYM = {
61 .common = {
62 .tag = HARDWARE_MODULE_TAG,
63 .module_api_version = MEMTRACK_MODULE_API_VERSION_0_1,
64 .hal_api_version = HARDWARE_HAL_API_VERSION,
65 .id = MEMTRACK_HARDWARE_MODULE_ID,
66 .name = "Exynos Memory Tracker HAL",
67 .author = "The Android Open Source Project",
68 .methods = &memtrack_module_methods,
69 },
70
71 .init = exynos_memtrack_init,
72 .getMemory = exynos_memtrack_get_memory,
73 };
74
75