All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
reporter.h
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_REPORTER_H
9#define PXR_BASE_TRACE_REPORTER_H
10
11#include "pxr/pxr.h"
12
13#include "pxr/base/trace/api.h"
14#include "pxr/base/trace/event.h"
15#include "pxr/base/trace/aggregateNode.h"
16#include "pxr/base/trace/reporterBase.h"
17
21
22#include <iosfwd>
23#include <string>
24
25PXR_NAMESPACE_OPEN_SCOPE
26
27#define TRACE_REPORTER_TOKENS \
28 ((warningString, "WARNING:"))
29
30TF_DECLARE_PUBLIC_TOKENS(TraceReporterTokens, TRACE_API, TRACE_REPORTER_TOKENS);
31
32
36
38
40
48 public TraceReporterBase {
49public:
50
51 TF_MALLOC_TAG_NEW("Trace", "TraceReporter");
52
53 using This = TraceReporter;
54 using ThisPtr = TraceReporterPtr;
55 using ThisRefPtr = TraceReporterRefPtr;
56
57 using Event = TraceEvent;
58 using TimeStamp = TraceEvent::TimeStamp;
59 using CounterMap = TfHashMap<TfToken, double, TfToken::HashFunctor>;
60
62 static ThisRefPtr New(const std::string& label,
63 DataSourcePtr dataSource) {
64 return TfCreateRefPtr(new This(label, std::move(dataSource)));
65 }
66
68 static ThisRefPtr New(const std::string& label) {
69 return TfCreateRefPtr(new This(label, nullptr));
70 }
71
73 TRACE_API static TraceReporterPtr GetGlobalReporter();
74
76 TRACE_API virtual ~TraceReporter();
77
79 const std::string& GetLabel() {
80 return _label;
81 }
82
85
88 TRACE_API void Report(
89 std::ostream &s,
90 int iterationCount=1);
91
93 TRACE_API void ReportTimes(std::ostream &s);
94
97 TRACE_API void ReportChromeTracing(std::ostream &s);
98
100
103
105 struct ParsedTree {
106 TraceAggregateTreeRefPtr tree;
107 int iterationCount;
108 };
109
118 TRACE_API static std::vector<ParsedTree> LoadReport(
119 std::istream &stream);
120
122
124 TRACE_API TraceAggregateNodePtr GetAggregateTreeRoot();
125
127 TRACE_API TraceEventNodeRefPtr GetEventRoot();
128
130 TRACE_API TraceEventTreeRefPtr GetEventTree();
131
134
138 TRACE_API const CounterMap & GetCounters() const;
139
142 TRACE_API int GetCounterIndex(const TfToken &key) const;
143
148 TRACE_API bool AddCounter(const TfToken &key, int index, double totalValue);
149
151
159 TRACE_API void UpdateTraceTrees();
160
162 TRACE_API void ClearTree();
163
166
170 TRACE_API void SetGroupByFunction(bool);
171
173 TRACE_API bool GetGroupByFunction() const;
174
178 TRACE_API void SetFoldRecursiveCalls(bool);
179
182 TRACE_API bool GetFoldRecursiveCalls() const;
183
186 TRACE_API void SetShouldAdjustForOverheadAndNoise(bool adjust);
187
190 TRACE_API bool ShouldAdjustForOverheadAndNoise() const;
191
193
198 TRACE_API static TraceAggregateNode::Id CreateValidEventId();
199
200protected:
201
202 TRACE_API TraceReporter(const std::string& label,
203 DataSourcePtr dataSource);
204
205private:
206 void _ProcessCollection(const TraceReporterBase::CollectionPtr&) override;
207 void _RebuildEventAndAggregateTrees();
208 void _PrintTimes(std::ostream &s);
209
210private:
211 std::string _label;
212
213 bool _groupByFunction;
214 bool _foldRecursiveCalls;
215 bool _shouldAdjustForOverheadAndNoise;
216
217 TraceAggregateTreeRefPtr _aggregateTree;
218 TraceEventTreeRefPtr _eventTree;
219};
220
221PXR_NAMESPACE_CLOSE_SCOPE
222
223#endif // PXR_BASE_TRACE_REPORTER_H
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
A representation of a call tree.
Definition: aggregateTree.h:31
A TfNotice that is sent when the TraceCollector creates a TraceCollection.
This represents an event recorded by a TraceCollector.
Definition: event.h:30
uint64_t TimeStamp
Time in "ticks".
Definition: event.h:33
TraceEventNode is used to represents call tree of a trace.
Definition: eventNode.h:36
This class contains a timeline call tree and a map of counters to their values over time.
Definition: eventTree.h:41
This class is a base class for report implementations.
Definition: reporterBase.h:36
This class converts streams of TraceEvent objects into call trees which can then be used as a data so...
Definition: reporter.h:48
static ThisRefPtr New(const std::string &label)
Create a new reporter with label and no data source.
Definition: reporter.h:68
static ThisRefPtr New(const std::string &label, DataSourcePtr dataSource)
Create a new reporter with label and dataSource.
Definition: reporter.h:62
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:79
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 std::vector< ParsedTree > LoadReport(std::istream &stream)
Load an aggregate tree report from the stream, as written by Report().
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.
Aggregate tree and its iteration count, parsed from a report.
Definition: reporter.h:105
Standard pointer typedefs.
#define TF_DECLARE_WEAK_AND_REF_PTRS(type)
Define standard weak, ref, and vector pointer types.
Definition: declarePtrs.h:72
#define TF_MALLOC_TAG_NEW(name1, name2)
Enable lib/tf memory management.
Definition: mallocTag.h:475
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:81