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.h
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#ifndef ut0timer_h
28#define ut0timer_h
29
30#include "univ.i"
31#include "data0type.h"
32#include <my_rdtsc.h>
33
34/* Current timer stats */
35extern struct my_timer_unit_info ut_timer;
36
37/**************************************************************//**
38Function pointer to point selected timer function.
39@return timer current value */
40extern ulonglong (*ut_timer_now)(void);
41
42/**************************************************************//**
43Sets up the data required for use of my_timer_* functions.
44Selects the best timer by high frequency, and tight resolution.
45Points my_timer_now() to the selected timer function.
46Initializes my_timer struct to contain the info for selected timer.*/
47UNIV_INTERN
48void ut_init_timer(void);
49
50/**************************************************************//**
51Return time passed since time then, automatically adjusted
52for the estimated timer overhead.
53@return time passed since "then" */
54UNIV_INLINE
55ulonglong
56ut_timer_since(
57/*===========*/
58 ulonglong then); /*!< in: time where to calculate */
59/**************************************************************//**
60Get time passed since "then", and update then to now
61@return time passed sinche "then" */
62UNIV_INLINE
63ulonglong
64ut_timer_since_and_update(
65/*======================*/
66 ulonglong *then); /*!< in: time where to calculate */
67/**************************************************************//**
68Convert native timer units in a ulonglong into seconds in a double
69@return time in a seconds */
70UNIV_INLINE
71double
72ut_timer_to_seconds(
73/*=================*/
74 ulonglong when); /*!< in: time where to calculate */
75/**************************************************************//**
76Convert native timer units in a ulonglong into milliseconds in a double
77@return time in milliseconds */
78UNIV_INLINE
79double
80ut_timer_to_milliseconds(
81/*=====================*/
82 ulonglong when); /*!< in: time where to calculate */
83/**************************************************************//**
84Convert native timer units in a ulonglong into microseconds in a double
85@return time in microseconds */
86UNIV_INLINE
87double
88ut_timer_to_microseconds(
89/*=====================*/
90 ulonglong when); /*!< in: time where to calculate */
91/**************************************************************//**
92Convert microseconds in a double to native timer units in a ulonglong
93@return time in microseconds */
94UNIV_INLINE
95ulonglong
96ut_microseconds_to_timer(
97/*=====================*/
98 ulonglong when); /*!< in: time where to calculate */
99
100#include "ut0timer.ic"
101
102#endif
103