Python time.clock_gettime() Examples

The following are 24 code examples for showing how to use time.clock_gettime(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module time , or try the search function .

Example 1
Project: android_universal   Author: bkerler   File: test_time.py    License: MIT License 6 votes vote down vote up
def test_time_ns_type(self):
        def check_ns(sec, ns):
            self.assertIsInstance(ns, int)

            sec_ns = int(sec * 1e9)
            # tolerate a difference of 50 ms
            self.assertLess((sec_ns - ns), 50 ** 6, (sec, ns))

        check_ns(time.time(),
                 time.time_ns())
        check_ns(time.monotonic(),
                 time.monotonic_ns())
        check_ns(time.perf_counter(),
                 time.perf_counter_ns())
        check_ns(time.process_time(),
                 time.process_time_ns())

        if hasattr(time, 'thread_time'):
            check_ns(time.thread_time(),
                     time.thread_time_ns())

        if hasattr(time, 'clock_gettime'):
            check_ns(time.clock_gettime(time.CLOCK_REALTIME),
                     time.clock_gettime_ns(time.CLOCK_REALTIME)) 
Example 2
Project: profiling   Author: what-studio   File: utils.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def thread_clock():
        return time.clock_gettime(time.CLOCK_THREAD_CPUTIME_ID)


#: Does nothing.  It allows any arguments. 
Example 3
Project: vulnix   Author: flyingcircusio   File: utils.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def __enter__(self):
        _log.debug('>>> %s', self.section)
        self.start = time.clock_gettime(time.CLOCK_MONOTONIC)
        return self 
Example 4
Project: vulnix   Author: flyingcircusio   File: utils.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def __exit__(self, *exc):
        self.end = time.clock_gettime(time.CLOCK_MONOTONIC)
        self.interval = self.end - self.start
        _log.debug('<<< %s %.2fs', self.section, self.interval)
        return False  # re-raise 
Example 5
Project: Fluid-Designer   Author: Microvellum   File: test_time.py    License: GNU General Public License v3.0 5 votes vote down vote up
def test_clock_realtime(self):
        time.clock_gettime(time.CLOCK_REALTIME) 
Example 6
Project: Fluid-Designer   Author: Microvellum   File: test_time.py    License: GNU General Public License v3.0 5 votes vote down vote up
def test_clock_monotonic(self):
        a = time.clock_gettime(time.CLOCK_MONOTONIC)
        b = time.clock_gettime(time.CLOCK_MONOTONIC)
        self.assertLessEqual(a, b) 
Example 7
Project: Fluid-Designer   Author: Microvellum   File: test_time.py    License: GNU General Public License v3.0 5 votes vote down vote up
def test_clock_settime(self):
        t = time.clock_gettime(time.CLOCK_REALTIME)
        try:
            time.clock_settime(time.CLOCK_REALTIME, t)
        except PermissionError:
            pass

        if hasattr(time, 'CLOCK_MONOTONIC'):
            self.assertRaises(OSError,
                              time.clock_settime, time.CLOCK_MONOTONIC, 0) 
Example 8
Project: Fluid-Designer   Author: Microvellum   File: test_time.py    License: GNU General Public License v3.0 5 votes vote down vote up
def test_monotonic_settime(self):
        t1 = time.monotonic()
        realtime = time.clock_gettime(time.CLOCK_REALTIME)
        # jump backward with an offset of 1 hour
        try:
            time.clock_settime(time.CLOCK_REALTIME, realtime - 3600)
        except PermissionError as err:
            self.skipTest(err)
        t2 = time.monotonic()
        time.clock_settime(time.CLOCK_REALTIME, realtime)
        # monotonic must not be affected by system clock updates
        self.assertGreaterEqual(t2, t1) 
Example 9
def _set_real_base(self, metaconvert):
        self._real_base = int(
            time.clock_gettime(time.CLOCK_REALTIME) *
            FFmpegPipeline.SECONDS_TO_NANOSECONDS)

        if ("tags" not in self.request):
            self.request["tags"] = {}

        self.request["tags"]["real_base"] = self._real_base

        properties = self._video_filter_map[metaconvert].properties
        properties["tags"] = "\'{}\'".format(
            json.dumps(self.request["tags"]).replace(':', r'\:')) 
Example 10
Project: PySyncObj   Author: bakwc   File: monotonic.py    License: MIT License 5 votes vote down vote up
def monotonic():
                """Monotonic clock, cannot go backward."""
                ts = timespec()
                if clock_gettime(CLOCK_MONOTONIC, ctypes.pointer(ts)):
                    errno = ctypes.get_errno()
                    raise OSError(errno, os.strerror(errno))
                return ts.tv_sec + ts.tv_nsec / 1.0e9

        # Perform a sanity-check. 
Example 11
Project: ironpython3   Author: IronLanguages   File: test_time.py    License: Apache License 2.0 5 votes vote down vote up
def test_clock_realtime(self):
        time.clock_gettime(time.CLOCK_REALTIME) 
Example 12
Project: ironpython3   Author: IronLanguages   File: test_time.py    License: Apache License 2.0 5 votes vote down vote up
def test_clock_monotonic(self):
        a = time.clock_gettime(time.CLOCK_MONOTONIC)
        b = time.clock_gettime(time.CLOCK_MONOTONIC)
        self.assertLessEqual(a, b) 
Example 13
Project: ironpython3   Author: IronLanguages   File: test_time.py    License: Apache License 2.0 5 votes vote down vote up
def test_clock_settime(self):
        t = time.clock_gettime(time.CLOCK_REALTIME)
        try:
            time.clock_settime(time.CLOCK_REALTIME, t)
        except PermissionError:
            pass

        if hasattr(time, 'CLOCK_MONOTONIC'):
            self.assertRaises(OSError,
                              time.clock_settime, time.CLOCK_MONOTONIC, 0) 
Example 14
Project: ironpython3   Author: IronLanguages   File: test_time.py    License: Apache License 2.0 5 votes vote down vote up
def test_monotonic_settime(self):
        t1 = time.monotonic()
        realtime = time.clock_gettime(time.CLOCK_REALTIME)
        # jump backward with an offset of 1 hour
        try:
            time.clock_settime(time.CLOCK_REALTIME, realtime - 3600)
        except PermissionError as err:
            self.skipTest(err)
        t2 = time.monotonic()
        time.clock_settime(time.CLOCK_REALTIME, realtime)
        # monotonic must not be affected by system clock updates
        self.assertGreaterEqual(t2, t1) 
Example 15
Project: lpdec   Author: supermihi   File: utils.py    License: GNU General Public License v3.0 5 votes vote down vote up
def clock():
        return time.clock_gettime(time.CLOCK_THREAD_CPUTIME_ID) 
Example 16
Project: Project-New-Reign---Nemesis-Main   Author: ShikyoKira   File: test_time.py    License: GNU General Public License v3.0 5 votes vote down vote up
def test_clock_realtime(self):
        time.clock_gettime(time.CLOCK_REALTIME) 
Example 17
Project: Project-New-Reign---Nemesis-Main   Author: ShikyoKira   File: test_time.py    License: GNU General Public License v3.0 5 votes vote down vote up
def test_clock_monotonic(self):
        a = time.clock_gettime(time.CLOCK_MONOTONIC)
        b = time.clock_gettime(time.CLOCK_MONOTONIC)
        self.assertLessEqual(a, b) 
Example 18
Project: Project-New-Reign---Nemesis-Main   Author: ShikyoKira   File: test_time.py    License: GNU General Public License v3.0 5 votes vote down vote up
def test_clock_settime(self):
        t = time.clock_gettime(time.CLOCK_REALTIME)
        try:
            time.clock_settime(time.CLOCK_REALTIME, t)
        except PermissionError:
            pass

        if hasattr(time, 'CLOCK_MONOTONIC'):
            self.assertRaises(OSError,
                              time.clock_settime, time.CLOCK_MONOTONIC, 0) 
Example 19
Project: Project-New-Reign---Nemesis-Main   Author: ShikyoKira   File: test_time.py    License: GNU General Public License v3.0 5 votes vote down vote up
def test_monotonic_settime(self):
        t1 = time.monotonic()
        realtime = time.clock_gettime(time.CLOCK_REALTIME)
        # jump backward with an offset of 1 hour
        try:
            time.clock_settime(time.CLOCK_REALTIME, realtime - 3600)
        except PermissionError as err:
            self.skipTest(err)
        t2 = time.monotonic()
        time.clock_settime(time.CLOCK_REALTIME, realtime)
        # monotonic must not be affected by system clock updates
        self.assertGreaterEqual(t2, t1) 
Example 20
Project: grove.py   Author: Seeed-Studio   File: __init__.py    License: MIT License 5 votes vote down vote up
def set_mode(self, mode=MODE_SLEEP, t_sb=t_sb_1000):
        # Writes ctrl_meas register with current temperature and pressure oversampling settings
        # Only changes the mode
        # If normal mode selected also sets the standby time in config register

        # Set class variables
        self.mode = mode
        self.t_sb = t_sb

        # If no measurements are enabled there is no point going into measurement
        if self.osrs_t + self.osrs_p + self.osrs_h == 0:
            print("No measurement enabled!\nSee set_oversampling()-function to enable measurement.")
            return 0

        try:
            # If normal mode set also t_sb(standby time)
            if self.mode == self.MODE_NORMAL:
                # Write normal mode standby time t_sb to config register
                self.__config(t_sb, self.filter, self.spi3w_en)
                # Write mode to ctr_meas register
                self.__ctrl_meas(self.osrs_t, self.osrs_p, self.mode)
            # Otherwise just change the mode in ctrl_meas register
            else:
                self.__ctrl_meas(self.osrs_t, self.osrs_p, self.mode)

            self.last_meas = clock_gettime(CLOCK_REALTIME)
            # Everything went well return 1
            return 1
        except Exception as e:
            # e = sys.exc_info()[0]
            print("<p>Error: %s</p>" % e)
            return 0

    #########################################################################
    # Set oversampling/enable measurement. OVRS_x0 disables the measurement #
    ######################################################################### 
Example 21
Project: android_universal   Author: bkerler   File: test_time.py    License: MIT License 5 votes vote down vote up
def test_clock_realtime(self):
        t = time.clock_gettime(time.CLOCK_REALTIME)
        self.assertIsInstance(t, float) 
Example 22
Project: android_universal   Author: bkerler   File: test_time.py    License: MIT License 5 votes vote down vote up
def test_clock_monotonic(self):
        a = time.clock_gettime(time.CLOCK_MONOTONIC)
        b = time.clock_gettime(time.CLOCK_MONOTONIC)
        self.assertLessEqual(a, b) 
Example 23
Project: android_universal   Author: bkerler   File: test_time.py    License: MIT License 5 votes vote down vote up
def test_pthread_getcpuclockid(self):
        clk_id = time.pthread_getcpuclockid(threading.get_ident())
        self.assertTrue(type(clk_id) is int)
        self.assertNotEqual(clk_id, time.CLOCK_THREAD_CPUTIME_ID)
        t1 = time.clock_gettime(clk_id)
        t2 = time.clock_gettime(clk_id)
        self.assertLessEqual(t1, t2) 
Example 24
Project: android_universal   Author: bkerler   File: test_time.py    License: MIT License 5 votes vote down vote up
def test_clock_settime(self):
        t = time.clock_gettime(time.CLOCK_REALTIME)
        try:
            time.clock_settime(time.CLOCK_REALTIME, t)
        except PermissionError:
            pass

        if hasattr(time, 'CLOCK_MONOTONIC'):
            self.assertRaises(OSError,
                              time.clock_settime, time.CLOCK_MONOTONIC, 0)