11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst binding = internalBinding('performance'); 41cb0ef41Sopenharmony_ciconst { 51cb0ef41Sopenharmony_ci milestones, 61cb0ef41Sopenharmony_ci getTimeOrigin, 71cb0ef41Sopenharmony_ci} = binding; 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_ci// TODO(joyeecheung): we may want to warn about access to 101cb0ef41Sopenharmony_ci// this during snapshot building. 111cb0ef41Sopenharmony_cilet timeOrigin = getTimeOrigin(); 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_cifunction now() { 141cb0ef41Sopenharmony_ci const hr = process.hrtime(); 151cb0ef41Sopenharmony_ci return (hr[0] * 1000 + hr[1] / 1e6) - timeOrigin; 161cb0ef41Sopenharmony_ci} 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_cifunction getMilestoneTimestamp(milestoneIdx) { 191cb0ef41Sopenharmony_ci const ns = milestones[milestoneIdx]; 201cb0ef41Sopenharmony_ci if (ns === -1) 211cb0ef41Sopenharmony_ci return ns; 221cb0ef41Sopenharmony_ci return ns / 1e6 - timeOrigin; 231cb0ef41Sopenharmony_ci} 241cb0ef41Sopenharmony_ci 251cb0ef41Sopenharmony_cifunction refreshTimeOrigin() { 261cb0ef41Sopenharmony_ci timeOrigin = getTimeOrigin(); 271cb0ef41Sopenharmony_ci} 281cb0ef41Sopenharmony_ci 291cb0ef41Sopenharmony_cimodule.exports = { 301cb0ef41Sopenharmony_ci now, 311cb0ef41Sopenharmony_ci getMilestoneTimestamp, 321cb0ef41Sopenharmony_ci refreshTimeOrigin, 331cb0ef41Sopenharmony_ci}; 34