OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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/files/file_tracing.h" |
| 6 |
| 7 #include "base/files/file.h" |
| 8 |
| 9 namespace base { |
| 10 |
| 11 // static |
| 12 FileTracing::Provider* FileTracing::g_provider = nullptr; |
| 13 |
| 14 FileTracing::ScopedEnabler::ScopedEnabler() { |
| 15 if (g_provider) |
| 16 g_provider->FileTracingEnable(this); |
| 17 } |
| 18 |
| 19 FileTracing::ScopedEnabler::~ScopedEnabler() { |
| 20 if (g_provider) |
| 21 g_provider->FileTracingDisable(this); |
| 22 } |
| 23 |
| 24 FileTracing::ScopedTrace::ScopedTrace() : initialized_(false) {} |
| 25 |
| 26 FileTracing::ScopedTrace::~ScopedTrace() { |
| 27 if (initialized_ && g_provider) { |
| 28 g_provider->FileTracingEventEnd( |
| 29 name_, &file_->trace_enabler_, file_->path_, size_); |
| 30 } |
| 31 } |
| 32 |
| 33 bool FileTracing::ScopedTrace::ShouldInitialize() const { |
| 34 return g_provider && g_provider->FileTracingCategoryIsEnabled(); |
| 35 } |
| 36 |
| 37 void FileTracing::ScopedTrace::Initialize( |
| 38 const char* name, File* file, int64 size) { |
| 39 file_ = file; |
| 40 name_ = name; |
| 41 size_ = size; |
| 42 initialized_ = true; |
| 43 |
| 44 if (g_provider) { |
| 45 g_provider->FileTracingEventBegin( |
| 46 name_, &file_->trace_enabler_, file_->path_, size_); |
| 47 } |
| 48 } |
| 49 |
| 50 } // namespace base |
OLD | NEW |