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

Unified Diff: base/files/file_posix.cc

Issue 1072133006: Add granular file tracing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@do-initialize
Patch Set: TRACE_EVENT* 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/files/file_posix.cc
diff --git a/base/files/file_posix.cc b/base/files/file_posix.cc
index dab9cc25704fcebd4aa7d200ea3ebe5024597adb..5d7424633df2adc3c078ee86abd3d3e8031bedd3 100644
--- a/base/files/file_posix.cc
+++ b/base/files/file_posix.cc
@@ -9,13 +9,13 @@
#include <sys/stat.h>
#include <unistd.h>
-#include "base/files/file_path.h"
#include "base/files/file_posix_hooks_internal.h"
#include "base/logging.h"
#include "base/metrics/sparse_histogram.h"
#include "base/posix/eintr_wrapper.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/thread_restrictions.h"
+#include "base/trace_event/trace_event.h"
#if defined(OS_ANDROID)
#include "base/os_compat_android.h"
@@ -185,6 +185,7 @@ void File::Close() {
return;
ThreadRestrictions::AssertIOAllowed();
+ TRACE_EVENT1(kTraceGroup, "Close", "path", path_.AsUTF8Unsafe());
UnprotectFileDescriptor(GetPlatformFile());
file_.reset();
}
@@ -192,6 +193,7 @@ void File::Close() {
int64 File::Seek(Whence whence, int64 offset) {
ThreadRestrictions::AssertIOAllowed();
DCHECK(IsValid());
+ TRACE_EVENT1(kTraceGroup, "Seek", "path", path_.AsUTF8Unsafe())
#if defined(OS_ANDROID)
COMPILE_ASSERT(sizeof(int64) == sizeof(off64_t), off64_t_64_bit);
@@ -210,6 +212,8 @@ int File::Read(int64 offset, char* data, int size) {
if (size < 0)
return -1;
+ TRACE_EVENT2(kTraceGroup, "Read", "path", path_.AsUTF8Unsafe(), "size", size);
+
int bytes_read = 0;
int rv;
do {
@@ -230,6 +234,9 @@ int File::ReadAtCurrentPos(char* data, int size) {
if (size < 0)
return -1;
+ TRACE_EVENT2(kTraceGroup, "ReadAtCurrentPost", "path", path_.AsUTF8Unsafe(),
+ "size", size);
+
int bytes_read = 0;
int rv;
do {
@@ -246,7 +253,8 @@ int File::ReadAtCurrentPos(char* data, int size) {
int File::ReadNoBestEffort(int64 offset, char* data, int size) {
ThreadRestrictions::AssertIOAllowed();
DCHECK(IsValid());
-
+ TRACE_EVENT2(kTraceGroup, "ReadNoBestEffort", "path", path_.AsUTF8Unsafe(),
+ "size", size);
return HANDLE_EINTR(pread(file_.get(), data, size, offset));
}
@@ -256,6 +264,8 @@ int File::ReadAtCurrentPosNoBestEffort(char* data, int size) {
if (size < 0)
return -1;
+ TRACE_EVENT2(kTraceGroup, "ReadAtCurrentPosNoBestEffort",
+ "path", path_.AsUTF8Unsafe(), "size", size);
return HANDLE_EINTR(read(file_.get(), data, size));
}
@@ -269,6 +279,9 @@ int File::Write(int64 offset, const char* data, int size) {
if (size < 0)
return -1;
+ TRACE_EVENT2(kTraceGroup, "Write", "path", path_.AsUTF8Unsafe(),
+ "size", size);
+
int bytes_written = 0;
int rv;
do {
@@ -289,6 +302,9 @@ int File::WriteAtCurrentPos(const char* data, int size) {
if (size < 0)
return -1;
+ TRACE_EVENT2(kTraceGroup, "WriteAtCurrentPos", "path", path_.AsUTF8Unsafe(),
+ "size", size);
+
int bytes_written = 0;
int rv;
do {
@@ -309,12 +325,16 @@ int File::WriteAtCurrentPosNoBestEffort(const char* data, int size) {
if (size < 0)
return -1;
+ TRACE_EVENT2(kTraceGroup, "WriteAtCurrentPosNoBestEffort",
+ "path", path_.AsUTF8Unsafe(), "size", size);
return HANDLE_EINTR(write(file_.get(), data, size));
}
int64 File::GetLength() {
DCHECK(IsValid());
+ TRACE_EVENT1(kTraceGroup, "GetLength", "path", path_.AsUTF8Unsafe())
+
stat_wrapper_t file_info;
if (CallFstat(file_.get(), &file_info))
return false;
@@ -325,6 +345,10 @@ int64 File::GetLength() {
bool File::SetLength(int64 length) {
ThreadRestrictions::AssertIOAllowed();
DCHECK(IsValid());
+
+ TRACE_EVENT2(kTraceGroup, "SetLength", "path", path_.AsUTF8Unsafe(),
+ "length", length);
+
return !CallFtruncate(file_.get(), length);
}
@@ -332,6 +356,8 @@ bool File::SetTimes(Time last_access_time, Time last_modified_time) {
ThreadRestrictions::AssertIOAllowed();
DCHECK(IsValid());
+ TRACE_EVENT1(kTraceGroup, "SetTimes", "path", path_.AsUTF8Unsafe())
+
timeval times[2];
times[0] = last_access_time.ToTimeVal();
times[1] = last_modified_time.ToTimeVal();
@@ -342,6 +368,8 @@ bool File::SetTimes(Time last_access_time, Time last_modified_time) {
bool File::GetInfo(Info* info) {
DCHECK(IsValid());
+ TRACE_EVENT1(kTraceGroup, "GetInfo", "path", path_.AsUTF8Unsafe())
+
stat_wrapper_t file_info;
if (CallFstat(file_.get(), &file_info))
return false;
@@ -351,10 +379,12 @@ bool File::GetInfo(Info* info) {
}
File::Error File::Lock() {
+ TRACE_EVENT1(kTraceGroup, "Lock", "path", path_.AsUTF8Unsafe())
return CallFctnlFlock(file_.get(), true);
}
File::Error File::Unlock() {
+ TRACE_EVENT1(kTraceGroup, "Unlock", "path", path_.AsUTF8Unsafe())
return CallFctnlFlock(file_.get(), false);
}
@@ -362,6 +392,8 @@ File File::Duplicate() {
if (!IsValid())
return File();
+ TRACE_EVENT1(kTraceGroup, "Duplicate", "path", path_.AsUTF8Unsafe())
+
PlatformFile other_fd = dup(GetPlatformFile());
if (other_fd == -1)
return File(OSErrorToFileError(errno));
@@ -454,10 +486,12 @@ void File::MemoryCheckingScopedFD::UpdateChecksum() {
// NaCl doesn't implement system calls to open files directly.
#if !defined(OS_NACL)
// TODO(erikkay): does it make sense to support FLAG_EXCLUSIVE_* here?
-void File::DoInitialize(const FilePath& name, uint32 flags) {
+void File::DoInitialize(uint32 flags) {
ThreadRestrictions::AssertIOAllowed();
DCHECK(!IsValid());
+ TRACE_EVENT1(kTraceGroup, "Initialize", "path", path_.AsUTF8Unsafe())
+
int open_flags = 0;
if (flags & FLAG_CREATE)
open_flags = O_CREAT | O_EXCL;
@@ -509,7 +543,7 @@ void File::DoInitialize(const FilePath& name, uint32 flags) {
mode |= S_IRGRP | S_IROTH;
#endif
- int descriptor = HANDLE_EINTR(open(name.value().c_str(), open_flags, mode));
+ int descriptor = HANDLE_EINTR(open(path_.value().c_str(), open_flags, mode));
if (flags & FLAG_OPEN_ALWAYS) {
if (descriptor < 0) {
@@ -517,7 +551,7 @@ void File::DoInitialize(const FilePath& name, uint32 flags) {
if (flags & FLAG_EXCLUSIVE_READ || flags & FLAG_EXCLUSIVE_WRITE)
open_flags |= O_EXCL; // together with O_CREAT implies O_NOFOLLOW
- descriptor = HANDLE_EINTR(open(name.value().c_str(), open_flags, mode));
+ descriptor = HANDLE_EINTR(open(path_.value().c_str(), open_flags, mode));
if (descriptor >= 0)
created_ = true;
}
@@ -532,7 +566,7 @@ void File::DoInitialize(const FilePath& name, uint32 flags) {
created_ = true;
if (flags & FLAG_DELETE_ON_CLOSE)
- unlink(name.value().c_str());
+ unlink(path_.value().c_str());
async_ = ((flags & FLAG_ASYNC) == FLAG_ASYNC);
error_details_ = FILE_OK;
@@ -544,14 +578,18 @@ void File::DoInitialize(const FilePath& name, uint32 flags) {
bool File::DoFlush() {
ThreadRestrictions::AssertIOAllowed();
DCHECK(IsValid());
+
#if defined(OS_NACL)
NOTIMPLEMENTED(); // NaCl doesn't implement fsync.
return true;
-#elif defined(OS_LINUX) || defined(OS_ANDROID)
+#else
Lei Zhang 2015/04/27 22:55:55 how about: { #if defined(OS_NACL) ... return; #el
Dan Beam 2015/04/28 03:17:11 Done.
Lei Zhang 2015/04/28 03:53:26 Oh, sorry for the bad advice. OS_NACL will still t
Dan Beam 2015/04/28 04:06:10 Reverted back to this code.
+ TRACE_EVENT1(kTraceGroup, "Flush", "path", path_.AsUTF8Unsafe())
+#if defined(OS_LINUX) || defined(OS_ANDROID)
return !HANDLE_EINTR(fdatasync(file_.get()));
#else
return !HANDLE_EINTR(fsync(file_.get()));
-#endif
+#endif // defined(OS_LINUX) || defined(OS_ANDROID)
+#endif // defined(OS_NACL)
}
void File::SetPlatformFile(PlatformFile file) {
« base/files/file.cc ('K') | « base/files/file.cc ('k') | base/files/file_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698