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