blob: c25772db8ab5a101f47885ce58016eb576687dd7 [file] [log] [blame]
dbeamfe14ece2015-05-11 16:53:47 +09001// 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
9namespace base {
10
11namespace {
12FileTracing::Provider* g_provider = nullptr;
13}
14
15// static
16void FileTracing::SetProvider(FileTracing::Provider* provider) {
17 g_provider = provider;
18}
19
20FileTracing::ScopedEnabler::ScopedEnabler() {
21 if (g_provider)
22 g_provider->FileTracingEnable(this);
23}
24
25FileTracing::ScopedEnabler::~ScopedEnabler() {
26 if (g_provider)
27 g_provider->FileTracingDisable(this);
28}
29
dbeamae926512015-06-10 01:08:16 +090030FileTracing::ScopedTrace::ScopedTrace() : id_(nullptr) {}
dbeamfe14ece2015-05-11 16:53:47 +090031
32FileTracing::ScopedTrace::~ScopedTrace() {
dbeamae926512015-06-10 01:08:16 +090033 if (id_ && g_provider)
34 g_provider->FileTracingEventEnd(name_, id_);
dbeamfe14ece2015-05-11 16:53:47 +090035}
36
37bool FileTracing::ScopedTrace::ShouldInitialize() const {
38 return g_provider && g_provider->FileTracingCategoryIsEnabled();
39}
40
41void FileTracing::ScopedTrace::Initialize(
42 const char* name, File* file, int64 size) {
dbeamae926512015-06-10 01:08:16 +090043 if (!g_provider)
44 return;
dbeamfe14ece2015-05-11 16:53:47 +090045
dbeamae926512015-06-10 01:08:16 +090046 id_ = &file->trace_enabler_;
47 name_ = name;
48
49 g_provider->FileTracingEventBegin(name_, id_, file->path_, size);
dbeamfe14ece2015-05-11 16:53:47 +090050}
51
52} // namespace base