HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
eventList.h
Go to the documentation of this file.
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 
15 #include "pxr/base/trace/event.h"
17 
18 #include <list>
19 #include <unordered_set>
20 
22 
23 ////////////////////////////////////////////////////////////////////////////////
24 /// \class TraceEventList
25 ///
26 /// This class represents an ordered collection of TraceEvents and the
27 /// TraceDynamicKeys and data that the events reference.
28 ///
30 public:
31  /// Constructor.
33 
34  /// Move Constructor.
35  TraceEventList(TraceEventList&&) = default;
36 
37  /// Move Assignment.
38  TraceEventList& operator=(TraceEventList&&) = default;
39 
40  // No copies
41  TraceEventList(const TraceEventList&) = delete;
42  TraceEventList& operator=(const TraceEventList&) = delete;
43 
44  /// \name Iterator support.
45  /// @{
47  const_iterator begin() const { return _events.begin();}
48  const_iterator end() const { return _events.end();}
49 
51  const_reverse_iterator rbegin() const { return _events.rbegin();}
52  const_reverse_iterator rend() const { return _events.rend();}
53  /// @}
54 
55  /// Returns whether there are any events in the list.
56  bool IsEmpty() const { return _events.empty();}
57 
58  /// Construct a TraceEvent at the end on the list.
59  /// Returns a reference to the newly constructed event.
60  template < class... Args>
61  const TraceEvent& EmplaceBack(Args&&... args) {
62  return _events.emplace_back(std::forward<Args>(args)...);
63  }
64 
65  /// For speed the TraceEvent class holds a pointer to a TraceStaticKeyData.
66  /// This method creates a key which can be referenced by events in this
67  /// container. Returns a TraceKey which will remain valid for the lifetime
68  /// of the container.
70  KeyCache::const_iterator it = _caches.front().insert(key).first;
71  return TraceKey(it->GetData());
72  }
73 
74  /// Appends the given list to the end of this list. This object will take
75  /// ownership of the events and keys in the appended list.
76  TRACE_API void Append(TraceEventList&& other);
77 
78  /// Copy data to the buffer and return a pointer to the cached data that is
79  /// valid for the lifetime of the Eventlist.
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 
86 private:
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 
103 
104 #endif //PXR_BASE_TRACE_EVENT_LIST_H
decltype(std::declval< TraceDataBuffer >().StoreData(std::declval< T >())) StoreData(const T &value)
Definition: eventList.h:82
const TraceEvent & EmplaceBack(Args &&...args)
Definition: eventList.h:61
const_reverse_iterator rend() const
Definition: eventList.h:52
TRACE_API TraceEventList()
Constructor.
bool empty() const
GLsizei const GLfloat * value
Definition: glcorearb.h:824
TraceEventContainer::const_reverse_iterator const_reverse_iterator
Definition: eventList.h:50
const_iterator end() const
const_reverse_iterator rbegin() const
TRACE_API void Append(TraceEventList &&other)
std::reverse_iterator< const_iterator > const_reverse_iterator
TraceEvent & emplace_back(Args &&...args)
TraceEventList & operator=(TraceEventList &&)=default
Move Assignment.
const_iterator begin() const
Definition: eventList.h:47
const_reverse_iterator rbegin() const
Definition: eventList.h:51
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
TraceKey CacheKey(const TraceDynamicKey &key)
Definition: eventList.h:69
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
**If you just want to fire and args
Definition: thread.h:618
const_iterator end() const
Definition: eventList.h:48
const_iterator begin() const
bool IsEmpty() const
Returns whether there are any events in the list.
Definition: eventList.h:56
const_reverse_iterator rend() const
const T * StoreData(const T &value)
Definition: dataBuffer.h:45
#define TRACE_API
Definition: api.h:23
Definition: key.h:23