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 Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 
25 #ifndef PXR_BASE_TRACE_COUNTER_ACCUMULATOR_H
26 #define PXR_BASE_TRACE_COUNTER_ACCUMULATOR_H
27 
28 #include "pxr/pxr.h"
29 
30 #include "pxr/base/trace/api.h"
32 
33 #include "pxr/base/tf/token.h"
34 
35 #include <map>
36 #include <unordered_map>
37 #include <vector>
38 
40 
41 ////////////////////////////////////////////////////////////////////////////////
42 /// \class TraceCounterAccumulator
43 ///
44 /// This class accumulates counter values from TraceCollection instances.
45 /// A TraceCounterAccumulator instance can accumulate counters from multiple
46 /// collections or the state of the counters can be set explicitly through
47 /// SetCurrentValues().
48 ///
49 ///
51 public:
52  using CounterValues = std::vector<std::pair<TraceEvent::TimeStamp, double>>;
53  using CounterValuesMap =
54  std::unordered_map<TfToken, CounterValues, TfToken::HashFunctor>;
55  using CounterMap =
56  std::unordered_map<TfToken, double, TfToken::HashFunctor>;
57 
58  /// Constructor.
59  TraceCounterAccumulator() = default;
60 
61  /// Returns a map of the counter values over time.
62  const CounterValuesMap& GetCounters() const {
63  return _counterValuesOverTime;
64  }
65 
66  /// Sets the current value of the counters.
68 
69  /// Returns the current value of the counters.
70  const CounterMap& GetCurrentValues() const {
71  return _currentValues;
72  }
73 
74  /// Reads events /p collection and updates the current values of the
75  /// counters.
76  TRACE_API void Update(const TraceCollection& collection);
77 
78 protected:
79  /// Determines whether or not counter events with \p id should be processed.
80  virtual bool _AcceptsCategory(TraceCategoryId id) = 0;
81 
82 private:
83  // TraceCollection::Visitor Interface
84  virtual void OnBeginCollection() override;
85  virtual void OnEndCollection() override;
86  virtual void OnBeginThread(const TraceThreadId&) override;
87  virtual void OnEndThread(const TraceThreadId&) override;
88  virtual bool AcceptsCategory(TraceCategoryId) override;
89  virtual void OnEvent(
90  const TraceThreadId&, const TfToken&, const TraceEvent&) override;
91 
92  struct _CounterValue {
93  double value;
94  bool isDelta;
95  };
96 
97  using _CounterDeltaValues =
98  std::multimap<TraceEvent::TimeStamp, _CounterValue>;
99  using _CounterDeltaMap = std::map<TfToken, _CounterDeltaValues>;
100 
101  _CounterDeltaMap _counterDeltas;
102  CounterValuesMap _counterValuesOverTime;
103  CounterMap _currentValues;
104 };
105 
107 
108 #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:87
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:1432
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
uint32_t TraceCategoryId
Categories that a TraceReporter can use to filter events.
Definition: category.h:44
#define TRACE_API
Definition: api.h:40