MongoDB  2.7.0
timer.h
1 // @file timer.h
2 
3 /* Copyright 2010 10gen Inc.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #pragma once
19 
20 #include "mongo/client/export_macros.h"
21 
22 namespace mongo {
23 
35  class MONGO_CLIENT_API Timer /*copyable*/ {
36  public:
37  static const unsigned long long millisPerSecond = 1000;
38  static const unsigned long long microsPerSecond = 1000 * millisPerSecond;
39  static const unsigned long long nanosPerSecond = 1000 * microsPerSecond;
40 
41  Timer() { reset(); }
42  int seconds() const { return (int)(micros() / 1000000); }
43  int millis() const { return (int)(micros() / 1000); }
44  int minutes() const { return seconds() / 60; }
45 
46 
50  inline int millisReset() {
51  unsigned long long nextNow = now();
52  unsigned long long deltaMicros =
53  ((nextNow - _old) * microsPerSecond) / _countsPerSecond;
54 
55  _old = nextNow;
56  return static_cast<int>(deltaMicros / 1000);
57  }
58 
59  inline unsigned long long micros() const {
60  return ((now() - _old) * microsPerSecond) / _countsPerSecond;
61  }
62 
63  inline void reset() { _old = now(); }
64 
73  static unsigned long long _countsPerSecond;
74 
75  private:
76  inline unsigned long long now() const;
77 
78  unsigned long long _old;
79  };
80 } // namespace mongo
81 
82 #include "mongo/util/timer-inl.h"
Time tracking object.
Definition: timer.h:35
static unsigned long long _countsPerSecond
Internally, the timer counts platform-dependent ticks of some sort, and must then convert those ticks...
Definition: timer.h:73
int millisReset()
Get the time interval and reset at the same time.
Definition: timer.h:50