From 3ec03522c9e3e06e0b30d2ac7c33473e22d30fa4 Mon Sep 17 00:00:00 2001 From: fredfrance-oss Date: Tue, 25 Nov 2025 01:15:47 +1100 Subject: [PATCH 1/2] Simple but significant speed improvement in textprinter.cpp --- panda/plugins/textprinter/textprinter.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/panda/plugins/textprinter/textprinter.cpp b/panda/plugins/textprinter/textprinter.cpp index e663af6a30d..96b915ecaf4 100644 --- a/panda/plugins/textprinter/textprinter.cpp +++ b/panda/plugins/textprinter/textprinter.cpp @@ -35,6 +35,7 @@ PANDAENDCOMMENT */ #include #include #include +#include #include "panda/plugin.h" @@ -53,11 +54,16 @@ void write_mem_callback(CPUState *env, target_ulong pc, target_ulong addr, size_ uint64_t mem_counter; std::set tap_points; +std::unordered_set tap_pc; gzFile read_tap_buffers; gzFile write_tap_buffers; void mem_callback(CPUState *env, target_ulong pc, target_ulong addr, size_t size, uint8_t *buf, gzFile f) { + if (tap_pc.find(pc) == tap_pc.end()) { + mem_counter++; + return; + } prog_point p = {}; get_prog_point(env, &p); @@ -142,6 +148,7 @@ bool init_plugin(void *self) { printf("Adding tap point (" TARGET_FMT_lx "," TARGET_FMT_lx ", %s)\n", p.caller, p.pc, sid_string); tap_points.insert(p); + tap_pc.insert(p.pc); g_free(sid_string); } taps.close(); From 2323c8f265a4982d60c00c0b9131366ceb89e6ab Mon Sep 17 00:00:00 2001 From: fredfrance-oss Date: Mon, 8 Dec 2025 20:22:19 +1100 Subject: [PATCH 2/2] Make code more readable Refactor memory callback to avoid duplicate code and improve readability. --- panda/plugins/textprinter/textprinter.cpp | 38 +++++++++++------------ 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/panda/plugins/textprinter/textprinter.cpp b/panda/plugins/textprinter/textprinter.cpp index 96b915ecaf4..4bf0590fdc6 100644 --- a/panda/plugins/textprinter/textprinter.cpp +++ b/panda/plugins/textprinter/textprinter.cpp @@ -60,32 +60,32 @@ gzFile write_tap_buffers; void mem_callback(CPUState *env, target_ulong pc, target_ulong addr, size_t size, uint8_t *buf, gzFile f) { + mem_counter++; if (tap_pc.find(pc) == tap_pc.end()) { - mem_counter++; return; } prog_point p = {}; get_prog_point(env, &p); - - if (tap_points.find(p) != tap_points.end()) { - target_ulong callers[16] = {0}; - int nret = get_callers(callers, 16, env); - unsigned char *buf_uc = static_cast(buf); - for (unsigned int i = 0; i < size; i++) { - for (int j = nret-1; j > 0; j--) { - gzprintf(f, TARGET_FMT_lx " ", callers[j]); - } - gzprintf(f, - TARGET_FMT_lx " " TARGET_FMT_lx " %d " TARGET_FMT_lx - " " TARGET_FMT_lx " %s " TARGET_FMT_lx - " %ld %02x\n", - p.caller, p.pc, p.stackKind, p.sidFirst, p.sidSecond, - p.isKernelMode ? "kernel" : "user", addr + i, mem_counter, - buf_uc[i]); + if (tap_points.find(p) == tap_points.end()) { + return; + } + + target_ulong callers[16] = {0}; + int nret = get_callers(callers, 16, env); + unsigned char *buf_uc = static_cast(buf); + for (unsigned int i = 0; i < size; i++) { + for (int j = nret-1; j > 0; j--) { + gzprintf(f, TARGET_FMT_lx " ", callers[j]); } + gzprintf(f, + TARGET_FMT_lx " " TARGET_FMT_lx " %d " TARGET_FMT_lx + " " TARGET_FMT_lx " %s " TARGET_FMT_lx + " %ld %02x\n", + p.caller, p.pc, p.stackKind, p.sidFirst, p.sidSecond, + p.isKernelMode ? "kernel" : "user", addr + i, mem_counter, + buf_uc[i]); } - mem_counter++; - + return; }