diff --git a/src/rvprof_output.c b/src/rvprof_output.c index 56ed6f6..9c7a862 100644 --- a/src/rvprof_output.c +++ b/src/rvprof_output.c @@ -12,4 +12,50 @@ static int compare_functions(const void* fn_a, const void* fn_b){ } else{ return 0; } -} \ No newline at end of file +} + +// 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; icaller, "---")==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 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; +}