コード例 #1
0
 def clock_getres(space, clk_id):
     with lltype.scoped_alloc(TIMESPEC) as timespec:
         ret = c_clock_getres(clk_id, timespec)
         if ret != 0:
             raise exception_from_saved_errno(space, space.w_OSError)
         secs = _timespec_to_seconds(timespec)
     return space.newfloat(secs)
コード例 #2
0
ファイル: interp_time.py プロジェクト: mozillazg/pypy
 def clock_getres(space, clk_id):
     with lltype.scoped_alloc(rtime.TIMESPEC) as tp:
         ret = rtime.c_clock_getres(clk_id, tp)
         if ret != 0:
             raise exception_from_saved_errno(space, space.w_IOError)
         t = float(rffi.getintfield(tp, "c_tv_sec")) + float(rffi.getintfield(tp, "c_tv_nsec")) * 0.000000001
     return space.wrap(t)
コード例 #3
0
 def clock_getres(space, clk_id):
     with lltype.scoped_alloc(rtime.TIMESPEC) as tp:
         ret = rtime.c_clock_getres(clk_id, tp)
         if ret != 0:
             raise exception_from_saved_errno(space, space.w_IOError)
         t = (float(rffi.getintfield(tp, 'c_tv_sec')) +
              float(rffi.getintfield(tp, 'c_tv_nsec')) * 0.000000001)
     return space.newfloat(t)
コード例 #4
0
ファイル: test_rtime.py プロジェクト: soIu/rpython
 def test_clock_getres(self):
     if not rtime.HAS_CLOCK_GETTIME:
         py.test.skip("no clock_gettime()")
     lst = []
     with lltype.scoped_alloc(rtime.TIMESPEC) as a1:
         res = rtime.c_clock_getres(rtime.CLOCK_MONOTONIC, a1)
         assert res == 0
         t = (float(rffi.getintfield(a1, 'c_tv_sec')) +
              float(rffi.getintfield(a1, 'c_tv_nsec')) * 0.000000001)
     assert 0.0 < t <= 1.0
コード例 #5
0
ファイル: test_rtime.py プロジェクト: mozillazg/pypy
 def test_clock_getres(self):
     if not rtime.HAS_CLOCK_GETTIME:
         py.test.skip("no clock_gettime()")
     lst = []
     with lltype.scoped_alloc(rtime.TIMESPEC) as a1:
         res = rtime.c_clock_getres(rtime.CLOCK_MONOTONIC, a1)
         assert res == 0
         t = (float(rffi.getintfield(a1, 'c_tv_sec')) +
              float(rffi.getintfield(a1, 'c_tv_nsec')) * 0.000000001)
     assert 0.0 < t <= 1.0
コード例 #6
0
    def process_time(space, w_info=None):
        if HAS_CLOCK_GETTIME and (rtime.CLOCK_PROF is not None or
                                  rtime.CLOCK_PROCESS_CPUTIME_ID is not None):
            if rtime.CLOCK_PROF is not None:
                clk_id = rtime.CLOCK_PROF
                implementation = "clock_gettime(CLOCK_PROF)"
            else:
                clk_id = rtime.CLOCK_PROCESS_CPUTIME_ID
                implementation = "clock_gettime(CLOCK_PROCESS_CPUTIME_ID)"
            with lltype.scoped_alloc(TIMESPEC) as timespec:
                ret = c_clock_gettime(clk_id, timespec)
                if ret == 0:
                    if w_info is not None:
                        with lltype.scoped_alloc(TIMESPEC) as tsres:
                            ret = c_clock_getres(clk_id, tsres)
                            if ret == 0:
                                res = _timespec_to_seconds(tsres)
                            else:
                                res = 1e-9
                        _setinfo(space, w_info, implementation, res, True,
                                 False)
                    return space.newfloat(_timespec_to_seconds(timespec))

        if True:  # XXX available except if it isn't?
            from rpython.rlib.rtime import (c_getrusage, RUSAGE, RUSAGE_SELF,
                                            decode_timeval)
            with lltype.scoped_alloc(RUSAGE) as rusage:
                ret = c_getrusage(RUSAGE_SELF, rusage)
                if ret == 0:
                    if w_info is not None:
                        _setinfo(space, w_info, "getrusage(RUSAGE_SELF)", 1e-6,
                                 True, False)
                    return space.newfloat(
                        decode_timeval(rusage.c_ru_utime) +
                        decode_timeval(rusage.c_ru_stime))
        if have_times:
            with lltype.scoped_alloc(rposix.TMS) as tms:
                ret = rposix.c_times(tms)
                if rffi.cast(lltype.Signed, ret) != -1:
                    cpu_time = float(
                        rffi.cast(lltype.Signed, tms.c_tms_utime) +
                        rffi.cast(lltype.Signed, tms.c_tms_stime))
                    if w_info is not None:
                        _setinfo(space, w_info, "times()",
                                 1.0 / rposix.CLOCK_TICKS_PER_SECOND, True,
                                 False)
                    return space.newfloat(cpu_time /
                                          rposix.CLOCK_TICKS_PER_SECOND)
        return clock(space)
コード例 #7
0
 def monotonic(space, w_info=None):
     if rtime.CLOCK_HIGHRES is not None:
         clk_id = rtime.CLOCK_HIGHRES
         implementation = "clock_gettime(CLOCK_HIGHRES)"
     else:
         clk_id = rtime.CLOCK_MONOTONIC
         implementation = "clock_gettime(CLOCK_MONOTONIC)"
     w_result = clock_gettime(space, clk_id)
     if w_info is not None:
         with lltype.scoped_alloc(TIMESPEC) as tsres:
             ret = c_clock_getres(clk_id, tsres)
             if ret == 0:
                 res = _timespec_to_seconds(tsres)
             else:
                 res = 1e-9
         _setinfo(space, w_info, implementation, res, True, False)
     return w_result
コード例 #8
0
def time(space, w_info=None):
    """time() -> floating point number

    Return the current time in seconds since the Epoch.
    Fractions of a second may be present if the system clock provides them."""
    if HAS_CLOCK_GETTIME:
        with lltype.scoped_alloc(TIMESPEC) as timespec:
            ret = c_clock_gettime(rtime.CLOCK_REALTIME, timespec)
            if ret == 0:
                if w_info is not None:
                    with lltype.scoped_alloc(TIMESPEC) as tsres:
                        ret = c_clock_getres(rtime.CLOCK_REALTIME, tsres)
                        if ret == 0:
                            res = _timespec_to_seconds(tsres)
                        else:
                            res = 1e-9
                        _setinfo(space, w_info,
                                 "clock_gettime(CLOCK_REALTIME)", res, False,
                                 True)
                return space.newfloat(_timespec_to_seconds(timespec))
    else:
        return gettimeofday(space, w_info)