Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(49)

Unified Diff: components/tracing/core/trace_ring_buffer.h

Issue 2197563002: tracing v2: minor refactoring to TraceRingBuffer test helpers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: simpler check Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/tracing/core/trace_ring_buffer.h
diff --git a/components/tracing/core/trace_ring_buffer.h b/components/tracing/core/trace_ring_buffer.h
index 4a86a8bbc4fc1b8d9c024e313e99c85cf128f939..534d3aafc8f30087d7a8a2c814edc204b4be6c26 100644
--- a/components/tracing/core/trace_ring_buffer.h
+++ b/components/tracing/core/trace_ring_buffer.h
@@ -5,15 +5,18 @@
#ifndef COMPONENTS_TRACING_CORE_TRACE_RING_BUFFER_H_
#define COMPONENTS_TRACING_CORE_TRACE_RING_BUFFER_H_
+#include <memory>
+
#include "base/atomicops.h"
#include "base/macros.h"
#include "base/synchronization/lock.h"
-#include "base/threading/thread.h"
#include "components/tracing/tracing_export.h"
namespace tracing {
namespace v2 {
+static const uint32_t kNoChunkOwner = 0;
+
class TRACING_EXPORT TraceRingBuffer {
public:
class Chunk {
@@ -39,14 +42,26 @@ class TRACING_EXPORT TraceRingBuffer {
return base::subtle::NoBarrier_Load(header());
}
+ void set_next_in_owner_list(Chunk* next) { next_in_owner_list_ = next; }
+ Chunk* next_in_owner_list() const { return next_in_owner_list_; }
+
+ // Owner is a flag matching the id of the TraceBufferWriter, 0 if not owned.
// Accesses to |owner_| must happen under the buffer |lock_|.
- bool is_owned() const { return owner_ != base::kInvalidThreadId; }
- void clear_owner() { owner_ = base::kInvalidThreadId; }
- void set_owner(base::PlatformThreadId tid) { owner_ = tid; }
+ bool is_owned() const { return owner_ != kNoChunkOwner; }
+ uint32_t owner() const { return owner_; }
+ void clear_owner() { owner_ = kNoChunkOwner; }
+ void set_owner(uint32_t owner) {
+ DCHECK_NE(kNoChunkOwner, owner);
+ owner_ = owner;
+ }
private:
uint8_t* begin_;
- base::PlatformThreadId owner_; // kInvalidThreadId -> Chunk is not owned.
+ uint32_t owner_;
+
+ // When a chunk is owned, this is the next pointer to keep track of all
+ // owned chunks in a singly linked list.
+ Chunk* next_in_owner_list_;
DISALLOW_COPY_AND_ASSIGN(Chunk);
};
@@ -54,13 +69,23 @@ class TRACING_EXPORT TraceRingBuffer {
TraceRingBuffer(uint8_t* begin, size_t size);
~TraceRingBuffer();
- Chunk* TakeChunk();
- void ReturnChunk(Chunk* chunk, uint32_t used_size);
+ Chunk* TakeChunk(uint32_t writer_id);
+ void ReturnChunk(Chunk* chunk);
+
+ size_t num_chunks() const { return num_chunks_; }
+
+ // Returns the number of chunks taken and not returned, without counting any
+ // bankrupcy chunk obtained when the ring buffer was full.
+ size_t GetNumChunksTaken() const;
+
+ const Chunk* chunks_for_testing() const { return chunks_.get(); }
+ bool IsBankrupcyChunkForTesting(const Chunk*) const;
private:
- base::Lock lock_;
+ mutable base::Lock lock_;
std::unique_ptr<Chunk[]> chunks_;
const size_t num_chunks_;
+ size_t num_chunks_taken_;
size_t current_chunk_idx_;
// An emergency chunk used in the rare case in which all chunks are in flight.
« no previous file with comments | « components/tracing/core/scattered_stream_writer_unittest.cc ('k') | components/tracing/core/trace_ring_buffer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698