test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
StorageAccount.h
Go to the documentation of this file.
1 #ifndef STORAGE_FACTORY_STORAGE_ACCOUNT_H
2 # define STORAGE_FACTORY_STORAGE_ACCOUNT_H
3 
4 # include <stdint.h>
5 # include <string>
6 # include <chrono>
7 # include <atomic>
8 # include <map>
9 # include <memory>
10 # include "tbb/concurrent_unordered_map.h"
11 
13 public:
14 
15  enum class Operation {
16  check,
17  close,
18  construct,
19  destruct,
20  flush,
21  open,
22  position,
23  prefetch,
24  read,
25  readActual,
26  readAsync,
29  readv,
30  resize,
31  seek,
32  stagein,
33  stat,
34  write,
37  writev
38  };
39 
40  struct Counter {
42  attempts{0},
43  successes{0},
44  amount{0},
45  amount_square{0.},
46  vector_count{0},
47  vector_square{0},
48  timeTotal{0.},
49  timeMin{0.},
50  timeMax{0.} {}
51 
52  Counter(Counter&& ) = default;
53 
54  //NOTE: This is needed by tbb::concurrent_unordered_map when it
55  // is constructing a new one. This would not give correct results
56  // if the object being passed were being updated, but that is not
57  // the case for operator[]
58  Counter( Counter const& iOther):
59  attempts{iOther.attempts.load()},
60  successes{iOther.successes.load()},
61  amount{iOther.amount.load()},
62  amount_square{iOther.amount_square.load()},
63  vector_count{iOther.vector_count.load()},
64  vector_square{iOther.vector_square.load()},
65  timeTotal{iOther.timeTotal.load()},
66  timeMin{iOther.timeMin.load()},
67  timeMax{iOther.timeMax.load()} {}
68 
69  //Use atomics to allow concurrent read/write for intermediate
70  // output of the statics while running. The values obtained
71  // won't be completely consistent but should be good enough for
72  // monitoring. The values obtained once the program is shutting
73  // down should be completely consistent.
74 
75  std::atomic<uint64_t> attempts;
76  std::atomic<uint64_t> successes;
77  std::atomic<uint64_t> amount;
78  // NOTE: Significant risk exists for underflow in this value.
79  // However, the use cases are marginal so I let it pass.
80  std::atomic<double> amount_square;
81  std::atomic<int64_t> vector_count;
82  std::atomic<int64_t> vector_square;
83  std::atomic<double> timeTotal;
84  std::atomic<double> timeMin;
85  std::atomic<double> timeMax;
86 
87  static void addTo(std::atomic<double>& iAtomic, double iToAdd) {
88  double oldValue = iAtomic.load();
89  double newValue = oldValue + iToAdd;
90  while( not iAtomic.compare_exchange_weak(oldValue, newValue)) {
91  newValue = oldValue+iToAdd;
92  }
93  }
94  };
95 
96  class Stamp {
97  public:
99 
100  void tick (uint64_t amount = 0, int64_t tick = 0) const;
101  protected:
103  std::chrono::time_point<std::chrono::high_resolution_clock> m_start;
104  };
105 
107  public:
108  StorageClassToken(StorageClassToken const&) = default;
109  int value() const { return m_value;}
110 
111  friend class StorageAccount;
112  private:
113  StorageClassToken() = delete;
114  explicit StorageClassToken(int iValue) : m_value{iValue} {}
115 
116  int m_value;
117 
118  };
119 
120  typedef tbb::concurrent_unordered_map<int, Counter> OperationStats;
121  typedef tbb::concurrent_unordered_map<int, OperationStats > StorageStats;
122 
123  static char const* operationName(Operation operation);
126 
127  static const StorageStats& summary(void);
128  static std::string summaryText(bool banner=false);
129  static void fillSummary(std::map<std::string, std::string> &summary);
131  Operation operation);
132 
133 private:
135 
136 };
137 
138 #endif // STORAGE_FACTORY_STORAGE_ACCOUNT_H
static StorageStats m_stats
static void fillSummary(std::map< std::string, std::string > &summary)
static char const * operationName(Operation operation)
std::atomic< double > timeMax
static const StorageStats & summary(void)
std::atomic< uint64_t > attempts
std::atomic< int64_t > vector_square
std::atomic< int64_t > vector_count
tbb::concurrent_unordered_map< int, OperationStats > StorageStats
std::atomic< double > timeMin
std::chrono::time_point< std::chrono::high_resolution_clock > m_start
static StorageClassToken tokenForStorageClassName(std::string const &iName)
std::atomic< uint64_t > successes
Counter(Counter const &iOther)
tbb::concurrent_unordered_map< int, Counter > OperationStats
static void addTo(std::atomic< double > &iAtomic, double iToAdd)
static const std::string & nameForToken(StorageClassToken)
std::atomic< double > amount_square
std::atomic< uint64_t > amount
static Counter & counter(StorageClassToken token, Operation operation)
unsigned long long uint64_t
Definition: Time.h:15
void tick(uint64_t amount=0, int64_t tick=0) const
Stamp(Counter &counter)
static std::string summaryText(bool banner=false)
std::atomic< double > timeTotal