Skip to content

Commit 3c4f328

Browse files
committed
Make cpu time == time
1 parent 9b721b1 commit 3c4f328

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/timers.cc

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,10 @@ double ProcessCPUUsage() {
144144
DiagnoseAndExit("clock_gettime(CLOCK_PROCESS_CPUTIME_ID, ...) failed");
145145
#elif defined(__wasm__)
146146
// <aztec>
147-
// We define a fallback that works with wasi. We return something
148-
// obviously wrong - we don't want per-thread timing.
149-
return 0;
147+
// We define a fallback that works with wasi
148+
struct timeval tv;
149+
gettimeofday(&tv, nullptr);
150+
return static_cast<int64_t>(tv.tv_sec) * 1000000 + tv.tv_usec;
150151
// </ aztec>
151152
#else
152153
struct rusage ru;
@@ -201,9 +202,10 @@ double ThreadCPUUsage() {
201202
DiagnoseAndExit("clock_gettime(CLOCK_THREAD_CPUTIME_ID, ...) failed");
202203
#else
203204
// <aztec>
204-
// We define a fallback that works with wasi. We return something
205-
// obviously wrong - we don't want per-thread timing.
206-
return 0;
205+
// We define a fallback that works with wasi
206+
struct timeval tv;
207+
gettimeofday(&tv, nullptr);
208+
return static_cast<int64_t>(tv.tv_sec) * 1000000 + tv.tv_usec;
207209
// </ aztec>
208210
#endif
209211
}

0 commit comments

Comments
 (0)