Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add monotonic clock config option, use it for debugger transport peeks #1659

Merged
merged 5 commits into from
Aug 3, 2017

Conversation

svaarala
Copy link
Owner

@svaarala svaarala commented Aug 3, 2017

  • Add DUK_USE_GET_MONOTONIC_TIME(), semantics similar to POSIX clock_gettime() CLOCK_MONOTONIC
  • Add internal helpers for getting Ecmascript/monotonic time, fewer macro calls and easier to debug
  • Change debugger transport peek rate limiting to use monotonic time
  • Manual test: make Date.now() run very slowly, provide monotonic time, and check that debugger peeks work at the expected ~200ms rate
  • Releases entry

@svaarala svaarala added this to the v2.2.0 milestone Aug 3, 2017
@svaarala
Copy link
Owner Author

svaarala commented Aug 3, 2017

Tested with:

diff --git a/src-input/duk_bi_date_unix.c b/src-input/duk_bi_date_unix.c
index 5613c9e5..6a045f7c 100644
--- a/src-input/duk_bi_date_unix.c
+++ b/src-input/duk_bi_date_unix.c
@@ -26,6 +26,7 @@ DUK_INTERNAL duk_double_t duk_bi_date_get_now_gettimeofday(duk_hthread *thr) {
 
        d = ((duk_double_t) tv.tv_sec) * 1000.0 +
            ((duk_double_t) (tv.tv_usec / 1000));
+       d = DUK_FLOOR(d / 100.0);
        DUK_ASSERT(DUK_FLOOR(d) == d);  /* no fractions */
 
        return d;

Debugger code makes transport peeks roughly every 10-20 seconds (1/100 from normal rate) as expected. Then added this hack to duk_config.h:

static inline double get_mono_time(duk_context *ctx) {
        struct timespec ts;

        clock_gettime(CLOCK_MONOTONIC, &ts);
        return (double) ts.tv_sec * 1000.0 + (double) ts.tv_nsec / 1000.0;
}

#define DUK_USE_GET_MONOTONIC_TIME(ctx) get_mono_time(ctx)

and debugger transport peeks again work normally (100-200ms interval).

@svaarala svaarala merged commit 1b073c8 into master Aug 3, 2017
@svaarala svaarala deleted the add-monotonic-clock-config branch August 3, 2017 23:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant