• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
18 class TraceBufferRingBuffer : public TraceBuffer {
19  public:
20   // Takes ownership of |trace_writer|.
21   TraceBufferRingBuffer(size_t max_chunks, TraceWriter* trace_writer);
22   ~TraceBufferRingBuffer() override = default;
23 
24   TraceObject* AddTraceEvent(uint64_t* handle) override;
25   TraceObject* GetEventByHandle(uint64_t handle) override;
26   bool Flush() override;
27 
28  private:
29   uint64_t MakeHandle(size_t chunk_index, uint32_t chunk_seq,
30                       size_t event_index) const;
31   void ExtractHandle(uint64_t handle, size_t* chunk_index, uint32_t* chunk_seq,
32                      size_t* event_index) const;
Capacity()33   size_t Capacity() const { return max_chunks_ * TraceBufferChunk::kChunkSize; }
34   size_t NextChunkIndex(size_t index) const;
35 
36   mutable base::Mutex mutex_;
37   size_t max_chunks_;
38   std::unique_ptr<TraceWriter> trace_writer_;
39   std::vector<std::unique_ptr<TraceBufferChunk>> chunks_;
40   size_t chunk_index_;
41   bool is_empty_ = true;
42   uint32_t current_chunk_seq_ = 1;
43 };
44 
45 }  // namespace tracing
46 }  // namespace platform
47 }  // namespace v8
48 
49 #endif  // V8_LIBPLATFORM_TRACING_TRACE_BUFFER_H_
50