xenium
perf_counter.hpp
1 //
2 // Copyright (c) 2018-2020 Manuel Pöter.
3 // Licensed under the MIT License. See LICENSE file in the project root for full license information.
4 //
5 
6 #ifndef XENIUM_RECLAMATION_DETAIL_PERF_COUNTER_HPP
7 #define XENIUM_RECLAMATION_DETAIL_PERF_COUNTER_HPP
8 
9 #include <cstdint>
10 
11 namespace xenium { namespace reclamation { namespace detail {
12 #ifdef WITH_PERF_COUNTER
13  struct perf_counter
14  {
15  perf_counter(std::size_t& counter) : counter(counter), cnt() {}
16  ~perf_counter() { counter += cnt; }
17  void inc() { ++cnt; }
18  private:
19  std::size_t& counter;
20  std::size_t cnt;
21  };
22 
23  #define PERF_COUNTER(name, counter) xenium::reclamation::detail::perf_counter name(counter);
24  #define INC_PERF_CNT(counter) ++counter;
25 #else
26  struct perf_counter
27  {
28  perf_counter() {}
29  void inc() {}
30  };
31 
32  #define PERF_COUNTER(name, counter) xenium::reclamation::detail::perf_counter name;
33  #define INC_PERF_CNT(counter)
34 #endif
35 }}}
36 
37 #endif