add sorting logic
This commit is contained in:
parent
bfa35f7d62
commit
1437339a1c
|
@ -12,4 +12,50 @@ static int compare_functions(const void* fn_a, const void* fn_b){
|
||||||
} else{
|
} else{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// actual report file generation
|
||||||
|
rvprof_error_t rvprof_output_generate_report(void){
|
||||||
|
if(!g_rvprof.output_file || g_rvprof.functions.size == 0){
|
||||||
|
return RVPROF_ERROR_INVALID_STATE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// safety measure: calculate total program time if not set or too small
|
||||||
|
uint64_t total_time_report = g_rvprof.total_program_time;
|
||||||
|
if (total_time_report == 0){
|
||||||
|
for(int i=0; i<g_rvprof.functions.size; i++){
|
||||||
|
function_stats_t* stats = &g_rvprof.functions.data[i];
|
||||||
|
// top-level (main)
|
||||||
|
if (strcmp(stats->caller, "---")==0){
|
||||||
|
if (stats->total_inclusive_time > total_time_report){
|
||||||
|
total_time_report = stats->total_inclusive_time;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// if still zero, sum all exclusive times
|
||||||
|
if (total_time_report == 0){
|
||||||
|
for (int i=0; i<g_rvprof.functions.size; i++){
|
||||||
|
total_time_report += g_rvprof.functions.data[i].total_exclusive_time;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// calculate elapsed time fractions
|
||||||
|
for (int i=0; i<g_rvprof.functions.size; i++){
|
||||||
|
function_stats_t* stats = &g_rvprof.functions.data[i];
|
||||||
|
if(total_time_report > 0){
|
||||||
|
stats->exclusive_percent = (double)stats->total_exclusive_time * 100.0 / (double)total_time_report;
|
||||||
|
stats->inclusive_percent = (double)stats->total_inclusive_time * 100.0 / (double)total_time_report;
|
||||||
|
} else{
|
||||||
|
stats->exclusive_percent = 0.0;
|
||||||
|
stats->inclusive_percent = 0.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// use stdlib's quicksort to sort functions by elapsed time
|
||||||
|
qsort(g_rvprof.functions.data, g_rvprof.functions.size, sizeof(function_stats_t), compare_functions);
|
||||||
|
|
||||||
|
return RVPROF_SUCCESS;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue