1/*****************************************************************************
2
3Copyright (c) 2013, 2014, Facebook, Inc. All Rights Reserved.
4Copyright (c) 2014, SkySQL Ab. All Rights Reserved.
5
6This program is free software; you can redistribute it and/or modify it under
7the terms of the GNU General Public License as published by the Free Software
8Foundation; version 2 of the License.
9
10This program is distributed in the hope that it will be useful, but WITHOUT
11ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License along with
15this program; if not, write to the Free Software Foundation, Inc.,
1651 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
17
18*****************************************************************************/
19
20/********************************************************************//**
21@file include/ut0timer.ic
22Timer rountines
23
24Created 30/07/2014 Jan Lindström jan.lindstrom@skysql.com
25modified from https://github.com/facebook/mysql-5.6/commit/c75a413edeb96eb99bf11d7269bdfea06f96d6b6
26*************************************************************************/
27
28/**************************************************************//**
29Return time passed since time then, automatically adjusted
30for the estimated timer overhead.
31@return time passed since "then" */
32UNIV_INLINE
33ulonglong
34ut_timer_since(
35/*===========*/
36 ulonglong then) /*!< in: time where to calculate */
37{
38 return (ut_timer_now() - then) - ut_timer.overhead;
39}
40
41/**************************************************************//**
42Get time passed since "then", and update then to now
43@return time passed sinche "then" */
44UNIV_INLINE
45ulonglong
46ut_timer_since_and_update(
47/*======================*/
48 ulonglong *then) /*!< in: time where to calculate */
49{
50 ulonglong now = ut_timer_now();
51 ulonglong ret = (now - (*then)) - ut_timer.overhead;
52 *then = now;
53 return ret;
54}
55
56/**************************************************************//**
57Convert native timer units in a ulonglong into seconds in a double
58@return time in a seconds */
59UNIV_INLINE
60double
61ut_timer_to_seconds(
62/*=================*/
63 ulonglong when) /*!< in: time where to calculate */
64{
65 double ret = (double)(when);
66 ret /= (double)(ut_timer.frequency);
67 return ret;
68}
69
70/**************************************************************//**
71Convert native timer units in a ulonglong into milliseconds in a double
72@return time in milliseconds */
73UNIV_INLINE
74double
75ut_timer_to_milliseconds(
76/*=====================*/
77 ulonglong when) /*!< in: time where to calculate */
78{
79 double ret = (double)(when);
80 ret *= 1000.0;
81 ret /= (double)(ut_timer.frequency);
82 return ret;
83}
84
85/**************************************************************//**
86Convert native timer units in a ulonglong into microseconds in a double
87@return time in microseconds */
88UNIV_INLINE
89double
90ut_timer_to_microseconds(
91/*=====================*/
92 ulonglong when) /*!< in: time where to calculate */
93{
94 double ret = (double)(when);
95 ret *= 1000000.0;
96 ret /= (double)(ut_timer.frequency);
97 return ret;
98}
99
100/**************************************************************//**
101Convert microseconds in a double to native timer units in a ulonglong
102@return time in microseconds */
103UNIV_INLINE
104ulonglong
105ut_microseconds_to_timer(
106/*=====================*/
107 ulonglong when) /*!< in: time where to calculate */
108{
109 double ret = (double)when;
110 ret *= (double)(ut_timer.frequency);
111 ret /= 1000000.0;
112 return (ulonglong)ret;
113}
114