Compare commits
3 Commits
6fb8bfefc6
...
b0841afa35
Author | SHA1 | Date |
---|---|---|
|
b0841afa35 | |
|
60ce804e36 | |
|
cc9a7ece7a |
|
@ -55,7 +55,6 @@ void rvprof_init(const char* output_file){
|
||||||
|
|
||||||
rvprof_symbols_init(g_rvprof.config.program_name); // in case symbol resolution fails, just addresses are printed later
|
rvprof_symbols_init(g_rvprof.config.program_name); // in case symbol resolution fails, just addresses are printed later
|
||||||
|
|
||||||
|
|
||||||
// rest of global state
|
// rest of global state
|
||||||
g_rvprof.stack_ptr = -1;
|
g_rvprof.stack_ptr = -1;
|
||||||
g_rvprof.initialized = 1;
|
g_rvprof.initialized = 1;
|
||||||
|
@ -73,3 +72,66 @@ void rvprof_init(const char* output_file){
|
||||||
// register atexit handler to automate cleanup
|
// register atexit handler to automate cleanup
|
||||||
register_atexit_handler();
|
register_atexit_handler();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void rvprof_set_program_name(const char* program_name){
|
||||||
|
if (g_rvprof.config.program_name){
|
||||||
|
rvprof_free(g_rvprof.config.program_name, strlen(g_rvprof.config.program_name)+1);
|
||||||
|
}
|
||||||
|
if (program_name) {
|
||||||
|
g_rvprof.config.program_name = rvprof_malloc(strlen(program_name)+1);
|
||||||
|
if (g_rvprof.config.program_name) {
|
||||||
|
strcpy(g_rvprof.config.program_name, program_name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void rvprof_region_begin(const char* name){
|
||||||
|
// auto-initialize with default settings if not yet initialized
|
||||||
|
if (!g_rvprof.initialized){
|
||||||
|
rvprof_init(NULL);
|
||||||
|
g_rvprof.auto_initialized = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_rvprof.stack_ptr++;
|
||||||
|
if(region_array_ensure_capacity(&g_rvprof.regions, g_rvprof.stack_ptr) < 0) {
|
||||||
|
g_rvprof.stack_ptr--;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
region_t* region = &g_rvprof.regions.data[g_rvprof.stack_ptr];
|
||||||
|
|
||||||
|
// initialize region
|
||||||
|
strncpy(region->name, name, MAX_NAME_LEN-1);
|
||||||
|
region->name[MAX_NAME_LEN-1] = '\0';
|
||||||
|
region->depth = g_rvprof.stack_ptr;
|
||||||
|
region->child_time = 0;
|
||||||
|
region->child_cycles = 0;
|
||||||
|
region->func_addr = NULL;
|
||||||
|
region->stack_id = rvprof_stats_get_or_create_stack_id;
|
||||||
|
|
||||||
|
// look up or create ID for region
|
||||||
|
const char* caller;
|
||||||
|
if(g_rvprof.stack_ptr > 0){
|
||||||
|
caller = g_rvprof.regions.data[g_rvprof.stack_ptr-1].name;
|
||||||
|
} else {
|
||||||
|
caller = "---";
|
||||||
|
}
|
||||||
|
region->function_id = rvprof_stats_find_or_create_function(name, caller);
|
||||||
|
|
||||||
|
// increase call count for ID and record call stack
|
||||||
|
if (region->function_id >= 0){
|
||||||
|
g_rvprof.functions.data[region->function_id].call_count++;
|
||||||
|
rvprof_stats_add_stack_id_to_function(region->function_id, region->stack_id);
|
||||||
|
if (g_rvprof.config.merge_regions){
|
||||||
|
rvprof_stats_add_caller_to_function(region->function_id, caller);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// start timing
|
||||||
|
region->start_time_ns = rvprof_timing_get_current();
|
||||||
|
region->start_cycles = rvprof_timing_get_cycles();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include "rvprof.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C"{
|
extern "C"{
|
||||||
|
|
Loading…
Reference in New Issue