MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NdbTimer.hpp
1 /*
2  Copyright (C) 2003-2006 MySQL AB
3  All rights reserved. Use is subject to license terms.
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; version 2 of the License.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
19 #ifndef NDBTIMER_H
20 #define NDBTIMER_H
21 
22 #include <NdbTick.h>
23 #include <NdbOut.hpp>
24 
25 //
26 // Class used for measuring time and priting the results
27 //
28 // Currently measures time in milliseconds
29 //
30 
31 class NdbTimer
32 {
33 public:
34 
35  NdbTimer();
36  ~NdbTimer() {};
37 
38  void doStart();
39  void doStop();
40  void doReset();
41  NDB_TICKS elapsedTime();
42  void printTransactionStatistics(const char* text,
43  int numTransactions,
44  int numOperations);
45  void printTestTimer(int numLoops,
46  int numRecords);
47  void printTotalTime(void);
48 private:
49  NDB_TICKS startTime;
50  NDB_TICKS stopTime;
51 };
52 
53 inline NdbTimer::NdbTimer(){
54  doReset();
55 }
56 
57 inline void NdbTimer::doReset(void){
58  startTime = 0;
59  stopTime = 0;
60 }
61 
62 inline void NdbTimer::doStart(void){
63  startTime = NdbTick_CurrentMillisecond();
64 }
65 
66 inline void NdbTimer::doStop(void){
67  stopTime = NdbTick_CurrentMillisecond();
68 }
69 
70 inline NDB_TICKS NdbTimer::elapsedTime(void){
71  return (stopTime - startTime);
72 }
73 
74 inline void NdbTimer::printTransactionStatistics(const char* text,
75  int numTransactions,
76  int numOperations){
77 
78  // Convert to Uint32 in order to be able to print it to screen
79  Uint32 lapTime = (Uint32)elapsedTime();
80  ndbout_c("%i transactions, %i %s total time = %d ms\nAverage %f ms/transaction, %f ms/%s.\n%f transactions/second, %f %ss/second.\n",
81  numTransactions, numTransactions*numOperations, text, lapTime,
82  ((double)lapTime/numTransactions), ((double)lapTime/(numTransactions*numOperations)), text,
83  1000.0/((double)lapTime/numOperations), 1000.0/((double)lapTime/(numTransactions*numOperations)), text);
84 }
85 
86 
87 
88 inline void NdbTimer::printTestTimer(int numLoops,
89  int numRecords){
90  // Convert to Uint32 in order to be able to print it to screen
91  Uint32 lapTime = (Uint32)elapsedTime();
92  ndbout_c("%i loop * %i records, total time = %d ms\nAverage %f ms/loop, %f ms/record.\n%f looop/second, %f records/second.\n",
93  numLoops, numRecords, lapTime,
94  ((double)lapTime/numLoops), ((double)lapTime/(numLoops*numRecords)),
95  1000.0/((double)lapTime/numLoops), 1000.0/((double)lapTime/(numLoops*numRecords)));
96 }
97 
98 
99 inline void NdbTimer::printTotalTime(void){
100  // Convert to Uint32 in order to be able to print it to screen
101  Uint32 lapTime = (Uint32)elapsedTime();
102  Uint32 secTime = lapTime/1000;
103  ndbout_c("Total time : %d seconds (%d ms)\n", secTime, lapTime);
104 }
105 
106 
107 
108 
109 
110 
111 #endif