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

Side by Side Diff: components/tracing/core/trace_ring_buffer.h

Issue 2049653002: tracing v2: Add TraceRingBuffer class. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase + oysteine review Created 4 years, 5 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 unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef COMPONENTS_TRACING_CORE_TRACE_RING_BUFFER_H_
6 #define COMPONENTS_TRACING_CORE_TRACE_RING_BUFFER_H_
7
8 #include "base/atomicops.h"
9 #include "base/macros.h"
10 #include "base/synchronization/lock.h"
11 #include "base/threading/thread.h"
12 #include "components/tracing/tracing_export.h"
13
14 namespace tracing {
15 namespace v2 {
16
17 class TRACING_EXPORT TraceRingBuffer {
18 public:
19 class Chunk {
20 public:
21 using Header = base::subtle::Atomic32;
22 static const size_t kSize = 32768;
petrcermak 2016/06/28 10:22:30 Would it make sense to define this with a bit shif
Primiano Tucci (use gerrit) 2016/06/28 14:52:11 Doesn't necessarily have to be a power of two IIRC
23
24 Chunk();
25 ~Chunk();
26
27 void Initialize(uint8_t* begin);
28 void Clear();
29
30 uint8_t* begin() const { return begin_; }
31 Header* header() const { return reinterpret_cast<Header*>(begin_); }
32 uint8_t* payload() const { return begin_ + sizeof(Header); }
33 uint8_t* end() const { return begin_ + kSize; }
34
35 void set_used_size(uint32_t size) {
36 base::subtle::NoBarrier_Store(header(), size);
37 }
38 uint32_t used_size() const {
39 return base::subtle::NoBarrier_Load(header());
40 }
41
42 bool is_owned() const { return owner_ != base::kInvalidThreadId; }
43 void clear_owner() { owner_ = base::kInvalidThreadId; }
petrcermak 2016/06/28 10:22:29 perhaps call |set_owner(base::kInvalidThreadId)| ?
Primiano Tucci (use gerrit) 2016/06/28 14:52:11 not a huge difference really, and technically lowe
44 void set_owner(base::PlatformThreadId tid) { owner_ = tid; }
45
46 private:
47 uint8_t* begin_;
48
49 // Accesses to owner_ must happen under the buffer |lock_|.
petrcermak 2016/06/28 10:22:29 nit: "|owner_|"
Primiano Tucci (use gerrit) 2016/06/28 14:52:11 Done.
50 base::PlatformThreadId owner_; // kInvalidThreadId -> Chunk is returned.
petrcermak 2016/06/28 10:22:29 You mean has been returned? Is to be reused? Is *b
Primiano Tucci (use gerrit) 2016/06/28 14:52:11 reworded as "not owned". It is the terminology we
51
52 DISALLOW_COPY_AND_ASSIGN(Chunk);
53 };
54
55 TraceRingBuffer(uint8_t* begin, size_t size);
56 ~TraceRingBuffer();
57
58 Chunk* TakeChunk();
59 void ReturnChunk(Chunk* chunk, uint32_t used_size);
60
61 private:
62 base::Lock lock_;
63 std::unique_ptr<Chunk[]> chunks_;
64 const size_t num_chunks_;
65 size_t current_chunk_idx_;
66
67 // An emergency chunk used in the rare case in which all chunks are in flight.
68 // This chunk is not part of the ring buffer and its contents are always
69 // discarded. Its only purpose is to avoid a crash (due to TakeChunk returning
70 // nullptr) in the case of a thread storm.
71 Chunk bankrupcy_chunk_;
72 std::unique_ptr<uint8_t[]> bankrupcy_chunk_storage_;
petrcermak 2016/06/28 10:22:29 would it make sense to rename this to |emergency_c
petrcermak 2016/06/28 10:22:30 Just to clarify, it can be the case that multiple
Primiano Tucci (use gerrit) 2016/06/28 14:52:11 Correct. If this is used this will contain complet
Primiano Tucci (use gerrit) 2016/06/28 14:52:11 Hmm bankrupcy gives me more the idea that you give
73
74 DISALLOW_COPY_AND_ASSIGN(TraceRingBuffer);
75 };
76
77 } // namespace v2
78 } // namespace tracing
79
80 #endif // COMPONENTS_TRACING_CORE_TRACE_RING_BUFFER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698