aboutsummaryrefslogtreecommitdiffstats
path: root/process.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-06-16 23:22:42 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-06-16 23:22:42 +0000
commit18b199343843afe47caa2d73da82d1213e0a60b6 (patch)
treef09b984459b8e5f4a04e9e1211b66515cbf2232f /process.c
parent9a32f3774b73af1b986218f84881cb49ae0a9101 (diff)
downloadruby-18b199343843afe47caa2d73da82d1213e0a60b6.tar.gz
mjit.c: measure time more precisely
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63674 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'process.c')
-rw-r--r--process.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/process.c b/process.c
index 9e242a2605..a60c0df16b 100644
--- a/process.c
+++ b/process.c
@@ -7184,7 +7184,7 @@ make_clock_result(struct timetick *ttp,
}
#ifdef __APPLE__
-static mach_timebase_info_data_t *
+static const mach_timebase_info_data_t *
get_mach_timebase_info(void)
{
static mach_timebase_info_data_t sTimebaseInfo;
@@ -7195,6 +7195,14 @@ get_mach_timebase_info(void)
return &sTimebaseInfo;
}
+
+double
+ruby_real_ms_time(void)
+{
+ const mach_timebase_info_data_t *info = get_mach_timebase_info();
+ uint64_t t = mach_absolute_time();
+ return (double)t * info->numer / info->denom / 1e6;
+}
#endif
/*
@@ -7450,7 +7458,7 @@ rb_clock_gettime(int argc, VALUE *argv)
#ifdef __APPLE__
#define RUBY_MACH_ABSOLUTE_TIME_BASED_CLOCK_MONOTONIC ID2SYM(id_MACH_ABSOLUTE_TIME_BASED_CLOCK_MONOTONIC)
if (clk_id == RUBY_MACH_ABSOLUTE_TIME_BASED_CLOCK_MONOTONIC) {
- mach_timebase_info_data_t *info = get_mach_timebase_info();
+ const mach_timebase_info_data_t *info = get_mach_timebase_info();
uint64_t t = mach_absolute_time();
tt.count = (int32_t)(t % 1000000000);
tt.giga_count = t / 1000000000;
@@ -7589,7 +7597,7 @@ rb_clock_getres(int argc, VALUE *argv)
#ifdef RUBY_MACH_ABSOLUTE_TIME_BASED_CLOCK_MONOTONIC
if (clk_id == RUBY_MACH_ABSOLUTE_TIME_BASED_CLOCK_MONOTONIC) {
- mach_timebase_info_data_t *info = get_mach_timebase_info();
+ const mach_timebase_info_data_t *info = get_mach_timebase_info();
tt.count = 1;
tt.giga_count = 0;
numerators[num_numerators++] = info->numer;