From a0b3af9c404c167cdd25e2523942eb132101a97c Mon Sep 17 00:00:00 2001 From: Patrick Lipka Date: Fri, 8 Aug 2025 17:42:54 +0200 Subject: [PATCH] add stats management --- src/rvprof_stats.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 src/rvprof_stats.c diff --git a/src/rvprof_stats.c b/src/rvprof_stats.c new file mode 100644 index 0000000..9126f40 --- /dev/null +++ b/src/rvprof_stats.c @@ -0,0 +1,73 @@ +#include "rvprof_internal.h" + +// get function id for given name / caller combination or create new one +int rvprof_stats_find_or_create_function( const char* name, const char* caller){ + if(g_rvprof.config.merge_regions){ + // ignore caller when merging stacks + for (int i=0; iname, name, MAX_NAME_LEN-1); + stats->name[MAX_NAME_LEN-1] = '\0'; + if(!g_rvprof.config.merge_regions){ + strncpy(stats->caller, caller, MAX_NAME_LEN-1); + stats->caller[MAX_NAME_LEN-1] = '\0'; + } + + return idx; +} + +// get call stack or create it +int rvprof_stats_get_or_create_stack_id(void) { + static char call_stack[4096]; + call_stack [0] = '\0'; + + for (int i=0; i<=g_rvprof.stack_ptr; i++){ + if (i>0){ + strcat(call_stack, "<"); + } + strcat(call_stack, g_rvprof.regions.data[i].name); + } + + // check if this stack exists already + for (int i=0; i