1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

v.builder: streamline -stats output between backends. add a 'compilation speed' stat too

This commit is contained in:
Delyan Angelov 2021-04-08 12:18:02 +03:00
parent 9881ff8448
commit 7c79e9bce7
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
7 changed files with 41 additions and 22 deletions

View File

@ -21,6 +21,8 @@ mut:
out_name_c string
out_name_js string
max_nr_errors int = 100
stats_lines int // size of backend generated source code in lines
stats_bytes int // size of backend generated source code in bytes
pub mut:
module_search_paths []string
parsed_files []ast.File
@ -283,6 +285,9 @@ pub fn (b &Builder) find_module_path(mod string, fpath string) ?string {
}
fn (b &Builder) show_total_warns_and_errors_stats() {
if b.checker.nr_errors == 0 && b.checker.nr_warnings == 0 && b.checker.nr_notices == 0 {
return
}
if b.pref.is_stats {
estring := util.bold(b.checker.nr_errors.str())
wstring := util.bold(b.checker.nr_warnings.str())

View File

@ -46,23 +46,8 @@ pub fn (mut b Builder) build_c(v_files []string, out_file string) {
f.writeln(output2) or { panic(err) }
f.close()
if b.pref.is_stats {
mut all_v_source_lines, mut all_v_source_bytes := 0, 0
for mut pf in b.parsed_files {
all_v_source_lines += pf.lines
all_v_source_bytes += pf.bytes
}
mut sall_v_source_lines := all_v_source_lines.str()
mut sall_v_source_bytes := all_v_source_bytes.str()
mut slines := (output2.count('\n') + 1).str()
mut sbytes := output2.len.str()
//
slines = util.bold('${slines:10s}')
sbytes = util.bold('${sbytes:10s}')
sall_v_source_lines = util.bold('${sall_v_source_lines:10s}')
sall_v_source_bytes = util.bold('${sall_v_source_bytes:10s}')
//
println(' V source code size: $sall_v_source_lines lines, $sall_v_source_bytes bytes')
println('generated C source code size: $slines lines, $sbytes bytes')
b.stats_lines = output2.count('\n') + 1
b.stats_bytes = output2.len
}
// os.write_file(out_file, b.gen_c(v_files))
}

View File

@ -45,8 +45,28 @@ pub fn compile(command string, pref &pref.Preferences) {
.x64 { b.compile_x64() }
}
if pref.is_stats {
compilation_time := util.bold(sw.elapsed().milliseconds().str())
println('compilation took: $compilation_time ms')
compilation_time_micros := 1 + sw.elapsed().microseconds()
scompilation_time_ms := util.bold('${f64(compilation_time_micros) / 1000.0:6.3f}')
mut all_v_source_lines, mut all_v_source_bytes := 0, 0
for mut pf in b.parsed_files {
all_v_source_lines += pf.lines
all_v_source_bytes += pf.bytes
}
mut sall_v_source_lines := all_v_source_lines.str()
mut sall_v_source_bytes := all_v_source_bytes.str()
sall_v_source_lines = util.bold('${sall_v_source_lines:10s}')
sall_v_source_bytes = util.bold('${sall_v_source_bytes:10s}')
println(' V source code size: $sall_v_source_lines lines, $sall_v_source_bytes bytes')
//
mut slines := b.stats_lines.str()
mut sbytes := b.stats_bytes.str()
slines = util.bold('${slines:10s}')
sbytes = util.bold('${sbytes:10s}')
println('generated target code size: $slines lines, $sbytes bytes')
//
vlines_per_second := int(1_000_000.0 * f64(all_v_source_lines) / f64(compilation_time_micros))
svlines_per_second := util.bold(vlines_per_second.str())
println('compilation took: $scompilation_time_ms ms, compilation speed: $svlines_per_second vlines/s')
}
b.exit_on_invalid_syntax()
// running does not require the parsers anymore

View File

@ -36,6 +36,10 @@ pub fn (mut b Builder) build_js(v_files []string, out_file string) {
output := b.gen_js(v_files)
mut f := os.create(out_file) or { panic(err) }
f.writeln(output) or { panic(err) }
if b.pref.is_stats {
b.stats_lines = output.count('\n') + 1
b.stats_bytes = output.len
}
f.close()
}

View File

@ -27,7 +27,7 @@ pub fn (mut b Builder) build_x64(v_files []string, out_file string) {
markused.mark_used(mut b.table, b.pref, b.parsed_files)
}
util.timing_start('x64 GEN')
x64.gen(b.parsed_files, b.table, out_file, b.pref)
b.stats_lines, b.stats_bytes = x64.gen(b.parsed_files, b.table, out_file, b.pref)
util.timing_measure('x64 GEN')
}

View File

@ -103,5 +103,7 @@ pub fn (mut g Gen) generate_elf_footer() {
os.chmod(g.out_name, 0o775) // make it an executable
unsafe { f.write_ptr(g.buf.data, g.buf.len) }
f.close()
if g.pref.is_verbose {
println('\nx64 elf binary has been successfully generated')
}
}

View File

@ -32,6 +32,7 @@ mut:
warnings []errors.Warning
syms []Symbol
relocs []Reloc
nlines int
}
// string_addr map[string]i64
@ -81,7 +82,7 @@ enum Size {
_64
}
pub fn gen(files []ast.File, table &ast.Table, out_name string, pref &pref.Preferences) {
pub fn gen(files []ast.File, table &ast.Table, out_name string, pref &pref.Preferences) (int, int) {
mut g := Gen{
table: table
sect_header_name_pos: 0
@ -96,6 +97,7 @@ pub fn gen(files []ast.File, table &ast.Table, out_name string, pref &pref.Prefe
g.stmts(file.stmts)
}
g.generate_elf_footer()
return g.nlines, g.buf.len
}
pub fn (mut g Gen) stmts(stmts []ast.Stmt) {
@ -272,6 +274,7 @@ fn (mut g Gen) jle(addr i64) {
}
fn (mut g Gen) println(comment string) {
g.nlines++
if !g.pref.is_verbose {
return
}