Atlas Runtime
stats.hpp
Go to the documentation of this file.
1 /*
2  * (c) Copyright 2016 Hewlett Packard Enterprise Development LP
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as
6  * published by the Free Software Foundation, either version 3 of the
7  * License, or (at your option) any later version. This program is
8  * distributed in the hope that it will be useful, but WITHOUT ANY
9  * WARRANTY; without even the implied warranty of MERCHANTABILITY or
10  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
11  * for more details. You should have received a copy of the GNU Lesser
12  * General Public License along with this program. If not, see
13  * <http://www.gnu.org/licenses/>.
14  */
15 
16 
17 #ifndef STATS_HPP
18 #define STATS_HPP
19 
20 #include <cstdlib>
21 #include <cassert>
22 
23 #include <stdint.h>
24 #include <pthread.h>
25 
26 namespace Atlas {
27 
28 class Stats {
29  static Stats *Instance_;
30 public:
31 
32  static Stats& createInstance() {
33  assert(!Instance_);
34  Instance_ = new Stats();
35  return *Instance_;
36  }
37 
38  static void deleteInstance() {
39  assert(Instance_);
40  delete Instance_;
41  Instance_ = nullptr;
42  }
43 
44  static Stats& getInstance() {
45  assert(Instance_);
46  return *Instance_;
47  }
48 
49  void acquireLock()
50  { int status = pthread_mutex_lock(&Lock_); assert(!status); }
51  void releaseLock()
52  { int status = pthread_mutex_unlock(&Lock_); assert(!status); }
53 
55  { ++TL_CriticalSectionCount; }
57  { ++TL_NestedCriticalSectionCount; }
59  { ++TL_LoggedStoreCount; }
61  { ++TL_CriticalLoggedStoreCount; }
63  { ++TL_UnloggedStoreCount; }
65  { ++TL_LogElisionFailCount; }
67  { ++TL_UnloggedCriticalStoreCount; }
68  void incrementLogMemUse(size_t sz)
69  { TL_LogMemUse += sz; }
70 
71  void print();
72 
73 private:
74  pthread_mutex_t Lock_;
75 
76  // Computed as the number of lock acquires
77  thread_local static uint64_t TL_CriticalSectionCount;
78 
79  // Given a lock acquire operation, if there is a lock already held
80  thread_local static uint64_t TL_NestedCriticalSectionCount;
81 
82  // Total number of writes logged (memset/memcpy, etc. counted as 1)
83  thread_local static uint64_t TL_LoggedStoreCount;
84 
85  // Total number of writes encountered within critical sections
86  thread_local static uint64_t TL_CriticalLoggedStoreCount;
87 
88  // Total number of writes not logged
89  thread_local static uint64_t TL_UnloggedStoreCount;
90 
91  // Total number of writes for which log elision failed
92  thread_local static uint64_t TL_LogElisionFailCount;
93 
94  // Total number of writes not logged within critical sections
95  thread_local static uint64_t TL_UnloggedCriticalStoreCount;
96 
97  // Total memory used by the program log
98  thread_local static uint64_t TL_LogMemUse;
99 
100  // Total number of CPU cache flushes for logging
101  thread_local static uint64_t TL_NumLogFlushes;
102 };
103 
104 } // namespace Atlas
105 
106 #endif
void incrementLoggedStoreCount()
Definition: stats.hpp:58
void incrementCriticalLoggedStoreCount()
Definition: stats.hpp:60
void releaseLock()
Definition: stats.hpp:51
static Stats & getInstance()
Definition: stats.hpp:44
Definition: stats.hpp:28
void acquireLock()
Definition: stats.hpp:49
void incrementNestedCriticalSectionCount()
Definition: stats.hpp:56
void print()
Definition: stats.cpp:44
void incrementCriticalSectionCount()
Definition: stats.hpp:54
static Stats & createInstance()
Definition: stats.hpp:32
void incrementUnloggedStoreCount()
Definition: stats.hpp:62
void incrementUnloggedCriticalStoreCount()
Definition: stats.hpp:66
void incrementLogMemUse(size_t sz)
Definition: stats.hpp:68
Definition: atlas_alloc_cpp.hpp:21
static void deleteInstance()
Definition: stats.hpp:38
void incrementLogElisionFailCount()
Definition: stats.hpp:64