libfoedus-core
FOEDUS Core Library
rdtsc_watch.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014-2015, Hewlett-Packard Development Company, LP.
3  * This program is free software; you can redistribute it and/or modify it
4  * under the terms of the GNU General Public License as published by the Free
5  * Software Foundation; either version 2 of the License, or (at your option)
6  * any later version.
7  *
8  * This program is distributed in the hope that it will be useful, but WITHOUT
9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11  * more details. You should have received a copy of the GNU General Public
12  * License along with this program; if not, write to the Free Software
13  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14  *
15  * HP designates this particular file as subject to the "Classpath" exception
16  * as provided by HP in the LICENSE.txt file that accompanied this code.
17  */
18 #ifndef FOEDUS_DEBUGGING_RDTSC_WATCH_HPP_
19 #define FOEDUS_DEBUGGING_RDTSC_WATCH_HPP_
20 
21 #include <stdint.h>
22 
23 #include "foedus/compiler.hpp"
25 
26 namespace foedus {
27 namespace debugging {
37 class RdtscWatch {
38  public:
39  inline RdtscWatch() ALWAYS_INLINE : started_(0), stopped_(0) { start(); }
40 
42  inline void start() ALWAYS_INLINE {
43  started_ = get_rdtsc();
44  }
45 
47  inline uint64_t stop() ALWAYS_INLINE {
48  stopped_ = get_rdtsc();
49  return elapsed();
50  }
51 
52  inline uint64_t elapsed() const ALWAYS_INLINE {
53  return stopped_ - started_;
54  }
55 
56  private:
57  uint64_t started_;
58  uint64_t stopped_;
59 };
60 
61 } // namespace debugging
62 } // namespace foedus
63 
64 #endif // FOEDUS_DEBUGGING_RDTSC_WATCH_HPP_
Root package of FOEDUS (Fast Optimistic Engine for Data Unification Services).
Definition: assert_nd.hpp:44
uint64_t elapsed() const __attribute__((always_inline))
Definition: rdtsc_watch.hpp:52
uint64_t get_rdtsc()
Returns the current CPU cycle via x86 RDTSC.
Definition: rdtsc.hpp:35
RdtscWatch() __attribute__((always_inline))
Definition: rdtsc_watch.hpp:39
void start() __attribute__((always_inline))
Take current time tick.
Definition: rdtsc_watch.hpp:42
A RDTSC-based low-overhead stop watch.
Definition: rdtsc_watch.hpp:37
Implements an RDTSC (Real-time time stamp counter) wait to emulate latency on slower devices...
uint64_t stop() __attribute__((always_inline))
Take another current time tick.
Definition: rdtsc_watch.hpp:47
#define ALWAYS_INLINE
A function suffix to hint that the function should always be inlined.
Definition: compiler.hpp:106