1 /*
2 * Copyright 2022 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 #include <dump/pixel_dump.h>
17
18 #include <android-base/file.h>
19 #include <stdio.h>
20 #include <log/log.h>
21
concat(char * result,const char * one,const char * two)22 char* concat(char* result, const char* one, const char* two){
23 strcpy(result, one);
24 strcat(result, two);
25 return result;
26 }
27
iterate(const char * path)28 void iterate(const char* path){
29 dirent *entry, *entry2;
30 char result[100], base[100];
31
32 std::unique_ptr<DIR, decltype(&closedir)> ion(opendir(path), closedir);
33 if (!ion) {
34 ALOGE("Fail To Open Dir %s", path);
35 return;
36 }
37 while ((entry = readdir(ion.get())) != nullptr) {
38 if(entry->d_name[0] == '.') {
39 continue;
40 }
41 strcpy(base, path);
42 strcat(base, entry->d_name);
43 strcat(base, "/");
44 std::unique_ptr<DIR, decltype(&closedir)> ion2(opendir(base), closedir);
45 if (!ion2) {
46 ALOGE("Fail To Open Dir %s\n", base);
47 return;
48 }
49 while ((entry2 = readdir(ion2.get())) != nullptr) {
50 if(entry2->d_name[0] == '.') {
51 continue;
52 }
53 dumpFileContent(entry2->d_name, concat(result, base, entry2->d_name));
54 }
55 }
56 return;
57 }
58
59 // Dump memory.
main()60 int main() {
61 dirent *entry;
62 char result[100];
63
64 printf("------ ION HEAPS ------\n");
65 iterate("/d/ion/");
66
67 dumpFileContent("dmabuf info", "/d/dma_buf/bufinfo");
68 dumpFileContent("Page Pinner - longterm pin", "/sys/kernel/debug/page_pinner/buffer");
69
70 printf("------ CMA info ------\n");
71 std::unique_ptr<DIR, decltype(&closedir)> cmadebug(opendir("/sys/kernel/debug/cma/"), closedir);
72 if (!cmadebug) {
73 ALOGE("Fail To Open Dir /sys/kernel/debug/cma/");
74 } else {
75 while ((entry = readdir(cmadebug.get())) != nullptr) {
76 if(entry->d_name[0] == '.') {
77 continue;
78 }
79 dumpFileContent("count", concat(result, concat(result, "/sys/kernel/debug/cma/", entry->d_name), "/count"));
80 dumpFileContent("used", concat(result, concat(result, "/sys/kernel/debug/cma/", entry->d_name), "/used"));
81 dumpFileContent("bitmap", concat(result, concat(result, "/sys/kernel/debug/cma/", entry->d_name), "/bitmap"));
82 }
83 }
84
85 printf("------ Pixel CMA stat ------\n");
86 iterate("/sys/kernel/pixel_stat/mm/cma/");
87
88 dumpFileContent("Pixel Trace", "/sys/kernel/tracing/instances/pixel/trace");
89 return 0;
90 }
91
92