Created
April 12, 2023 09:33
-
-
Save houzhi0608/7a4ffdf5b387c3aac2c34b7d9f4d233a to your computer and use it in GitHub Desktop.
gpt dumpmem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.io.*; | |
| import java.util.*; | |
| public class CompareDumpsysMeminfo { | |
| public static void main(String[] args) throws IOException { | |
| // 解析命令行参数 | |
| if (args.length != 3) { | |
| printHelp(); | |
| return; | |
| } | |
| String fileA = args[0]; | |
| String fileB = args[1]; | |
| String resultFile = args[2]; | |
| // 定义需要对比的数据列 | |
| String[] columns = {"Pss Total", "Private Dirty", "Private Clean", "SwapPss Dirty", "Heap Size", "Heap Alloc", "Heap Free"}; | |
| // 定义需要对比的数据行 | |
| String[] rows = {"Native Heap", "Dalvik Heap", "Dalvik Other", "Stack", "Ashmem", "Gfx dev", "Other dev", ".so mmap", ".jar mmap", ".apk mmap"}; | |
| // 定义列名到列索引的映射 | |
| Map<String, Integer> columnMap = new HashMap<>(); | |
| for (int i = 0; i < columns.length; i++) { | |
| columnMap.put(columns[i], i); | |
| } | |
| // 定义行名到行索引的映射 | |
| Map<String, Integer> rowMap = new HashMap<>(); | |
| for (int i = 0; i < rows.length; i++) { | |
| rowMap.put(rows[i], i); | |
| } | |
| // 读取文件 A 和 B 的内容 | |
| int[][] dataA = readData(fileA, columnMap, rowMap); | |
| int[][] dataB = readData(fileB, columnMap, rowMap); | |
| // 对比两个数据矩阵并输出结果 | |
| compareData(dataA, dataB, columns, rows, resultFile); | |
| } | |
| private static void printHelp() { | |
| System.out.println("Usage: java -jar CompareDumpsysMeminfo.jar <fileA> <fileB> <resultFile>"); | |
| } | |
| private static int[][] readData(String fileName, Map<String, Integer> columnMap, Map<String, Integer> rowMap) throws IOException { | |
| int[][] data = new int[rowMap.size()][columnMap.size()]; | |
| BufferedReader br = new BufferedReader(new FileReader(fileName)); | |
| String line; | |
| while ((line = br.readLine()) != null) { | |
| for (String row : rowMap.keySet()) { | |
| if (line.trim().startsWith(row)) { | |
| String[] parts = line.trim().split("\\s+"); | |
| int columnIndex = 0; | |
| for (int i = 1; i < parts.length; i++) { | |
| if (!parts[i].isEmpty() && isNumeric(parts[i])) { | |
| int rowIndex = rowMap.get(row); | |
| data[rowIndex][columnIndex] = Integer.parseInt(parts[i]); | |
| columnIndex++; | |
| } | |
| } | |
| } | |
| } | |
| } | |
| br.close(); | |
| return data; | |
| } | |
| private static boolean isNumeric(String str) { | |
| try { | |
| Integer.parseInt(str); | |
| return true; | |
| } catch (NumberFormatException e) { | |
| return false; | |
| } | |
| } | |
| private static void compareData(int[][] dataA, int[][] dataB, String[] columns, String[] rows, String resultFile) throws IOException { | |
| BufferedWriter bw = new BufferedWriter(new FileWriter(resultFile)); | |
| for (int i = 0; i < rows.length; i++) { | |
| bw.write(rows[i] + "\n"); | |
| for (int j = 0; j < columns.length; j++) { | |
| bw.write(" " + columns[j] + ": " + dataA[i][j] + " -> " + dataB[i][j] + "\n"); | |
| } | |
| bw.write("\n"); | |
| } | |
| bw.close(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment