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::reclamation::detail {
12 #ifdef WITH_PERF_COUNTER
13 struct perf_counter {
14  perf_counter(std::size_t& counter) : counter(counter), cnt() {}
15  ~perf_counter() { counter += cnt; }
16  void inc() { ++cnt; }
17 
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  perf_counter() = default;
28  void inc() {}
29 };
30 
31  #define PERF_COUNTER(name, counter) xenium::reclamation::detail::perf_counter name;
32  #define INC_PERF_CNT(counter)
33 #endif
34 } // namespace xenium::reclamation::detail
35 
36 #endif