HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
counterAccumulator.h
Go to the documentation of this file.
1 //
2 // Copyright 2018 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 
8 #ifndef PXR_BASE_TRACE_COUNTER_ACCUMULATOR_H
9 #define PXR_BASE_TRACE_COUNTER_ACCUMULATOR_H
10 
11 #include "pxr/pxr.h"
12 
13 #include "pxr/base/trace/api.h"
15 
16 #include "pxr/base/tf/token.h"
17 
18 #include <map>
19 #include <unordered_map>
20 #include <vector>
21 
23 
24 ////////////////////////////////////////////////////////////////////////////////
25 /// \class TraceCounterAccumulator
26 ///
27 /// This class accumulates counter values from TraceCollection instances.
28 /// A TraceCounterAccumulator instance can accumulate counters from multiple
29 /// collections or the state of the counters can be set explicitly through
30 /// SetCurrentValues().
31 ///
32 ///
34 public:
35  using CounterValues = std::vector<std::pair<TraceEvent::TimeStamp, double>>;
36  using CounterValuesMap =
37  std::unordered_map<TfToken, CounterValues, TfToken::HashFunctor>;
38  using CounterMap =
39  std::unordered_map<TfToken, double, TfToken::HashFunctor>;
40 
41  /// Constructor.
42  TraceCounterAccumulator() = default;
43 
44  /// Returns a map of the counter values over time.
45  const CounterValuesMap& GetCounters() const {
46  return _counterValuesOverTime;
47  }
48 
49  /// Sets the current value of the counters.
51 
52  /// Returns the current value of the counters.
53  const CounterMap& GetCurrentValues() const {
54  return _currentValues;
55  }
56 
57  /// Reads events /p collection and updates the current values of the
58  /// counters.
59  TRACE_API void Update(const TraceCollection& collection);
60 
61 protected:
62  /// Determines whether or not counter events with \p id should be processed.
63  virtual bool _AcceptsCategory(TraceCategoryId id) = 0;
64 
65 private:
66  // TraceCollection::Visitor Interface
67  virtual void OnBeginCollection() override;
68  virtual void OnEndCollection() override;
69  virtual void OnBeginThread(const TraceThreadId&) override;
70  virtual void OnEndThread(const TraceThreadId&) override;
71  virtual bool AcceptsCategory(TraceCategoryId) override;
72  virtual void OnEvent(
73  const TraceThreadId&, const TfToken&, const TraceEvent&) override;
74 
75  struct _CounterValue {
76  double value;
77  bool isDelta;
78  };
79 
80  using _CounterDeltaValues =
81  std::multimap<TraceEvent::TimeStamp, _CounterValue>;
82  using _CounterDeltaMap = std::map<TfToken, _CounterDeltaValues>;
83 
84  _CounterDeltaMap _counterDeltas;
85  CounterValuesMap _counterValuesOverTime;
86  CounterMap _currentValues;
87 };
88 
90 
91 #endif //PXR_BASE_TRACE_COUNTER_ACCUMULATOR_H
TraceCounterAccumulator()=default
Constructor.
TRACE_API void Update(const TraceCollection &collection)
std::vector< std::pair< TraceEvent::TimeStamp, double >> CounterValues
GLsizei const GLfloat * value
Definition: glcorearb.h:824
virtual bool _AcceptsCategory(TraceCategoryId id)=0
Determines whether or not counter events with id should be processed.
std::unordered_map< TfToken, CounterValues, TfToken::HashFunctor > CounterValuesMap
Definition: token.h:70
TRACE_API void SetCurrentValues(const CounterMap &)
Sets the current value of the counters.
const CounterMap & GetCurrentValues() const
Returns the current value of the counters.
std::unordered_map< TfToken, double, TfToken::HashFunctor > CounterMap
const CounterValuesMap & GetCounters() const
Returns a map of the counter values over time.
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
uint32_t TraceCategoryId
Categories that a TraceReporter can use to filter events.
Definition: category.h:27
#define TRACE_API
Definition: api.h:23