Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(151)

Side by Side Diff: base/files/file_tracing.h

Issue 1216183004: Only set File::[tracing_]path_ when file tracing is enabled. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: it even compiles! Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/files/file_posix.cc ('k') | base/files/file_tracing.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #ifndef BASE_FILES_FILE_TRACING_H_ 5 #ifndef BASE_FILES_FILE_TRACING_H_
6 #define BASE_FILES_FILE_TRACING_H_ 6 #define BASE_FILES_FILE_TRACING_H_
7 7
8 #include "base/base_export.h" 8 #include "base/base_export.h"
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
11 11
12 #define FILE_TRACING_PREFIX "File" 12 #define FILE_TRACING_PREFIX "File"
13 13
14 #define SCOPED_FILE_TRACE_WITH_SIZE(name, size) \ 14 #define SCOPED_FILE_TRACE_WITH_SIZE(name, size) \
15 FileTracing::ScopedTrace scoped_file_trace; \ 15 FileTracing::ScopedTrace scoped_file_trace; \
16 if (scoped_file_trace.ShouldInitialize()) \ 16 if (FileTracing::IsCategoryEnabled()) \
17 scoped_file_trace.Initialize(FILE_TRACING_PREFIX "::" name, this, size) 17 scoped_file_trace.Initialize(FILE_TRACING_PREFIX "::" name, this, size)
18 18
19 #define SCOPED_FILE_TRACE(name) SCOPED_FILE_TRACE_WITH_SIZE(name, 0) 19 #define SCOPED_FILE_TRACE(name) SCOPED_FILE_TRACE_WITH_SIZE(name, 0)
20 20
21 namespace base { 21 namespace base {
22 22
23 class File; 23 class File;
24 class FilePath; 24 class FilePath;
25 25
26 class BASE_EXPORT FileTracing { 26 class BASE_EXPORT FileTracing {
27 public: 27 public:
28 // Whether the file tracing category is enabled.
29 static bool IsCategoryEnabled();
30
28 class Provider { 31 class Provider {
29 public: 32 public:
30 // Whether the file tracing category is currently enabled. 33 // Whether the file tracing category is currently enabled.
31 virtual bool FileTracingCategoryIsEnabled() const = 0; 34 virtual bool FileTracingCategoryIsEnabled() const = 0;
32 35
33 // Enables file tracing for |id|. Must be called before recording events. 36 // Enables file tracing for |id|. Must be called before recording events.
34 virtual void FileTracingEnable(void* id) = 0; 37 virtual void FileTracingEnable(void* id) = 0;
35 38
36 // Disables file tracing for |id|. 39 // Disables file tracing for |id|.
37 virtual void FileTracingDisable(void* id) = 0; 40 virtual void FileTracingDisable(void* id) = 0;
(...skipping 16 matching lines...) Expand all
54 public: 57 public:
55 ScopedEnabler(); 58 ScopedEnabler();
56 ~ScopedEnabler(); 59 ~ScopedEnabler();
57 }; 60 };
58 61
59 class ScopedTrace { 62 class ScopedTrace {
60 public: 63 public:
61 ScopedTrace(); 64 ScopedTrace();
62 ~ScopedTrace(); 65 ~ScopedTrace();
63 66
64 // Whether this trace should be initialized or not.
65 bool ShouldInitialize() const;
66
67 // Called only if the tracing category is enabled. |name| is the name of the 67 // Called only if the tracing category is enabled. |name| is the name of the
68 // event to trace (e.g. "Read", "Write") and must have an application 68 // event to trace (e.g. "Read", "Write") and must have an application
69 // lifetime (e.g. static or literal). |file| is the file being traced; must 69 // lifetime (e.g. static or literal). |file| is the file being traced; must
70 // outlive this class. |size| is the size (in bytes) of this event. 70 // outlive this class. |size| is the size (in bytes) of this event.
71 void Initialize(const char* name, File* file, int64 size); 71 void Initialize(const char* name, File* file, int64 size);
72 72
73 private: 73 private:
74 // The ID of this trace. Based on the |file| passed to |Initialize()|. Must 74 // The ID of this trace. Based on the |file| passed to |Initialize()|. Must
75 // outlive this class. 75 // outlive this class.
76 void* id_; 76 void* id_;
77 77
78 // The name of the event to trace (e.g. "Read", "Write"). Prefixed with 78 // The name of the event to trace (e.g. "Read", "Write"). Prefixed with
79 // "File". 79 // "File".
80 const char* name_; 80 const char* name_;
81 81
82 DISALLOW_COPY_AND_ASSIGN(ScopedTrace); 82 DISALLOW_COPY_AND_ASSIGN(ScopedTrace);
83 }; 83 };
84 84
85 DISALLOW_COPY_AND_ASSIGN(FileTracing); 85 DISALLOW_COPY_AND_ASSIGN(FileTracing);
86 }; 86 };
87 87
88 } // namespace base 88 } // namespace base
89 89
90 #endif // BASE_FILES_FILE_TRACING_H_ 90 #endif // BASE_FILES_FILE_TRACING_H_
OLDNEW
« no previous file with comments | « base/files/file_posix.cc ('k') | base/files/file_tracing.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698