All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
eventList.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_EVENT_LIST_H
9#define PXR_BASE_TRACE_EVENT_LIST_H
10
11#include "pxr/pxr.h"
12
13#include "pxr/base/trace/dataBuffer.h"
14#include "pxr/base/trace/dynamicKey.h"
15#include "pxr/base/trace/event.h"
16#include "pxr/base/trace/eventContainer.h"
17
18#include <list>
19#include <unordered_set>
20
21PXR_NAMESPACE_OPEN_SCOPE
22
30public:
32 TRACE_API TraceEventList();
33
36
39
40 // No copies
41 TraceEventList(const TraceEventList&) = delete;
42 TraceEventList& operator=(const TraceEventList&) = delete;
43
47 const_iterator begin() const { return _events.begin();}
48 const_iterator end() const { return _events.end();}
49
50 using const_reverse_iterator = TraceEventContainer::const_reverse_iterator;
51 const_reverse_iterator rbegin() const { return _events.rbegin();}
52 const_reverse_iterator rend() const { return _events.rend();}
54
56 bool IsEmpty() const { return _events.empty();}
57
60 template < class... Args>
61 const TraceEvent& EmplaceBack(Args&&... args) {
62 return _events.emplace_back(std::forward<Args>(args)...);
63 }
64
70 KeyCache::const_iterator it = _caches.front().insert(key).first;
71 return TraceKey(it->GetData());
72 }
73
76 TRACE_API void Append(TraceEventList&& other);
77
80 template < typename T>
81 decltype(std::declval<TraceDataBuffer>().StoreData(std::declval<T>()))
82 StoreData(const T& value) {
83 return _dataCache.StoreData(value);
84 }
85
86private:
87
88 TraceEventContainer _events;
89
90 // For speed the TraceEvent class holds a pointer to a TraceStaticKeyData.
91 // For some events (ones not created by TRACE_FUNCTION and
92 // TRACE_SCOPE macros), we need to hold onto the TraceDynamicKey to
93 // keep the reference valid. Using std::list to avoid reallocation,
94 // keep reference valid by keeping things stable in memory.
95 using KeyCache =
96 std::unordered_set<TraceDynamicKey, TraceDynamicKey::HashFunctor>;
97 std::list<KeyCache> _caches;
98
99 TraceDataBuffer _dataCache;
100};
101
102PXR_NAMESPACE_CLOSE_SCOPE
103
104#endif //PXR_BASE_TRACE_EVENT_LIST_H
This class stores copies of data that are associated with TraceEvent instances.
Definition: dataBuffer.h:34
const T * StoreData(const T &value)
Makes a copy of value and returns a pointer to it.
Definition: dataBuffer.h:45
This class stores data used to create dynamic keys which can be referenced in TraceEvent instances.
Definition: dynamicKey.h:25
Bidirectional iterator of TraceEvents.
Holds TraceEvent instances.
This represents an event recorded by a TraceCollector.
Definition: event.h:30
This class represents an ordered collection of TraceEvents and the TraceDynamicKeys and data that the...
Definition: eventList.h:29
TraceKey CacheKey(const TraceDynamicKey &key)
For speed the TraceEvent class holds a pointer to a TraceStaticKeyData.
Definition: eventList.h:69
const TraceEvent & EmplaceBack(Args &&... args)
Construct a TraceEvent at the end on the list.
Definition: eventList.h:61
TRACE_API TraceEventList()
Constructor.
bool IsEmpty() const
Returns whether there are any events in the list.
Definition: eventList.h:56
TraceEventList(TraceEventList &&)=default
Move Constructor.
TraceEventList & operator=(TraceEventList &&)=default
Move Assignment.
TRACE_API void Append(TraceEventList &&other)
Appends the given list to the end of this list.
decltype(std::declval< TraceDataBuffer >().StoreData(std::declval< T >())) StoreData(const T &value)
Copy data to the buffer and return a pointer to the cached data that is valid for the lifetime of the...
Definition: eventList.h:82
A wrapper around a TraceStaticKeyData pointer that is stored in TraceEvent instances.
Definition: key.h:23