Loading...
Searching...
No Matches
reporter.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_REPORTER_H
26#define PXR_BASE_TRACE_REPORTER_H
27
28#include "pxr/pxr.h"
29
30#include "pxr/base/trace/api.h"
31#include "pxr/base/trace/event.h"
32#include "pxr/base/trace/aggregateNode.h"
33#include "pxr/base/trace/reporterBase.h"
34
38
39#include <iosfwd>
40#include <string>
41
42PXR_NAMESPACE_OPEN_SCOPE
43
44#define TRACE_REPORTER_TOKENS \
45 ((warningString, "WARNING:"))
46
47TF_DECLARE_PUBLIC_TOKENS(TraceReporterTokens, TRACE_API, TRACE_REPORTER_TOKENS);
48
49
53
55
57
65 public TraceReporterBase {
66public:
67
68 TF_MALLOC_TAG_NEW("Trace", "TraceReporter");
69
70 using This = TraceReporter;
71 using ThisPtr = TraceReporterPtr;
72 using ThisRefPtr = TraceReporterRefPtr;
73
74 using Event = TraceEvent;
75 using TimeStamp = TraceEvent::TimeStamp;
76 using CounterMap = TfHashMap<TfToken, double, TfToken::HashFunctor>;
77
79 static ThisRefPtr New(const std::string& label,
80 DataSourcePtr dataSource) {
81 return TfCreateRefPtr(new This(label, std::move(dataSource)));
82 }
83
85 static ThisRefPtr New(const std::string& label) {
86 return TfCreateRefPtr(new This(label, nullptr));
87 }
88
90 TRACE_API static TraceReporterPtr GetGlobalReporter();
91
93 TRACE_API virtual ~TraceReporter();
94
96 const std::string& GetLabel() {
97 return _label;
98 }
99
102
105 TRACE_API void Report(
106 std::ostream &s,
107 int iterationCount=1);
108
110 TRACE_API void ReportTimes(std::ostream &s);
111
114 TRACE_API void ReportChromeTracing(std::ostream &s);
115
117
119 TRACE_API TraceAggregateNodePtr GetAggregateTreeRoot();
120
122 TRACE_API TraceEventNodeRefPtr GetEventRoot();
123
125 TRACE_API TraceEventTreeRefPtr GetEventTree();
126
129
133 TRACE_API const CounterMap & GetCounters() const;
134
137 TRACE_API int GetCounterIndex(const TfToken &key) const;
138
143 TRACE_API bool AddCounter(const TfToken &key, int index, double totalValue);
144
146
154 TRACE_API void UpdateTraceTrees();
155
157 TRACE_API void ClearTree();
158
161
165 TRACE_API void SetGroupByFunction(bool);
166
168 TRACE_API bool GetGroupByFunction() const;
169
173 TRACE_API void SetFoldRecursiveCalls(bool);
174
177 TRACE_API bool GetFoldRecursiveCalls() const;
178
181 TRACE_API void SetShouldAdjustForOverheadAndNoise(bool adjust);
182
185 TRACE_API bool ShouldAdjustForOverheadAndNoise() const;
186
188
193 TRACE_API static TraceAggregateNode::Id CreateValidEventId();
194
195protected:
196
197 TRACE_API TraceReporter(const std::string& label,
198 DataSourcePtr dataSource);
199
200private:
201 void _ProcessCollection(const TraceReporterBase::CollectionPtr&) override;
202 void _RebuildEventAndAggregateTrees();
203 void _PrintTimes(std::ostream &s);
204
205private:
206 std::string _label;
207
208 bool _groupByFunction;
209 bool _foldRecursiveCalls;
210 bool _shouldAdjustForOverheadAndNoise;
211
212 TraceAggregateTreeRefPtr _aggregateTree;
213 TraceEventTreeRefPtr _eventTree;
214};
215
216PXR_NAMESPACE_CLOSE_SCOPE
217
218#endif // PXR_BASE_TRACE_REPORTER_H
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:88
A representation of a call tree.
Definition: aggregateTree.h:48
A TfNotice that is sent when the TraceCollector creates a TraceCollection.
This represents an event recorded by a TraceCollector.
Definition: event.h:47
uint64_t TimeStamp
Time in "ticks".
Definition: event.h:50
TraceEventNode is used to represents call tree of a trace.
Definition: eventNode.h:53
This class contains a timeline call tree and a map of counters to their values over time.
Definition: eventTree.h:58
This class is a base class for report implementations.
Definition: reporterBase.h:53
This class converts streams of TraceEvent objects into call trees which can then be used as a data so...
Definition: reporter.h:65
static ThisRefPtr New(const std::string &label)
Create a new reporter with label and no data source.
Definition: reporter.h:85
static ThisRefPtr New(const std::string &label, DataSourcePtr dataSource)
Create a new reporter with label and dataSource.
Definition: reporter.h:79
TRACE_API void Report(std::ostream &s, int iterationCount=1)
Generates a report to the ostream s, dividing all times by iterationCount.
static TRACE_API TraceAggregateNode::Id CreateValidEventId()
Creates a valid TraceAggregateNode::Id object.
TRACE_API const CounterMap & GetCounters() const
Returns a map of counters (counter keys), associated with their total accumulated value.
TRACE_API void UpdateTraceTrees()
This fully re-builds the event and aggregate trees from whatever the current collection holds.
TRACE_API bool GetGroupByFunction() const
Returns the current group-by-function state.
TRACE_API void SetShouldAdjustForOverheadAndNoise(bool adjust)
Set whether or not the reporter should adjust scope times for overhead and noise.
TRACE_API void ReportTimes(std::ostream &s)
Generates a report of the times to the ostream s.
const std::string & GetLabel()
Return the label associated with this reporter.
Definition: reporter.h:96
TRACE_API TraceEventNodeRefPtr GetEventRoot()
Returns the root node of the call tree.
TRACE_API void ReportChromeTracing(std::ostream &s)
Generates a timeline trace report suitable for viewing in Chrome's trace viewer.
TRACE_API bool ShouldAdjustForOverheadAndNoise() const
Returns the current setting for addjusting scope times for overhead and noise.
TRACE_API bool AddCounter(const TfToken &key, int index, double totalValue)
Add a counter to the reporter.
virtual TRACE_API ~TraceReporter()
Destructor.
static TRACE_API TraceReporterPtr GetGlobalReporter()
Returns the global reporter.
TRACE_API bool GetFoldRecursiveCalls() const
Returns the current setting for recursion folding for stack trace event reporting.
TRACE_API TraceAggregateNodePtr GetAggregateTreeRoot()
Returns the root node of the aggregated call tree.
TRACE_API int GetCounterIndex(const TfToken &key) const
Returns the numeric index associated with a counter key.
TRACE_API void SetFoldRecursiveCalls(bool)
When stack trace event reporting, this sets whether or not recursive calls are folded in the output.
TRACE_API void ClearTree()
Clears event tree and counters.
TRACE_API void SetGroupByFunction(bool)
This affects only stack trace event reporting.
TRACE_API TraceEventTreeRefPtr GetEventTree()
Returns the event call tree.
Standard pointer typedefs.
#define TF_DECLARE_WEAK_AND_REF_PTRS(type)
Define standard weak, ref, and vector pointer types.
Definition: declarePtrs.h:89
#define TF_MALLOC_TAG_NEW(name1, name2)
Enable lib/tf memory management.
Definition: mallocTag.h:489
This file defines some macros that are useful for declaring and using static TfTokens.
#define TF_DECLARE_PUBLIC_TOKENS(...)
Macro to define public tokens.
Definition: staticTokens.h:108