| Index: base/trace_event/thread_local_event_buffer.cc
|
| diff --git a/base/trace_event/thread_local_event_buffer.cc b/base/trace_event/thread_local_event_buffer.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..502b27c1ab65c21891e1bfe662b2d41c5122e69c
|
| --- /dev/null
|
| +++ b/base/trace_event/thread_local_event_buffer.cc
|
| @@ -0,0 +1,60 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "base/trace_event/thread_local_event_buffer.h"
|
| +
|
| +#include "base/trace_event/trace_buffer.h"
|
| +#include "base/trace_event/trace_event_impl.h"
|
| +#include "base/trace_event/trace_log.h"
|
| +
|
| +namespace base {
|
| +namespace trace_event {
|
| +
|
| +ThreadLocalEventBuffer::ThreadLocalEventBuffer(int generation)
|
| + : chunk_index_(0), generation_(generation) {}
|
| +
|
| +ThreadLocalEventBuffer::~ThreadLocalEventBuffer() {
|
| + DCHECK(thread_checker_.CalledOnValidThread());
|
| + // The instance must have been flushed before destruction. Otherwise the
|
| + // owned chunk will be lost forever.
|
| + DCHECK(!chunk_);
|
| +}
|
| +
|
| +TraceEvent* ThreadLocalEventBuffer::AddTraceEvent(TraceEventHandle* handle) {
|
| + DCHECK(thread_checker_.CalledOnValidThread());
|
| +
|
| + if (chunk_ && chunk_->IsFull())
|
| + Flush(); // |chunk_| will be empty and evaluate to false after this call.
|
| +
|
| + if (!chunk_) {
|
| + chunk_ = TraceLog::GetInstance()->TakeChunk(&chunk_index_);
|
| + if (!chunk_)
|
| + return NULL;
|
| + }
|
| +
|
| + size_t event_index;
|
| + TraceEvent* trace_event = chunk_->AddTraceEvent(&event_index);
|
| + DCHECK(trace_event);
|
| + if (handle)
|
| + chunk_->MakeHandle(chunk_index_, event_index, handle);
|
| + return trace_event;
|
| +}
|
| +
|
| +TraceEvent* ThreadLocalEventBuffer::GetEventByHandle(TraceEventHandle handle) {
|
| + if (!chunk_ || handle.chunk_seq != chunk_->seq() ||
|
| + handle.chunk_index != chunk_index_) {
|
| + return nullptr;
|
| + }
|
| + return chunk_->GetEventAt(handle.event_index);
|
| +}
|
| +
|
| +void ThreadLocalEventBuffer::Flush() {
|
| + if (!chunk_)
|
| + return;
|
| + TraceLog::GetInstance()->ReturnChunk(std::move(chunk_), generation_,
|
| + chunk_index_);
|
| +}
|
| +
|
| +} // namespace trace_event
|
| +} // namespace base
|
|
|