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

Unified Diff: base/trace_event/scoped_file_trace.h

Issue 1072133006: Add granular file tracing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@do-initialize
Patch Set: add async file tracing Created 5 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: base/trace_event/scoped_file_trace.h
diff --git a/base/trace_event/scoped_file_trace.h b/base/trace_event/scoped_file_trace.h
new file mode 100644
index 0000000000000000000000000000000000000000..61fa256ad37e81b4ec7687d8725ed18fe71a1b17
--- /dev/null
+++ b/base/trace_event/scoped_file_trace.h
@@ -0,0 +1,51 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef BASE_TRACE_EVENT_SCOPED_FILE_TRACE_H_
+#define BASE_TRACE_EVENT_SCOPED_FILE_TRACE_H_
+
+#include <string>
+
+#include "base/basictypes.h"
+#include "base/macros.h"
+
+namespace base {
+
+class FilePath;
+
+// A class to trace file I/O. Just stick one in a scope you're tracing like so:
+//
+// FilePath path("/var/run/prog");
+// File prog(path, File::FILE_OPEN | File::FILE_WRITE);
+// {
+// ScopedFileTrace trace(path, "Write", 1);
+// prog.Write(0, "1", 1);
+// }
+//
+// Tracing will be started/stopped automatically based on the scope it lives in.
+//
+class ScopedFileTrace {
+ public:
+ ScopedFileTrace(const FilePath& path, const char* event, size_t bytes);
+ ~ScopedFileTrace();
+
+ // The group that shows up in chrome://tracing.
+ static const char kGroup[];
Dan Beam 2015/04/23 22:32:19 don't really care where this lives; it's arguable
+
+ private:
+ // The file path being traced.
+ std::string path_;
Dan Beam 2015/04/24 03:45:18 Note to self: const
+
+ // The event to trace (e.g. "Read", "Write").
+ const char* event_;
+
+ // Number of bytes involved in this event. Not reported if 0.
+ size_t bytes_;
Dan Beam 2015/04/24 03:45:18 Also const if it's too hard to update with real by
+
+ DISALLOW_COPY_AND_ASSIGN(ScopedFileTrace);
+};
+
+} // namespace base
+
+#endif // BASE_TRACE_EVENT_SCOPED_FILE_TRACE_H_

Powered by Google App Engine
This is Rietveld 408576698