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

Side by Side Diff: base/trace_event/thread_local_event_buffer.cc

Issue 2503473002: tracing: split out ThreadLocalEventBuffer
Patch Set: Created 4 years, 1 month 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
« no previous file with comments | « base/trace_event/thread_local_event_buffer.h ('k') | base/trace_event/trace_buffer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "base/trace_event/thread_local_event_buffer.h"
6
7 #include "base/trace_event/trace_buffer.h"
8 #include "base/trace_event/trace_event_impl.h"
9 #include "base/trace_event/trace_log.h"
10
11 namespace base {
12 namespace trace_event {
13
14 ThreadLocalEventBuffer::ThreadLocalEventBuffer(int generation)
15 : chunk_index_(0), generation_(generation) {}
16
17 ThreadLocalEventBuffer::~ThreadLocalEventBuffer() {
18 DCHECK(thread_checker_.CalledOnValidThread());
19 // The instance must have been flushed before destruction. Otherwise the
20 // owned chunk will be lost forever.
21 DCHECK(!chunk_);
22 }
23
24 TraceEvent* ThreadLocalEventBuffer::AddTraceEvent(TraceEventHandle* handle) {
25 DCHECK(thread_checker_.CalledOnValidThread());
26
27 if (chunk_ && chunk_->IsFull())
28 Flush(); // |chunk_| will be empty and evaluate to false after this call.
29
30 if (!chunk_) {
31 chunk_ = TraceLog::GetInstance()->TakeChunk(&chunk_index_);
32 if (!chunk_)
33 return NULL;
34 }
35
36 size_t event_index;
37 TraceEvent* trace_event = chunk_->AddTraceEvent(&event_index);
38 DCHECK(trace_event);
39 if (handle)
40 chunk_->MakeHandle(chunk_index_, event_index, handle);
41 return trace_event;
42 }
43
44 TraceEvent* ThreadLocalEventBuffer::GetEventByHandle(TraceEventHandle handle) {
45 if (!chunk_ || handle.chunk_seq != chunk_->seq() ||
46 handle.chunk_index != chunk_index_) {
47 return nullptr;
48 }
49 return chunk_->GetEventAt(handle.event_index);
50 }
51
52 void ThreadLocalEventBuffer::Flush() {
53 if (!chunk_)
54 return;
55 TraceLog::GetInstance()->ReturnChunk(std::move(chunk_), generation_,
56 chunk_index_);
57 }
58
59 } // namespace trace_event
60 } // namespace base
OLDNEW
« no previous file with comments | « base/trace_event/thread_local_event_buffer.h ('k') | base/trace_event/trace_buffer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698