V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
trace-buffer.h
1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef V8_LIBPLATFORM_TRACING_TRACE_BUFFER_H_
6 #define V8_LIBPLATFORM_TRACING_TRACE_BUFFER_H_
7 
8 #include <memory>
9 #include <vector>
10 
11 #include "include/libplatform/v8-tracing.h"
12 #include "src/base/platform/mutex.h"
13 
14 namespace v8 {
15 namespace platform {
16 namespace tracing {
17 
19  public:
20  TraceBufferRingBuffer(size_t max_chunks, TraceWriter* trace_writer);
21  ~TraceBufferRingBuffer() override = default;
22 
23  TraceObject* AddTraceEvent(uint64_t* handle) override;
24  TraceObject* GetEventByHandle(uint64_t handle) override;
25  bool Flush() override;
26 
27  private:
28  uint64_t MakeHandle(size_t chunk_index, uint32_t chunk_seq,
29  size_t event_index) const;
30  void ExtractHandle(uint64_t handle, size_t* chunk_index, uint32_t* chunk_seq,
31  size_t* event_index) const;
32  size_t Capacity() const { return max_chunks_ * TraceBufferChunk::kChunkSize; }
33  size_t NextChunkIndex(size_t index) const;
34 
35  mutable base::Mutex mutex_;
36  size_t max_chunks_;
37  std::unique_ptr<TraceWriter> trace_writer_;
38  std::vector<std::unique_ptr<TraceBufferChunk>> chunks_;
39  size_t chunk_index_;
40  bool is_empty_ = true;
41  uint32_t current_chunk_seq_ = 1;
42 };
43 
44 } // namespace tracing
45 } // namespace platform
46 } // namespace v8
47 
48 #endif // V8_LIBPLATFORM_TRACING_TRACE_BUFFER_H_
Definition: libplatform.h:13