Simplify file tracing end events.
R=oysteine@chromium.org
BUG=none
TEST=pathless file trace events with size work
Review URL: https://codereview.chromium.org/1149083012
Cr-Commit-Position: refs/heads/master@{#333498}
CrOS-Libchrome-Original-Commit: 97f619f66b30bcafe0fd211f1e09bcf6ae4f325d
diff --git a/base/files/file_tracing.cc b/base/files/file_tracing.cc
index a1919c4..c25772d 100644
--- a/base/files/file_tracing.cc
+++ b/base/files/file_tracing.cc
@@ -27,13 +27,11 @@
g_provider->FileTracingDisable(this);
}
-FileTracing::ScopedTrace::ScopedTrace() : initialized_(false) {}
+FileTracing::ScopedTrace::ScopedTrace() : id_(nullptr) {}
FileTracing::ScopedTrace::~ScopedTrace() {
- if (initialized_ && g_provider) {
- g_provider->FileTracingEventEnd(
- name_, &file_->trace_enabler_, file_->path_, size_);
- }
+ if (id_ && g_provider)
+ g_provider->FileTracingEventEnd(name_, id_);
}
bool FileTracing::ScopedTrace::ShouldInitialize() const {
@@ -42,15 +40,13 @@
void FileTracing::ScopedTrace::Initialize(
const char* name, File* file, int64 size) {
- file_ = file;
- name_ = name;
- size_ = size;
- initialized_ = true;
+ if (!g_provider)
+ return;
- if (g_provider) {
- g_provider->FileTracingEventBegin(
- name_, &file_->trace_enabler_, file_->path_, size_);
- }
+ id_ = &file->trace_enabler_;
+ name_ = name;
+
+ g_provider->FileTracingEventBegin(name_, id_, file->path_, size);
}
} // namespace base
diff --git a/base/files/file_tracing.h b/base/files/file_tracing.h
index 8452037..149bd78 100644
--- a/base/files/file_tracing.h
+++ b/base/files/file_tracing.h
@@ -37,16 +37,13 @@
virtual void FileTracingDisable(void* id) = 0;
// Begins an event for |id| with |name|. |path| tells where in the directory
- // structure the event is happening (and may be blank). |size| is reported
- // if not 0.
+ // structure the event is happening (and may be blank). |size| is the number
+ // of bytes involved in the event.
virtual void FileTracingEventBegin(
const char* name, void* id, const FilePath& path, int64 size) = 0;
- // Ends an event for |id| with |name|. |path| tells where in the directory
- // structure the event is happening (and may be blank). |size| is reported
- // if not 0.
- virtual void FileTracingEventEnd(
- const char* name, void* id, const FilePath& path, int64 size) = 0;
+ // Ends an event for |id| with |name|.
+ virtual void FileTracingEventEnd(const char* name, void* id) = 0;
};
// Sets a global file tracing provider to query categories and record events.
@@ -67,23 +64,21 @@
// Whether this trace should be initialized or not.
bool ShouldInitialize() const;
- // Called only if the tracing category is enabled.
- void Initialize(const char* event, File* file, int64 size);
+ // Called only if the tracing category is enabled. |name| is the name of the
+ // event to trace (e.g. "Read", "Write") and must have an application
+ // lifetime (e.g. static or literal). |file| is the file being traced; must
+ // outlive this class. |size| is the size (in bytes) of this event.
+ void Initialize(const char* name, File* file, int64 size);
private:
- // True if |Initialize()| has been called. Don't touch |path_|, |event_|,
- // or |bytes_| if |initialized_| is false.
- bool initialized_;
+ // The ID of this trace. Based on the |file| passed to |Initialize()|. Must
+ // outlive this class.
+ void* id_;
- // The event name to trace (e.g. "Read", "Write"). Prefixed with "File".
+ // The name of the event to trace (e.g. "Read", "Write"). Prefixed with
+ // "File".
const char* name_;
- // The file being traced. Must outlive this class.
- File* file_;
-
- // The size (in bytes) of this trace. Not reported if 0.
- int64 size_;
-
DISALLOW_COPY_AND_ASSIGN(ScopedTrace);
};
diff --git a/base/trace_event/trace_event.h b/base/trace_event/trace_event.h
index 6fdbf41..397bafc 100644
--- a/base/trace_event/trace_event.h
+++ b/base/trace_event/trace_event.h
@@ -731,16 +731,12 @@
INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_NESTABLE_ASYNC_BEGIN, \
category_group, name, id, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, \
arg2_name, arg2_val)
-// Records a single NESTABLE_ASYNC_END event called "name" immediately, with 0,
-// 1, or 2 associated arguments. If the category is not enabled, then this does
+// Records a single NESTABLE_ASYNC_END event called "name" immediately, with 0
+// or 2 associated arguments. If the category is not enabled, then this does
// nothing.
#define TRACE_EVENT_NESTABLE_ASYNC_END0(category_group, name, id) \
INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_NESTABLE_ASYNC_END, \
category_group, name, id, TRACE_EVENT_FLAG_NONE)
-#define TRACE_EVENT_NESTABLE_ASYNC_END1(category_group, name, id, arg1_name, \
- arg1_val) \
- INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_NESTABLE_ASYNC_END, \
- category_group, name, id, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val)
#define TRACE_EVENT_NESTABLE_ASYNC_END2(category_group, name, id, arg1_name, \
arg1_val, arg2_name, arg2_val) \
INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_NESTABLE_ASYNC_END, \