| 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.ic | 
|---|
| 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 |  | 
|---|
| 28 | /**************************************************************//** | 
|---|
| 29 | Return time passed since time then, automatically adjusted | 
|---|
| 30 | for the estimated timer overhead. | 
|---|
| 31 | @return	time passed since "then" */ | 
|---|
| 32 | UNIV_INLINE | 
|---|
| 33 | ulonglong | 
|---|
| 34 | ut_timer_since( | 
|---|
| 35 | /*===========*/ | 
|---|
| 36 | ulonglong	then) /*!< in: time where to calculate */ | 
|---|
| 37 | { | 
|---|
| 38 | return (ut_timer_now() - then) - ut_timer.overhead; | 
|---|
| 39 | } | 
|---|
| 40 |  | 
|---|
| 41 | /**************************************************************//** | 
|---|
| 42 | Get time passed since "then", and update then to now | 
|---|
| 43 | @return time passed sinche "then" */ | 
|---|
| 44 | UNIV_INLINE | 
|---|
| 45 | ulonglong | 
|---|
| 46 | ut_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 | /**************************************************************//** | 
|---|
| 57 | Convert native timer units in a ulonglong into seconds in a double | 
|---|
| 58 | @return time in a seconds */ | 
|---|
| 59 | UNIV_INLINE | 
|---|
| 60 | double | 
|---|
| 61 | ut_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 | /**************************************************************//** | 
|---|
| 71 | Convert native timer units in a ulonglong into milliseconds in a double | 
|---|
| 72 | @return time in milliseconds */ | 
|---|
| 73 | UNIV_INLINE | 
|---|
| 74 | double | 
|---|
| 75 | ut_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 | /**************************************************************//** | 
|---|
| 86 | Convert native timer units in a ulonglong into microseconds in a double | 
|---|
| 87 | @return time in microseconds */ | 
|---|
| 88 | UNIV_INLINE | 
|---|
| 89 | double | 
|---|
| 90 | ut_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 | /**************************************************************//** | 
|---|
| 101 | Convert microseconds in a double to native timer units in a ulonglong | 
|---|
| 102 | @return time in microseconds */ | 
|---|
| 103 | UNIV_INLINE | 
|---|
| 104 | ulonglong | 
|---|
| 105 | ut_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 |  | 
|---|