Loading...
Searching...
No Matches
counterAccumulator.h
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"
31#include "pxr/base/trace/collection.h"
32
33#include "pxr/base/tf/token.h"
34
35#include <map>
36#include <unordered_map>
37#include <vector>
38
39PXR_NAMESPACE_OPEN_SCOPE
40
51public:
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
60
62 const CounterValuesMap& GetCounters() const {
63 return _counterValuesOverTime;
64 }
65
67 TRACE_API void SetCurrentValues(const CounterMap&);
68
70 const CounterMap& GetCurrentValues() const {
71 return _currentValues;
72 }
73
76 TRACE_API void Update(const TraceCollection& collection);
77
78protected:
80 virtual bool _AcceptsCategory(TraceCategoryId id) = 0;
81
82private:
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
106PXR_NAMESPACE_CLOSE_SCOPE
107
108#endif //PXR_BASE_TRACE_COUNTER_ACCUMULATOR_H
uint32_t TraceCategoryId
Categories that a TraceReporter can use to filter events.
Definition: category.h:44
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:88
This interface provides a way to access data a TraceCollection.
Definition: collection.h:83
This class owns lists of TraceEvent instances per thread, and allows read access to them.
Definition: collection.h:49
This class accumulates counter values from TraceCollection instances.
TraceCounterAccumulator()=default
Constructor.
const CounterMap & GetCurrentValues() const
Returns the current value of the counters.
virtual bool _AcceptsCategory(TraceCategoryId id)=0
Determines whether or not counter events with id should be processed.
const CounterValuesMap & GetCounters() const
Returns a map of the counter values over time.
TRACE_API void SetCurrentValues(const CounterMap &)
Sets the current value of the counters.
TRACE_API void Update(const TraceCollection &collection)
Reads events /p collection and updates the current values of the counters.
This represents an event recorded by a TraceCollector.
Definition: event.h:47
This class represents an identifier for a thread.
Definition: threads.h:40
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...