add rvprof_region_begin
This commit is contained in:
parent
60ce804e36
commit
b0841afa35
|
@ -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
|
||||
|
||||
|
||||
// rest of global state
|
||||
g_rvprof.stack_ptr = -1;
|
||||
g_rvprof.initialized = 1;
|
||||
|
@ -86,3 +85,53 @@ void rvprof_set_program_name(const char* 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();
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue