| 1 | /***************************************************************************** |
| 2 | |
| 3 | Copyright (c) 2013, 2014, Facebook, Inc. All Rights Reserved. |
| 4 | Copyright (c) 2014, SkySQL Ab. All Rights Reserved. |
| 5 | |
| 6 | This program is free software; you can redistribute it and/or modify it under |
| 7 | the terms of the GNU General Public License as published by the Free Software |
| 8 | Foundation; version 2 of the License. |
| 9 | |
| 10 | This program is distributed in the hope that it will be useful, but WITHOUT |
| 11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 12 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
| 13 | |
| 14 | You should have received a copy of the GNU General Public License along with |
| 15 | this program; if not, write to the Free Software Foundation, Inc., |
| 16 | 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA |
| 17 | |
| 18 | *****************************************************************************/ |
| 19 | |
| 20 | /********************************************************************//** |
| 21 | @file include/ut0timer.h |
| 22 | Timer rountines |
| 23 | |
| 24 | Created 30/07/2014 Jan Lindström jan.lindstrom@skysql.com |
| 25 | modified 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 */ |
| 35 | extern struct my_timer_unit_info ut_timer; |
| 36 | |
| 37 | /**************************************************************//** |
| 38 | Function pointer to point selected timer function. |
| 39 | @return timer current value */ |
| 40 | extern ulonglong (*ut_timer_now)(void); |
| 41 | |
| 42 | /**************************************************************//** |
| 43 | Sets up the data required for use of my_timer_* functions. |
| 44 | Selects the best timer by high frequency, and tight resolution. |
| 45 | Points my_timer_now() to the selected timer function. |
| 46 | Initializes my_timer struct to contain the info for selected timer.*/ |
| 47 | UNIV_INTERN |
| 48 | void ut_init_timer(void); |
| 49 | |
| 50 | /**************************************************************//** |
| 51 | Return time passed since time then, automatically adjusted |
| 52 | for the estimated timer overhead. |
| 53 | @return time passed since "then" */ |
| 54 | UNIV_INLINE |
| 55 | ulonglong |
| 56 | ut_timer_since( |
| 57 | /*===========*/ |
| 58 | ulonglong then); /*!< in: time where to calculate */ |
| 59 | /**************************************************************//** |
| 60 | Get time passed since "then", and update then to now |
| 61 | @return time passed sinche "then" */ |
| 62 | UNIV_INLINE |
| 63 | ulonglong |
| 64 | ut_timer_since_and_update( |
| 65 | /*======================*/ |
| 66 | ulonglong *then); /*!< in: time where to calculate */ |
| 67 | /**************************************************************//** |
| 68 | Convert native timer units in a ulonglong into seconds in a double |
| 69 | @return time in a seconds */ |
| 70 | UNIV_INLINE |
| 71 | double |
| 72 | ut_timer_to_seconds( |
| 73 | /*=================*/ |
| 74 | ulonglong when); /*!< in: time where to calculate */ |
| 75 | /**************************************************************//** |
| 76 | Convert native timer units in a ulonglong into milliseconds in a double |
| 77 | @return time in milliseconds */ |
| 78 | UNIV_INLINE |
| 79 | double |
| 80 | ut_timer_to_milliseconds( |
| 81 | /*=====================*/ |
| 82 | ulonglong when); /*!< in: time where to calculate */ |
| 83 | /**************************************************************//** |
| 84 | Convert native timer units in a ulonglong into microseconds in a double |
| 85 | @return time in microseconds */ |
| 86 | UNIV_INLINE |
| 87 | double |
| 88 | ut_timer_to_microseconds( |
| 89 | /*=====================*/ |
| 90 | ulonglong when); /*!< in: time where to calculate */ |
| 91 | /**************************************************************//** |
| 92 | Convert microseconds in a double to native timer units in a ulonglong |
| 93 | @return time in microseconds */ |
| 94 | UNIV_INLINE |
| 95 | ulonglong |
| 96 | ut_microseconds_to_timer( |
| 97 | /*=====================*/ |
| 98 | ulonglong when); /*!< in: time where to calculate */ |
| 99 | |
| 100 | #include "ut0timer.ic" |
| 101 | |
| 102 | #endif |
| 103 | |