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

profile: use specialized time__vpc_now

This commit is contained in:
Delyan Angelov
2020-04-26 20:36:38 +03:00
parent 50a83736ff
commit e523540f3a
5 changed files with 48 additions and 36 deletions

View File

@@ -39,3 +39,19 @@ fn sys_mono_now() u64 {
}
}
// NB: vpc_now is used by `v -profile` .
// It should NOT call *any other v function*, just C functions and casts.
[inline]
fn vpc_now() u64 {
$if macos {
tm := C.mach_absolute_time()
if time_base.denom == 0 {
C.mach_timebase_info(&time_base)
}
return (tm - start_time) * time_base.numer / time_base.denom
} $else {
ts := C.timespec{}
C.clock_gettime(C.CLOCK_MONOTONIC, &ts)
return u64(ts.tv_sec) * 1_000_000_000 + u64(ts.tv_nsec)
}
}