To protect your data, the CISO officer has suggested users to enable 2FA as soon as possible.
Currently 2.8% of users enabled 2FA.

Commit f2afaa3c authored by Zixian Cai's avatar Zixian Cai
Browse files

Fix clock callback for WebAssembly

parent ae2c3c96
......@@ -23,12 +23,12 @@ limitations under the License.
#define DEFAULT_FLOAT_FORMAT_PREC 6 // 1 microsec
#include <time.h>
#ifdef __MACH__
#if defined(__MACH__)
// Use mach_absolute_time on macOS
typedef uint64_t timestamp_t;
#include <mach/mach_time.h>
static inline void get_nano_timestamp(timestamp_t* tstamp) {
static inline void get_timestamp(timestamp_t* tstamp) {
*tstamp = mach_absolute_time();
}
static double get_elapsed_time(timestamp_t* t0, timestamp_t* t1) {
......@@ -41,10 +41,23 @@ limitations under the License.
elapsed_nano = elapsed * tb.numer / tb.denom;
return ((double)elapsed_nano) * 1e-9;
}
#elif defined(__WASM__)
// clock_gettime doesn't work when compile through emscripten
// mach_absolute_time doesn't work either
typedef clock_t timestamp_t;
static inline void get_timestamp(timestamp_t* tstamp){
*tstamp = clock();
}
static double get_elapsed_time(timestamp_t* t0, timestamp_t* t1) {
timestamp_t elapsed;
elapsed = *t1 - *t0;
return ((double) elapsed) / CLOCKS_PER_SEC;
}
#else
// Use clock_gettime on Linux
typedef struct timespec timestamp_t;
static inline void get_nano_timestamp(timestamp_t* tstamp) {
static inline void get_timestamp(timestamp_t* tstamp) {
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, tstamp);
}
static double get_elapsed_time(timestamp_t* t0, timestamp_t* t1) {
......@@ -75,12 +88,12 @@ void* cb_init(const char *param_s) {
void cb_begin(void *p) {
Callback *cb = (Callback*)p;
// call time measurement function
get_nano_timestamp(&cb->t0);
get_timestamp(&cb->t0);
}
void cb_end(void *p) {
Callback *cb = (Callback*)p;
get_nano_timestamp(&cb->t1);
get_timestamp(&cb->t1);
}
void cb_report(void *p) {
......
......@@ -54,7 +54,7 @@ class WASM(Language):
cmd.append(cc['exec'])
# flags
flags = ['-s', "WASM=1"]
flags = ['-s', "WASM=1", '-D__WASM__']
include_flags = ['-I%(callback_dir)s' % locals()]
cc_flags = list(
map(lambda a: expandenv(a, task.env), cc.get('flags', [])))
......@@ -86,7 +86,8 @@ class WASM(Language):
cmd.extend(task.benchmark['args'])
return cls.run_in_subproc(cmd, task.env, cwd=str(target.parent.resolve()))
return cls.run_in_subproc(cmd, task.env,
cwd=str(target.parent.resolve()))
@classmethod
def run_in_subproc(cls, cmd, env=None, **kwargs):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment