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

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

Issue 1072133006: Add granular file tracing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@do-initialize
Patch Set: actually compiles :D Created 5 years, 7 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
(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 #ifndef BASE_FILES_FILE_TRACING_H_
6 #define BASE_FILES_FILE_TRACING_H_
7
8 #include "base/base_export.h"
9 #include "base/basictypes.h"
10 #include "base/macros.h"
11
12 #define FILE_TRACING_PREFIX "File"
13
14 #define SCOPED_FILE_TRACE_WITH_SIZE(name, size) \
15 FileTracing::ScopedTrace scoped_file_trace; \
16 if (scoped_file_trace.ShouldInitialize()) \
17 scoped_file_trace.Initialize(FILE_TRACING_PREFIX "::" name, this, size)
18
19 #define SCOPED_FILE_TRACE(name) SCOPED_FILE_TRACE_WITH_SIZE(name, 0)
20
21 namespace base {
22
23 class File;
24 class FilePath;
25
26 class BASE_EXPORT FileTracing {
27 public:
28 class Provider {
29 public:
30 // Whether the file tracing category is currently enabled.
31 virtual bool FileTracingCategoryIsEnabled() const = 0;
32
33 // Enables file tracing for |id|. Must be called before recording events.
34 virtual void FileTracingEnable(void* id) = 0;
35
36 // Disables file tracing for |id|.
37 virtual void FileTracingDisable(void* id) = 0;
38
39 // Begins an event for |id| with |name|. |path| tells where in the directory
40 // structure the event is happening (and may be blank). |size| is reported
41 // if not 0.
42 virtual void FileTracingEventBegin(
43 const char* name, void* id, const FilePath& path, int64 size) = 0;
44
45 // Ends an event for |id| with |name|. |path| tells where in the directory
46 // structure the event is happening (and may be blank). |size| is reported
47 // if not 0.
48 virtual void FileTracingEventEnd(
49 const char* name, void* id, const FilePath& path, int64 size) = 0;
50 };
51
52 static Provider* g_provider;
Lei Zhang 2015/05/08 17:40:19 Can you have a static SetProvider() method instead
Dan Beam 2015/05/08 18:54:03 Done.
53
54 // Enables file tracing while in scope.
55 class ScopedEnabler {
56 public:
57 ScopedEnabler();
58 ~ScopedEnabler();
59 };
60
61 class ScopedTrace {
62 public:
63 ScopedTrace();
64 ~ScopedTrace();
65
66 // Whether this trace should be initialized or not.
67 bool ShouldInitialize() const;
Lei Zhang 2015/05/08 17:40:19 Any reason to have this separated from Initialize(
Dan Beam 2015/05/08 18:54:03 less work is done in the common case that the cate
68
69 // Called only if the tracing category is enabled.
70 void Initialize(const char* event, File* file, int64 size);
71
72 private:
73 // True if |Initialize()| has been called. Don't touch |path_|, |event_|,
74 // or |bytes_| if |initialized_| is false.
75 bool initialized_;
76
77 // The event name to trace (e.g. "Read", "Write"). Prefixed with "File".
78 const char* name_;
79
80 // The file being traced. Must outlive this class.
81 File* file_;
82
83 // The size (in bytes) of this trace. Not reported if 0.
84 int64 size_;
85
86 DISALLOW_COPY_AND_ASSIGN(ScopedTrace);
87 };
88
89 DISALLOW_COPY_AND_ASSIGN(FileTracing);
90 };
91
92 } // namespace base
93
94 #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