diff mbox series

[1/4] plugins/execlog: add struct execlog_ctx

Message ID 20240228200211.1512816-2-svens@stackframe.org (mailing list archive)
State New, archived
Headers show
Series plugins/execlog: add data address match and address range support | expand

Commit Message

Sven Schnelle Feb. 28, 2024, 8:02 p.m. UTC
Add a context structure for future enhancements. No functional
change intended.

Signed-off-by: Sven Schnelle <svens@stackframe.org>
---
 contrib/plugins/execlog.c | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)
diff mbox series

Patch

diff --git a/contrib/plugins/execlog.c b/contrib/plugins/execlog.c
index 82dc2f584e..90da1911b2 100644
--- a/contrib/plugins/execlog.c
+++ b/contrib/plugins/execlog.c
@@ -24,6 +24,10 @@  static GRWLock expand_array_lock;
 static GPtrArray *imatches;
 static GArray *amatches;
 
+struct execlog_ctx {
+    GString *s;
+};
+
 /*
  * Expand last_exec array.
  *
@@ -34,8 +38,9 @@  static void expand_last_exec(int cpu_index)
 {
     g_rw_lock_writer_lock(&expand_array_lock);
     while (cpu_index >= last_exec->len) {
-        GString *s = g_string_new(NULL);
-        g_ptr_array_add(last_exec, s);
+        struct execlog_ctx *ctx = g_new(struct execlog_ctx, 1);
+        ctx->s = g_string_new(NULL);
+        g_ptr_array_add(last_exec, ctx);
     }
     g_rw_lock_writer_unlock(&expand_array_lock);
 }
@@ -46,14 +51,13 @@  static void expand_last_exec(int cpu_index)
 static void vcpu_mem(unsigned int cpu_index, qemu_plugin_meminfo_t info,
                      uint64_t vaddr, void *udata)
 {
-    GString *s;
-
     /* Find vCPU in array */
     g_rw_lock_reader_lock(&expand_array_lock);
     g_assert(cpu_index < last_exec->len);
-    s = g_ptr_array_index(last_exec, cpu_index);
+    struct execlog_ctx *ctx = g_ptr_array_index(last_exec, cpu_index);
     g_rw_lock_reader_unlock(&expand_array_lock);
 
+    GString *s = ctx->s;
     /* Indicate type of memory access */
     if (qemu_plugin_mem_is_store(info)) {
         g_string_append(s, ", store");
@@ -77,8 +81,6 @@  static void vcpu_mem(unsigned int cpu_index, qemu_plugin_meminfo_t info,
  */
 static void vcpu_insn_exec(unsigned int cpu_index, void *udata)
 {
-    GString *s;
-
     /* Find or create vCPU in array */
     g_rw_lock_reader_lock(&expand_array_lock);
     if (cpu_index >= last_exec->len) {
@@ -86,8 +88,9 @@  static void vcpu_insn_exec(unsigned int cpu_index, void *udata)
         expand_last_exec(cpu_index);
         g_rw_lock_reader_lock(&expand_array_lock);
     }
-    s = g_ptr_array_index(last_exec, cpu_index);
+    struct execlog_ctx *ctx = g_ptr_array_index(last_exec, cpu_index);
     g_rw_lock_reader_unlock(&expand_array_lock);
+    GString *s = ctx->s;
 
     /* Print previous instruction in cache */
     if (s->len) {
@@ -183,9 +186,10 @@  static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb)
 static void plugin_exit(qemu_plugin_id_t id, void *p)
 {
     guint i;
-    GString *s;
+
     for (i = 0; i < last_exec->len; i++) {
-        s = g_ptr_array_index(last_exec, i);
+        struct execlog_ctx *ctx = g_ptr_array_index(last_exec, i);
+        GString *s = ctx->s;
         if (s->str) {
             qemu_plugin_outs(s->str);
             qemu_plugin_outs("\n");