OLD | NEW |
| (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/basictypes.h" | |
9 #include "base/macros.h" | |
10 #include "base/trace_event/trace_event.h" | |
11 | |
12 #define FILE_TRACING_PREFIX "File" | |
13 | |
14 #define FILE_TRACING_BEGIN() \ | |
15 TRACE_EVENT_NESTABLE_ASYNC_BEGIN0( \ | |
16 base::kFileTracingEventCategoryGroup, FILE_TRACING_PREFIX, this) | |
17 | |
18 #define FILE_TRACING_END() \ | |
19 TRACE_EVENT_NESTABLE_ASYNC_END0( \ | |
20 base::kFileTracingEventCategoryGroup, FILE_TRACING_PREFIX, this) | |
21 | |
22 #define SCOPED_FILE_TRACE_WITH_SIZE(name, size) \ | |
23 base::ScopedFileTrace scoped_file_trace; \ | |
24 do { \ | |
25 bool category_enabled; \ | |
26 TRACE_EVENT_CATEGORY_GROUP_ENABLED( \ | |
27 base::kFileTracingEventCategoryGroup, &category_enabled); \ | |
28 if (category_enabled) \ | |
29 scoped_file_trace.Initialize( \ | |
30 FILE_TRACING_PREFIX "::" name, this, size); \ | |
31 } while (0) | |
32 | |
33 #define SCOPED_FILE_TRACE(name) SCOPED_FILE_TRACE_WITH_SIZE(name, 0) | |
34 | |
35 namespace base { | |
36 | |
37 class File; | |
38 | |
39 extern const char kFileTracingEventCategoryGroup[]; | |
40 | |
41 class ScopedFileTrace { | |
42 public: | |
43 ScopedFileTrace(); | |
44 ~ScopedFileTrace(); | |
45 | |
46 // Called only if the tracing category is enabled. | |
47 void Initialize(const char* event, File* file, int64 size); | |
48 | |
49 private: | |
50 // True if |Initialize()| has been called. Don't touch |path_|, |event_|, | |
51 // or |bytes_| if |initialized_| is false. | |
52 bool initialized_; | |
53 | |
54 // The event name to trace (e.g. "Read", "Write"). Prefixed with "base::File". | |
55 const char* name_; | |
56 | |
57 // The file being traced. Must outlive this class. | |
58 File* file_; | |
59 | |
60 // The size (in bytes) of this trace. Not reported if 0. | |
61 int64 size_; | |
62 | |
63 DISALLOW_COPY_AND_ASSIGN(ScopedFileTrace); | |
64 }; | |
65 | |
66 } // namespace base | |
67 | |
68 #endif // BASE_FILES_FILE_TRACING_H_ | |
OLD | NEW |