Ion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
calltracemanager.h
Go to the documentation of this file.
1 
18 #ifndef ION_PROFILE_CALLTRACEMANAGER_H_
19 #define ION_PROFILE_CALLTRACEMANAGER_H_
20 
21 #include <chrono> // NOLINT
22 #include <memory>
23 #include <vector>
24 
26 #include "ion/base/lockguards.h"
27 #include "ion/base/setting.h"
31 #include "ion/port/mutex.h"
32 #include "ion/port/timer.h"
33 #include "ion/profile/timeline.h"
35 
36 namespace ion {
37 namespace profile {
38 
39 class TraceRecorder;
40 
45  public:
47  enum EventArgType {
51  };
52 
57 
62 
65 
68 
70  kMarkEvent = 10,
71 
74 
78 
82 
86  };
87 
93  };
94 
100 
103 
106 
108 
110  explicit CallTraceManager(size_t buffer_size);
111 
112  ~CallTraceManager() override;
113 
116 
121 
123  const TraceList& GetAllTraceRecorders() const { return recorder_list_; }
124 
127  int GetScopeEnterEvent(const char* string_id);
128 
130  const char* GetScopeEnterEventName(uint32 event_id) const;
131 
133  static int GetNumArgsForEvent(uint32 event_id);
134 
136  static EventArgType GetArgType(uint32 event_id, int arg_index);
137 
139  size_t GetNumScopeEvents() const { return scope_event_map_.size(); }
140 
143  std::string SnapshotCallTraces() const;
144 
148  virtual uint32 GetTimeInUs() const {
149  return static_cast<uint32>(
150  std::chrono::duration_cast<std::chrono::microseconds>(timer_.Get())
151  .count());
152  }
153 
157  uint64 GetTimeInNs() const {
158  return static_cast<uint64>(
159  std::chrono::duration_cast<std::chrono::nanoseconds>(timer_.Get())
160  .count());
161  }
162 
165  void WriteFile(const std::string& filename) const;
166 
168  Timeline BuildTimeline() const;
169 
171  void RegisterTimelineMetric(std::unique_ptr<TimelineMetric> metric) {
172  timeline_metrics_.push_back(std::move(metric));
173  }
174 
178 
179  private:
181  struct NamedTraceRecorderArray {
182  NamedTraceRecorderArray() {
183  for (int i = 0; i < kNumNamedTraceRecorders; ++i) {
184  recorders[i] = NULL;
185  }
186  }
187 
189  TraceRecorder* recorders[kNumNamedTraceRecorders];
190  };
191 
193  TraceRecorder* AllocateTraceRecorder();
194 
196  port::Mutex mutex_;
197 
199  base::ThreadLocalObject<TraceRecorder*> trace_recorder_;
200 
202  base::ThreadLocalObject<NamedTraceRecorderArray> named_trace_recorders_;
203 
205  TraceList recorder_list_;
206 
209  size_t buffer_size_;
210 
212  port::Timer timer_;
213 
215  ScopeEventMap scope_event_map_;
216 
218  ReverseScopeEventMap reverse_scope_event_map_;
219 
222  std::vector<std::unique_ptr<TimelineMetric>> timeline_metrics_;
223 };
224 
228  public:
229  ScopedTracer(TraceRecorder* recorder, int id);
230  ~ScopedTracer();
231 
232  private:
233  TraceRecorder* recorder_;
234 };
235 
239  public:
240  ScopedFrameTracer(TraceRecorder* recorder, uint32 id);
242 
243  private:
244  TraceRecorder* recorder_;
245 };
246 
247 } // namespace profile
248 } // namespace ion
249 
250 #endif // ION_PROFILE_CALLTRACEMANAGER_H_
The event for defining new WTF events, both custom and built-in events.
base::AllocUnorderedMap< uint32, const char * > ReverseScopeEventMap
Reversed mapping from custom scope event id to name.
static int GetNumArgsForEvent(uint32 event_id)
Gets the number of arguments for a particular event.
Class to automatically record scope start and end events using the given TraceRecorder.
Class for recording frame events.
Definition: tracerecorder.h:42
static EventArgType GetArgType(uint32 event_id, int arg_index)
Gets the argument types for a particular event.
Copyright 2016 Google Inc.
Definition: timeline.h:47
Class to automatically record frame start and end events using the given TraceRecorder.
void WriteFile(const std::string &filename) const
Writes the current WTF trace to a file, which usually ends in the extension ".wtf-trace".
virtual uint32 GetTimeInUs() const
Returns the time in microseconds, relative to the timebase.
BuiltinEventType
Defines the built-in WTF events that we use.
Allocatable is an abstract base class for classes whose memory is managed by an Allocator.
Definition: allocatable.h:60
base::AllocUnorderedMap< const void *, uint32 > ScopeEventMap
Custom scope event mapping from name (as a pointer to a literal string) to uint32 id...
NamedTraceRecorderType
Defines name trace recorders.
std::string name
Definition: printer.cc:324
EventArgType
Defines argument types for WTF events.
Clock::duration Get() const
Returns the elapsed time since construction or the last Reset().
Definition: timer.cc:85
std::string SnapshotCallTraces() const
Returns a snapshot of traces to a string in binary .wtf-trace format.
TraceRecorder * GetNamedTraceRecorder(NamedTraceRecorderType name)
Gets the TraceRecorder instance specific to the current thread of the given name. ...
analytics::Benchmark RunTimelineMetrics() const
Runs all registered metrics on the current timeline and returns a benchmark object containing the col...
ScopedFrameTracer(TraceRecorder *recorder, uint32 id)
const TraceList & GetAllTraceRecorders() const
Gets the list of all trace recorders for all threads.
Manages call trace recording for visualization in Web Tracing Framework (WTF) format.
TraceRecorder * GetTraceRecorder()
Gets the TraceRecorder instance specific to the current thread.
size_t GetNumScopeEvents() const
Returns the number of unique custom scope events recorded.
The starting offset for scope event ids, purposefully set high to make room for built-in WTF events...
int GetScopeEnterEvent(const char *string_id)
Queries the event id of a scope enter event, based on string_id.
ScopedTracer(TraceRecorder *recorder, int id)
The Benchmark class provides types and utilities to make it easier to create performance benchmarks...
Definition: benchmark.h:34
Timeline BuildTimeline() const
Convert the current WTF trace into a timeline.
void RegisterTimelineMetric(std::unique_ptr< TimelineMetric > metric)
Registers a timeline metric.
base::AllocVector< TraceRecorder * > TraceList
List of TraceRecorders, one created for each thread of execution.
const char * GetScopeEnterEventName(uint32 event_id) const
Returns the name of the scope enter event with the given id.
uint64 GetTimeInNs() const
Returns the time in nanoseconds, relative to the timebase.