-
Notifications
You must be signed in to change notification settings - Fork 27
/
analyze_snapshot.ts
66 lines (53 loc) · 1.71 KB
/
analyze_snapshot.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/**
* Script used to analyze snapshots from the indexer.
*
* Usage: tsx analyze_snapshot.ts <snapshot_file_name>
*/
import fs from "fs";
interface LogEntry {
address: string;
eventName: string;
args: {
tableId: string;
keyTuple: string[];
staticData: string;
encodedLengths: string;
dynamicData: string;
};
}
interface LogData {
logs: LogEntry[];
}
const tableData = fs.readFileSync("all_tables.json");
const tables = JSON.parse(tableData);
function getTableName(tableId) {
const table = tables.find((t) => t.tableId === tableId);
return table ? table.name : "Table not found";
}
// Take snapshot file name from command line argument
const snapshotFileName = process.argv[2]; // Assuming the first argument is the file name
// Read the JSON file using the command line argument
const rawData = fs.readFileSync(snapshotFileName, "utf8");
const data: LogData = JSON.parse(rawData);
// Function to count logs per table ID
function countLogsPerTableId(logs: LogEntry[]): Map<string, number> {
const tableIdCounts = new Map<string, number>();
logs.forEach((log) => {
const tableId = log.args.tableId;
if (tableIdCounts.has(tableId)) {
tableIdCounts.set(tableId, tableIdCounts.get(tableId)! + 1);
} else {
tableIdCounts.set(tableId, 1);
}
});
return tableIdCounts;
}
// Get the counts
const counts = countLogsPerTableId(data.logs);
// Convert the map to an array and sort it in descending order based on count
const sortedCounts = Array.from(counts).sort((a, b) => b[1] - a[1]);
// Display the sorted counts
console.log("Counts of logs per table ID in descending order:");
sortedCounts.forEach(([tableId, count]) => {
console.log(`${getTableName(tableId)}: ${count}`);
});