profile: produce civilized output

pull/4618/head
Delyan Angelov 2020-04-27 12:45:19 +03:00
parent 99a7b69578
commit dd1ee39271
1 changed files with 3 additions and 2 deletions

View File

@ -29,15 +29,16 @@ fn (mut g Gen) profile_fn(fn_name string, is_main bool){
pub fn (mut g Gen) gen_vprint_profile_stats() {
g.pcs_declarations.writeln('void vprint_profile_stats(){')
fstring := '"%14llu %14.3fms %14.0fns %s \\n"'
if g.pref.profile_file == '-' {
for pc_meta in g.pcs {
g.pcs_declarations.writeln('\tif (${pc_meta.vpc_calls}) printf("%llu %f %f ${pc_meta.fn_name} \\n", ${pc_meta.vpc_calls}, ${pc_meta.vpc_name}, ${pc_meta.vpc_name}/${pc_meta.vpc_calls} );')
g.pcs_declarations.writeln('\tif (${pc_meta.vpc_calls}) printf($fstring, ${pc_meta.vpc_calls}, ${pc_meta.vpc_name}/1000000.0, ${pc_meta.vpc_name}/${pc_meta.vpc_calls}, "${pc_meta.fn_name}" );')
}
} else {
g.pcs_declarations.writeln('\tFILE * fp;')
g.pcs_declarations.writeln('\tfp = fopen ("${g.pref.profile_file}", "w+");')
for pc_meta in g.pcs {
g.pcs_declarations.writeln('\tif (${pc_meta.vpc_calls}) fprintf(fp, "%llu %f %f ${pc_meta.fn_name} \\n", ${pc_meta.vpc_calls}, ${pc_meta.vpc_name}, ${pc_meta.vpc_name}/${pc_meta.vpc_calls} );')
g.pcs_declarations.writeln('\tif (${pc_meta.vpc_calls}) fprintf(fp, $fstring, ${pc_meta.vpc_calls}, ${pc_meta.vpc_name}/1000000.0, ${pc_meta.vpc_name}/${pc_meta.vpc_calls}, "${pc_meta.fn_name}" );')
}
g.pcs_declarations.writeln('\tfclose(fp);')
}