mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: support -profile - and -profile x.txt
This commit is contained in:
@@ -141,8 +141,17 @@ fn (mut g Gen) gen_fn_decl(it ast.FnDecl) {
|
||||
if is_main {
|
||||
if g.pref.is_prof {
|
||||
g.pcs_declarations.writeln('void vprint_profile_stats(){')
|
||||
for pfn_name, pcounter_name in g.pcs {
|
||||
g.pcs_declarations.writeln('\tif (${pcounter_name}_calls) printf("%llu %f %f ${pfn_name} \\n", ${pcounter_name}_calls, $pcounter_name, $pcounter_name / ${pcounter_name}_calls );')
|
||||
if g.pref.profile_file == '-' {
|
||||
for pfn_name, pcounter_name in g.pcs {
|
||||
g.pcs_declarations.writeln('\tif (${pcounter_name}_calls) printf("%llu %f %f ${pfn_name} \\n", ${pcounter_name}_calls, $pcounter_name, $pcounter_name / ${pcounter_name}_calls );')
|
||||
}
|
||||
}else{
|
||||
g.pcs_declarations.writeln('\tFILE * fp;')
|
||||
g.pcs_declarations.writeln('\tfp = fopen ("${g.pref.profile_file}", "w+");')
|
||||
for pfn_name, pcounter_name in g.pcs {
|
||||
g.pcs_declarations.writeln('\tif (${pcounter_name}_calls) fprintf(fp, "%llu %f %f ${pfn_name} \\n", ${pcounter_name}_calls, $pcounter_name, $pcounter_name / ${pcounter_name}_calls );')
|
||||
}
|
||||
g.pcs_declarations.writeln('\tfclose(fp);')
|
||||
}
|
||||
g.pcs_declarations.writeln('}')
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ pub mut:
|
||||
is_live bool // main program that contains live/hot code
|
||||
is_shared bool // an ordinary shared library, -shared, no matter if it is live or not
|
||||
is_prof bool // benchmark every function
|
||||
profile_file string // the profile results will be stored inside profile_file
|
||||
translated bool // `v translate doom.v` are we running V code translated from C? allow globals, ++ expressions, etc
|
||||
is_prod bool // use "-O2"
|
||||
obfuscate bool // `v -obf program.v`, renames functions to "f_XXX"
|
||||
|
||||
Reference in New Issue
Block a user