All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
eventList.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_EVENT_LIST_H
26 #define PXR_BASE_TRACE_EVENT_LIST_H
27 
28 #include "pxr/pxr.h"
29 
30 #include "pxr/base/trace/dataBuffer.h"
31 #include "pxr/base/trace/dynamicKey.h"
32 #include "pxr/base/trace/event.h"
33 #include "pxr/base/trace/eventContainer.h"
34 
35 #include <list>
36 #include <unordered_set>
37 
38 PXR_NAMESPACE_OPEN_SCOPE
39 
47 public:
49  TRACE_API TraceEventList();
50 
52  TraceEventList(TraceEventList&&) = default;
53 
55  TraceEventList& operator=(TraceEventList&&) = default;
56 
57  // No copies
58  TraceEventList(const TraceEventList&) = delete;
59  TraceEventList& operator=(const TraceEventList&) = delete;
60 
64  const_iterator begin() const { return _events.begin();}
65  const_iterator end() const { return _events.end();}
66 
67  using const_reverse_iterator = TraceEventContainer::const_reverse_iterator;
68  const_reverse_iterator rbegin() const { return _events.rbegin();}
69  const_reverse_iterator rend() const { return _events.rend();}
71 
73  bool IsEmpty() const { return _events.empty();}
74 
77  template < class... Args>
78  const TraceEvent& EmplaceBack(Args&&... args) {
79  return _events.emplace_back(std::forward<Args>(args)...);
80  }
81 
87  KeyCache::const_iterator it = _caches.front().insert(key).first;
88  return TraceKey(it->GetData());
89  }
90 
93  TRACE_API void Append(TraceEventList&& other);
94 
97  template < typename T>
98  decltype(std::declval<TraceDataBuffer>().StoreData(std::declval<T>()))
99  StoreData(const T& value) {
100  return _dataCache.StoreData(value);
101  }
102 
103 private:
104 
105  TraceEventContainer _events;
106 
107  // For speed the TraceEvent class holds a pointer to a TraceStaticKeyData.
108  // For some events (ones not created by TRACE_FUNCTION and
109  // TRACE_SCOPE macros), we need to hold onto the TraceDynamicKey to
110  // keep the reference valid. Using std::list to avoid reallocation,
111  // keep reference valid by keeping things stable in memory.
112  using KeyCache =
113  std::unordered_set<TraceDynamicKey, TraceDynamicKey::HashFunctor>;
114  std::list<KeyCache> _caches;
115 
116  TraceDataBuffer _dataCache;
117 };
118 
119 PXR_NAMESPACE_CLOSE_SCOPE
120 
121 #endif //PXR_BASE_TRACE_EVENT_LIST_H
const TraceEvent & EmplaceBack(Args &&...args)
Construct a TraceEvent at the end on the list.
Definition: eventList.h:78
Bidirectional iterator of TraceEvents.
This class stores copies of data that are associated with TraceEvent instances.
Definition: dataBuffer.h:51
bool IsEmpty() const
Returns whether there are any events in the list.
Definition: eventList.h:73
This class stores data used to create dynamic keys which can be referenced in TraceEvent instances...
Definition: dynamicKey.h:42
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:99
TRACE_API TraceEventList()
Constructor.
This represents an event recorded by a TraceCollector.
Definition: event.h:47
TraceKey CacheKey(const TraceDynamicKey &key)
For speed the TraceEvent class holds a pointer to a TraceStaticKeyData.
Definition: eventList.h:86
TraceEventList & operator=(TraceEventList &&)=default
Move Assignment.
This class represents an ordered collection of TraceEvents and the TraceDynamicKeys and data that the...
Definition: eventList.h:46
const T * StoreData(const T &value)
Makes a copy of value and returns a pointer to it.
Definition: dataBuffer.h:62
Holds TraceEvent instances.
A wrapper around a TraceStaticKeyData pointer that is stored in TraceEvent instances.
Definition: key.h:40