• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/atomicops.h"
8 #include "base/files/file.h"
9 
10 using base::subtle::AtomicWord;
11 
12 namespace base {
13 
14 namespace {
15 AtomicWord g_provider;
16 }
17 
GetProvider()18 FileTracing::Provider* GetProvider() {
19   AtomicWord provider = base::subtle::Acquire_Load(&g_provider);
20   return reinterpret_cast<FileTracing::Provider*>(provider);
21 }
22 
23 // static
IsCategoryEnabled()24 bool FileTracing::IsCategoryEnabled() {
25   FileTracing::Provider* provider = GetProvider();
26   return provider && provider->FileTracingCategoryIsEnabled();
27 }
28 
29 // static
SetProvider(FileTracing::Provider * provider)30 void FileTracing::SetProvider(FileTracing::Provider* provider) {
31   base::subtle::Release_Store(&g_provider,
32                               reinterpret_cast<AtomicWord>(provider));
33 }
34 
ScopedEnabler()35 FileTracing::ScopedEnabler::ScopedEnabler() {
36   FileTracing::Provider* provider = GetProvider();
37   if (provider)
38     provider->FileTracingEnable(this);
39 }
40 
~ScopedEnabler()41 FileTracing::ScopedEnabler::~ScopedEnabler() {
42   FileTracing::Provider* provider = GetProvider();
43   if (provider)
44     provider->FileTracingDisable(this);
45 }
46 
ScopedTrace()47 FileTracing::ScopedTrace::ScopedTrace() : id_(nullptr) {}
48 
~ScopedTrace()49 FileTracing::ScopedTrace::~ScopedTrace() {
50   if (id_) {
51     FileTracing::Provider* provider = GetProvider();
52     if (provider)
53       provider->FileTracingEventEnd(name_, id_);
54   }
55 }
56 
Initialize(const char * name,const File * file,int64_t size)57 void FileTracing::ScopedTrace::Initialize(const char* name,
58                                           const File* file,
59                                           int64_t size) {
60   id_ = &file->trace_enabler_;
61   name_ = name;
62   GetProvider()->FileTracingEventBegin(name_, id_, file->tracing_path_, size);
63 }
64 
65 }  // namespace base
66