vinix-ports / tools / vinix-time-ld.v
26 lines · 23 sloc · 709 bytes · da3db5c26bdf794ef3d62aeeff7018922019eb86
Raw
1// Build as a private ld.lld and pass -B<its-directory> -fuse-ld=lld to GCC.
2// GNU time writes peak KiB, elapsed seconds, exit status, and linker arguments.
3module main
4
5import os
6
7fn measure() ! {
8 linker := os.getenv('VINIX_REAL_LD')
9 log := os.getenv('VINIX_LINK_LOG')
10 if !os.is_abs_path(linker) || !os.is_abs_path(log) {
11 return error('set VINIX_REAL_LD and VINIX_LINK_LOG to absolute paths')
12 }
13 if os.real_path(linker) == os.real_path(os.executable()) {
14 return error('VINIX_REAL_LD resolves to the timing wrapper itself')
15 }
16 mut args := ['-a', '-o', log, '-f', '%M\t%e\t%x\t%C', linker]
17 args << os.args[1..]
18 os.execvp('time', args)!
19}
20
21fn main() {
22 measure() or {
23 eprintln(err)
24 exit(1)
25 }
26}
27