| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef COMPONENTS_TRACING_CORE_TRACE_RING_BUFFER_H_ | 5 #ifndef COMPONENTS_TRACING_CORE_TRACE_RING_BUFFER_H_ |
| 6 #define COMPONENTS_TRACING_CORE_TRACE_RING_BUFFER_H_ | 6 #define COMPONENTS_TRACING_CORE_TRACE_RING_BUFFER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/atomicops.h" | 10 #include "base/atomicops.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/synchronization/lock.h" | 12 #include "base/synchronization/lock.h" |
| 13 #include "components/tracing/tracing_export.h" | 13 #include "components/tracing/tracing_export.h" |
| 14 | 14 |
| 15 namespace tracing { | 15 namespace tracing { |
| 16 namespace v2 { | 16 namespace v2 { |
| 17 | 17 |
| 18 static const uint32_t kNoChunkOwner = 0; | 18 static const uint32_t kNoChunkOwner = 0; |
| 19 static const size_t kChunkSize = 32 * 1024; |
| 19 | 20 |
| 20 class TRACING_EXPORT TraceRingBuffer { | 21 class TRACING_EXPORT TraceRingBuffer { |
| 21 public: | 22 public: |
| 22 class Chunk { | 23 class Chunk { |
| 23 public: | 24 public: |
| 24 using Header = base::subtle::Atomic32; | 25 using Header = base::subtle::Atomic32; |
| 25 static constexpr size_t kSize = 32 * 1024; | |
| 26 | 26 |
| 27 Chunk(); | 27 Chunk(); |
| 28 ~Chunk(); | 28 ~Chunk(); |
| 29 | 29 |
| 30 void Initialize(uint8_t* begin); | 30 void Initialize(uint8_t* begin); |
| 31 void Clear(); | 31 void Clear(); |
| 32 | 32 |
| 33 uint8_t* begin() const { return begin_; } | 33 uint8_t* begin() const { return begin_; } |
| 34 Header* header() const { return reinterpret_cast<Header*>(begin_); } | 34 Header* header() const { return reinterpret_cast<Header*>(begin_); } |
| 35 uint8_t* payload() const { return begin_ + sizeof(Header); } | 35 uint8_t* payload() const { return begin_ + sizeof(Header); } |
| 36 uint8_t* end() const { return begin_ + kSize; } | 36 uint8_t* end() const { return begin_ + kChunkSize; } |
| 37 | 37 |
| 38 void set_used_size(uint32_t size) { | 38 void set_used_size(uint32_t size) { |
| 39 base::subtle::NoBarrier_Store(header(), size); | 39 base::subtle::NoBarrier_Store(header(), size); |
| 40 } | 40 } |
| 41 uint32_t used_size() const { | 41 uint32_t used_size() const { |
| 42 return base::subtle::NoBarrier_Load(header()); | 42 return base::subtle::NoBarrier_Load(header()); |
| 43 } | 43 } |
| 44 | 44 |
| 45 void set_next_in_owner_list(Chunk* next) { next_in_owner_list_ = next; } | 45 void set_next_in_owner_list(Chunk* next) { next_in_owner_list_ = next; } |
| 46 Chunk* next_in_owner_list() const { return next_in_owner_list_; } | 46 Chunk* next_in_owner_list() const { return next_in_owner_list_; } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 Chunk bankrupcy_chunk_; | 95 Chunk bankrupcy_chunk_; |
| 96 std::unique_ptr<uint8_t[]> bankrupcy_chunk_storage_; | 96 std::unique_ptr<uint8_t[]> bankrupcy_chunk_storage_; |
| 97 | 97 |
| 98 DISALLOW_COPY_AND_ASSIGN(TraceRingBuffer); | 98 DISALLOW_COPY_AND_ASSIGN(TraceRingBuffer); |
| 99 }; | 99 }; |
| 100 | 100 |
| 101 } // namespace v2 | 101 } // namespace v2 |
| 102 } // namespace tracing | 102 } // namespace tracing |
| 103 | 103 |
| 104 #endif // COMPONENTS_TRACING_CORE_TRACE_RING_BUFFER_H_ | 104 #endif // COMPONENTS_TRACING_CORE_TRACE_RING_BUFFER_H_ |
| OLD | NEW |