Bug 1585922 - New function cpuNow() for the JS shell;r=arai

Differential Revision: https://phabricator.services.mozilla.com/D48051

--HG--
extra : moz-landing-system : lando
This commit is contained in:
David Teller 2019-10-03 13:08:27 +00:00
parent 7770e575a0
commit 72b2e89d13

View File

@ -36,6 +36,7 @@
#if defined(MALLOC_H)
# include MALLOC_H /* for malloc_usable_size, malloc_size, _msize */
#endif
#include <ctime>
#include <math.h>
#include <signal.h>
#include <stdio.h>
@ -2684,6 +2685,13 @@ static bool Now(JSContext* cx, unsigned argc, Value* vp) {
return true;
}
static bool CpuNow(JSContext* cx, unsigned argc, Value* vp) {
CallArgs args = CallArgsFromVp(argc, vp);
double now = double(std::clock()) / double(CLOCKS_PER_SEC);
args.rval().setDouble(now);
return true;
}
static bool PrintInternal(JSContext* cx, const CallArgs& args, RCFile* file) {
if (!file->isOpen()) {
JS_ReportErrorASCII(cx, "output file is closed");
@ -9132,6 +9140,12 @@ JS_FN_HELP("parseBin", BinParse, 1, 0,
" object: Don't create a new DOM object, but instead use the supplied\n"
" FakeDOMObject."),
JS_FN_HELP("cpuNow", CpuNow, /* nargs= */ 0, /* flags = */ 0,
"cpuNow()",
" Returns the approximate processor time used by the process since an arbitrary epoch, in seconds.\n"
" Only the difference between two calls to `cpuNow()` is meaningful."),
JS_FS_HELP_END
};
// clang-format on