How Date.now() function value is returned (Is it from kernel of v8 engine has its own implementation)

57 views
Skip to first unread message

Abhishek Kanike

unread,
May 21, 2018, 6:22:45 PM5/21/18
to v8-users
Hi,
I want to know how the date.now() function is called in javascript (or how it returns the value). I believe that javascript uses date.now() by system call. I want to in chrome source code how it is being set. 
This is useful for one of the performance benchmark that I am working on.
Can someone please guide me to know how this happens in v8 engine.

Thanks in advance.

Regards,
K Abhishek

Jakob Kummerow

unread,
May 21, 2018, 6:40:27 PM5/21/18
to v8-users
The time always has to be retrieved from the kernel. V8's implementation is in base::OS::TimeCurrentMillis, implemented in src/base/platform/platform-{win32,posix}.cc.

--
--
v8-users mailing list
v8-u...@googlegroups.com
http://groups.google.com/group/v8-users
---
You received this message because you are subscribed to the Google Groups "v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to v8-users+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Abhishek Kanike

unread,
May 21, 2018, 7:51:33 PM5/21/18
to v8-u...@googlegroups.com
Cool.. I see it. Thanks a lot Jacob.

Abhishek Kanike

unread,
May 21, 2018, 7:51:54 PM5/21/18
to v8-u...@googlegroups.com
Sorry JaKob

Abhishek Kanike

unread,
Jun 18, 2018, 5:39:27 PM6/18/18
to v8-u...@googlegroups.com
​Hi,
For confirmation i am using a simple Date.now() call on button click [Attached]. 
I have added a print log in Time::NOW() at https://cs.chromium.org/chromium/src/v8/src/base/platform/time.cc?type=cs&sq=package:chromium&g=0&l=402 as printf("v8:DEBUG::TIME:NOW called").
I am not getting this log in adb logcat. So is this the correct place from where Date.now() is getting called?

Regards, 
K Abhishek
--
Cheers, 
K Abhishek
date_now.html

Jakob Kummerow

unread,
Jun 18, 2018, 6:12:53 PM6/18/18
to v8-users
Yes, it is.

Have you tried using a debugger? You can set a breakpoint in the BUILTIN(DateNow) function here:


and step through the code from there.

Abhishek Kanike

unread,
Jun 18, 2018, 6:48:21 PM6/18/18
to v8-u...@googlegroups.com
Jakob,
Thanks for quick reply. 
That's a good point, should have tried with gdb. Will check with that.
Is there a way to add logs in v8 source code, it will be lot faster to debug.
In cc (compositor), i used LOG(INFO)<<"print"; from base/logging.h (of main chromium src)

Jakob Kummerow

unread,
Jun 18, 2018, 8:07:48 PM6/18/18
to v8-users
Sure, just use printf or std::cout << "print\n". I don't know whether adb logcat has any special requirements.

Abhishek Kanike

unread,
Jun 21, 2018, 12:55:02 PM6/21/18
to v8-u...@googlegroups.com
Hi Jakob and v8-users,​​
I have following observations on printing logs in v8 and date.now call trace.
  1. Logs in v8:
    printf and std::cout were not outputting any logs in adb logcat. I ​tried redirecting stdio logs to logcat by following commands - 
    $ adb shell stop
    $ adb shell setprop log.redirect-stdio true
    $ adb shell start
    But still logs were not getting displayed in adb logcat. So I used android log library. Following is the procedure
    • Import header file:
      #if defined(V8_OS_ANDROID)
        #include <android/log.h>
      #endif
    • Print log:
      #if defined(V8_OS_ANDROID)
        __android_log_print(ANDROID_LOG_INFO, "<TAG>", "<MESSAGE>");
      #endif

  2. Date.now() final system call:
    Date.now() calls V8Platform::CurrentClockTimeMillis() from src/gin/v8_platform.cc ---> Time::Now() from src/base/time/time.cc ---> getTimeofDay() rather than base::OS::TimeCurrentMillis. Can anyone explain this behaviour?
Regards,
K Abhishek

Jakob Kummerow

unread,
Jun 21, 2018, 2:34:56 PM6/21/18
to v8-users
gin provides its own v8::Platform implementation, overriding the default platform.

Abhishek Kanike

unread,
Jun 21, 2018, 6:30:19 PM6/21/18
to v8-u...@googlegroups.com
​Yes gin has its own implementation of time apart from default-platform.
I have one more concern.
How can i implement my own javascript API?
Basically I am thinking to create two javascript API which calls two respective calls from my shared library (external)​.
Instead of creating two new api's is there any other method from JavaScript which calls my external library functions. I dont want to fork processes from javascript to execute my library functions since I am planning to profile chrome browser.

Regards,
K Abhishek 
Reply all
Reply to author
Forward
0 new messages