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 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 
32 #include "pxr/base/trace/event.h"
34 
35 #include <list>
36 #include <unordered_set>
37 
39 
40 ////////////////////////////////////////////////////////////////////////////////
41 /// \class TraceEventList
42 ///
43 /// This class represents an ordered collection of TraceEvents and the
44 /// TraceDynamicKeys and data that the events reference.
45 ///
47 public:
48  /// Constructor.
50 
51  /// Move Constructor.
52  TraceEventList(TraceEventList&&) = default;
53 
54  /// Move Assignment.
55  TraceEventList& operator=(TraceEventList&&) = default;
56 
57  // No copies
58  TraceEventList(const TraceEventList&) = delete;
59  TraceEventList& operator=(const TraceEventList&) = delete;
60 
61  /// \name Iterator support.
62  /// @{
64  const_iterator begin() const { return _events.begin();}
65  const_iterator end() const { return _events.end();}
66 
68  const_reverse_iterator rbegin() const { return _events.rbegin();}
69  const_reverse_iterator rend() const { return _events.rend();}
70  /// @}
71 
72  /// Returns whether there are any events in the list.
73  bool IsEmpty() const { return _events.empty();}
74 
75  /// Construct a TraceEvent at the end on the list.
76  /// Returns a reference to the newly constructed event.
77  template < class... Args>
78  const TraceEvent& EmplaceBack(Args&&... args) {
79  return _events.emplace_back(std::forward<Args>(args)...);
80  }
81 
82  /// For speed the TraceEvent class holds a pointer to a TraceStaticKeyData.
83  /// This method creates a key which can be referenced by events in this
84  /// container. Returns a TraceKey which will remain valid for the lifetime
85  /// of the container.
87  KeyCache::const_iterator it = _caches.front().insert(key).first;
88  return TraceKey(it->GetData());
89  }
90 
91  /// Appends the given list to the end of this list. This object will take
92  /// ownership of the events and keys in the appended list.
93  TRACE_API void Append(TraceEventList&& other);
94 
95  /// Copy data to the buffer and return a pointer to the cached data that is
96  /// valid for the lifetime of the Eventlist.
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 
120 
121 #endif //PXR_BASE_TRACE_EVENT_LIST_H
decltype(std::declval< TraceDataBuffer >().StoreData(std::declval< T >())) StoreData(const T &value)
Definition: eventList.h:99
const TraceEvent & EmplaceBack(Args &&...args)
Definition: eventList.h:78
const_reverse_iterator rend() const
Definition: eventList.h:69
TRACE_API TraceEventList()
Constructor.
bool empty() const
TraceEventContainer::const_reverse_iterator const_reverse_iterator
Definition: eventList.h:67
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:64
const_reverse_iterator rbegin() const
Definition: eventList.h:68
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1432
TraceKey CacheKey(const TraceDynamicKey &key)
Definition: eventList.h:86
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
**If you just want to fire and args
Definition: thread.h:609
const_iterator end() const
Definition: eventList.h:65
Definition: core.h:1131
const_iterator begin() const
bool IsEmpty() const
Returns whether there are any events in the list.
Definition: eventList.h:73
const_reverse_iterator rend() const
const T * StoreData(const T &value)
Definition: dataBuffer.h:62
#define TRACE_API
Definition: api.h:40
Definition: key.h:40