[Android] Make adb_install_apk use the device blacklist.
[chromium-blink-merge.git] / base / files / file_tracing.h
blob149bd78a9b4a5000543ff3d36cd88397b4bb9ede
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.
5 #ifndef BASE_FILES_FILE_TRACING_H_
6 #define BASE_FILES_FILE_TRACING_H_
8 #include "base/base_export.h"
9 #include "base/basictypes.h"
10 #include "base/macros.h"
12 #define FILE_TRACING_PREFIX "File"
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)
19 #define SCOPED_FILE_TRACE(name) SCOPED_FILE_TRACE_WITH_SIZE(name, 0)
21 namespace base {
23 class File;
24 class FilePath;
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;
33 // Enables file tracing for |id|. Must be called before recording events.
34 virtual void FileTracingEnable(void* id) = 0;
36 // Disables file tracing for |id|.
37 virtual void FileTracingDisable(void* id) = 0;
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 the number
41 // of bytes involved in the event.
42 virtual void FileTracingEventBegin(
43 const char* name, void* id, const FilePath& path, int64 size) = 0;
45 // Ends an event for |id| with |name|.
46 virtual void FileTracingEventEnd(const char* name, void* id) = 0;
49 // Sets a global file tracing provider to query categories and record events.
50 static void SetProvider(Provider* provider);
52 // Enables file tracing while in scope.
53 class ScopedEnabler {
54 public:
55 ScopedEnabler();
56 ~ScopedEnabler();
59 class ScopedTrace {
60 public:
61 ScopedTrace();
62 ~ScopedTrace();
64 // Whether this trace should be initialized or not.
65 bool ShouldInitialize() const;
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
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.
71 void Initialize(const char* name, File* file, int64 size);
73 private:
74 // The ID of this trace. Based on the |file| passed to |Initialize()|. Must
75 // outlive this class.
76 void* id_;
78 // The name of the event to trace (e.g. "Read", "Write"). Prefixed with
79 // "File".
80 const char* name_;
82 DISALLOW_COPY_AND_ASSIGN(ScopedTrace);
85 DISALLOW_COPY_AND_ASSIGN(FileTracing);
88 } // namespace base
90 #endif // BASE_FILES_FILE_TRACING_H_