Skip to content

Conversation

@sunfishcode
Copy link
Member

Upcoming WASI snapshots omit the PROCESS_CPUTIME clock, since WASI has
no inherent concept of processes, and since implementations which don't
use a process for each instance don't have a way to implement it
efficiently.

However, clock, times, and getrusage are useful functions, so
provide optional emulated version of them, using the MONOTONIC clock.
This means these implementations will measure not just the program's
own CPU time, but also time spent suspended while other programs are
running.

Due to this difference in behavior, put these implementations behind
a flag. Users must pass -D_WASI_EMULATED_PROCESS_CLOCK and link with
-lwasi-emulated-process-clocks to enable them.

Upcoming WASI snapshots omit the `PROCESS_CPUTIME` clock, since WASI has
no inherent concept of processes, and since implementations which don't
use a process for each instance don't have a way to implement it
efficiently.

However, `clock`, `times`, and `getrusage` are useful functions, so
provide optional emulated version of them, using the `MONOTONIC` clock.
This means these implementations will measure not just the program's
own CPU time, but also time spent suspended while other programs are
running.

Due to this difference in behavior, put these implementations behind
a flag. Users must pass `-D_WASI_EMULATED_PROCESS_CLOCK` and link with
`-lwasi-emulated-process-clocks` to enable them.
@sunfishcode sunfishcode force-pushed the sunfishcode/reimplement-process-clocks branch from 0cde165 to f6b79d4 Compare March 22, 2021 18:53
@sunfishcode sunfishcode merged commit c82d116 into main Mar 23, 2021
@sunfishcode sunfishcode deleted the sunfishcode/reimplement-process-clocks branch March 23, 2021 17:34
@zeux
Copy link

zeux commented Dec 31, 2021

It would be nice to be able to simply use clock() without having to specify additional defines and libraries... On Windows, clock() already accounts for the amount of time spent waiting, so I'm not sure that the value of the extra warnings/errors in absence of the said define justify themselves...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants