OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/files/file_tracing.h" | 5 #include "base/files/file_tracing.h" |
6 | 6 |
7 #include "base/files/file.h" | 7 #include "base/files/file.h" |
8 | 8 |
9 namespace base { | 9 namespace base { |
10 | 10 |
11 namespace { | 11 namespace { |
12 FileTracing::Provider* g_provider = nullptr; | 12 FileTracing::Provider* g_provider = nullptr; |
13 } | 13 } |
14 | 14 |
15 // static | 15 // static |
| 16 bool FileTracing::IsCategoryEnabled() { |
| 17 return g_provider && g_provider->FileTracingCategoryIsEnabled(); |
| 18 } |
| 19 |
| 20 // static |
16 void FileTracing::SetProvider(FileTracing::Provider* provider) { | 21 void FileTracing::SetProvider(FileTracing::Provider* provider) { |
17 g_provider = provider; | 22 g_provider = provider; |
18 } | 23 } |
19 | 24 |
20 FileTracing::ScopedEnabler::ScopedEnabler() { | 25 FileTracing::ScopedEnabler::ScopedEnabler() { |
21 if (g_provider) | 26 if (g_provider) |
22 g_provider->FileTracingEnable(this); | 27 g_provider->FileTracingEnable(this); |
23 } | 28 } |
24 | 29 |
25 FileTracing::ScopedEnabler::~ScopedEnabler() { | 30 FileTracing::ScopedEnabler::~ScopedEnabler() { |
26 if (g_provider) | 31 if (g_provider) |
27 g_provider->FileTracingDisable(this); | 32 g_provider->FileTracingDisable(this); |
28 } | 33 } |
29 | 34 |
30 FileTracing::ScopedTrace::ScopedTrace() : id_(nullptr) {} | 35 FileTracing::ScopedTrace::ScopedTrace() : id_(nullptr) {} |
31 | 36 |
32 FileTracing::ScopedTrace::~ScopedTrace() { | 37 FileTracing::ScopedTrace::~ScopedTrace() { |
33 if (id_ && g_provider) | 38 if (id_ && g_provider) |
34 g_provider->FileTracingEventEnd(name_, id_); | 39 g_provider->FileTracingEventEnd(name_, id_); |
35 } | 40 } |
36 | 41 |
37 bool FileTracing::ScopedTrace::ShouldInitialize() const { | |
38 return g_provider && g_provider->FileTracingCategoryIsEnabled(); | |
39 } | |
40 | |
41 void FileTracing::ScopedTrace::Initialize( | 42 void FileTracing::ScopedTrace::Initialize( |
42 const char* name, File* file, int64 size) { | 43 const char* name, File* file, int64 size) { |
43 if (!g_provider) | |
44 return; | |
45 | |
46 id_ = &file->trace_enabler_; | 44 id_ = &file->trace_enabler_; |
47 name_ = name; | 45 name_ = name; |
48 | 46 g_provider->FileTracingEventBegin(name_, id_, file->tracing_path_, size); |
49 g_provider->FileTracingEventBegin(name_, id_, file->path_, size); | |
50 } | 47 } |
51 | 48 |
52 } // namespace base | 49 } // namespace base |
OLD | NEW |