| Index: base/files/file_posix.cc
|
| diff --git a/base/files/file_posix.cc b/base/files/file_posix.cc
|
| index dab9cc25704fcebd4aa7d200ea3ebe5024597adb..4feb4f0bd9ae1e2ec1961b0e948c6328cb58772e 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/scoped_file_trace.h"
|
|
|
| #if defined(OS_ANDROID)
|
| #include "base/os_compat_android.h"
|
| @@ -181,6 +181,7 @@ PlatformFile File::TakePlatformFile() {
|
| }
|
|
|
| void File::Close() {
|
| + ScopedFileTrace trace(path_, "Close", 0);
|
| if (!IsValid())
|
| return;
|
|
|
| @@ -210,6 +211,8 @@ int File::Read(int64 offset, char* data, int size) {
|
| if (size < 0)
|
| return -1;
|
|
|
| + ScopedFileTrace trace(path_, "Read", size);
|
| +
|
| int bytes_read = 0;
|
| int rv;
|
| do {
|
| @@ -230,6 +233,8 @@ int File::ReadAtCurrentPos(char* data, int size) {
|
| if (size < 0)
|
| return -1;
|
|
|
| + ScopedFileTrace trace(path_, "ReadAtCurrentPos", size);
|
| +
|
| int bytes_read = 0;
|
| int rv;
|
| do {
|
| @@ -246,7 +251,7 @@ int File::ReadAtCurrentPos(char* data, int size) {
|
| int File::ReadNoBestEffort(int64 offset, char* data, int size) {
|
| ThreadRestrictions::AssertIOAllowed();
|
| DCHECK(IsValid());
|
| -
|
| + ScopedFileTrace trace(path_, "ReadNoBestEffort", size);
|
| return HANDLE_EINTR(pread(file_.get(), data, size, offset));
|
| }
|
|
|
| @@ -256,6 +261,7 @@ int File::ReadAtCurrentPosNoBestEffort(char* data, int size) {
|
| if (size < 0)
|
| return -1;
|
|
|
| + ScopedFileTrace trace(path_, "ReadAtCurrentPosNoBestEffort", size);
|
| return HANDLE_EINTR(read(file_.get(), data, size));
|
| }
|
|
|
| @@ -269,6 +275,8 @@ int File::Write(int64 offset, const char* data, int size) {
|
| if (size < 0)
|
| return -1;
|
|
|
| + ScopedFileTrace trace(path_, "Write", size);
|
| +
|
| int bytes_written = 0;
|
| int rv;
|
| do {
|
| @@ -289,6 +297,8 @@ int File::WriteAtCurrentPos(const char* data, int size) {
|
| if (size < 0)
|
| return -1;
|
|
|
| + ScopedFileTrace trace(path_, "WriteAtCurrentPos", size);
|
| +
|
| int bytes_written = 0;
|
| int rv;
|
| do {
|
| @@ -309,12 +319,15 @@ int File::WriteAtCurrentPosNoBestEffort(const char* data, int size) {
|
| if (size < 0)
|
| return -1;
|
|
|
| + ScopedFileTrace trace(path_, "WriteAtCurrentPosNoBestEffort", size);
|
| return HANDLE_EINTR(write(file_.get(), data, size));
|
| }
|
|
|
| int64 File::GetLength() {
|
| DCHECK(IsValid());
|
|
|
| + ScopedFileTrace trace(path_, "GetLength", 0);
|
| +
|
| stat_wrapper_t file_info;
|
| if (CallFstat(file_.get(), &file_info))
|
| return false;
|
| @@ -325,6 +338,8 @@ int64 File::GetLength() {
|
| bool File::SetLength(int64 length) {
|
| ThreadRestrictions::AssertIOAllowed();
|
| DCHECK(IsValid());
|
| +
|
| + ScopedFileTrace trace(path_, "SetLength", 0);
|
| return !CallFtruncate(file_.get(), length);
|
| }
|
|
|
| @@ -336,12 +351,15 @@ bool File::SetTimes(Time last_access_time, Time last_modified_time) {
|
| times[0] = last_access_time.ToTimeVal();
|
| times[1] = last_modified_time.ToTimeVal();
|
|
|
| + ScopedFileTrace trace(path_, "SetTimes", 0);
|
| return !CallFutimes(file_.get(), times);
|
| }
|
|
|
| bool File::GetInfo(Info* info) {
|
| DCHECK(IsValid());
|
|
|
| + ScopedFileTrace trace(path_, "GetInfo", 0);
|
| +
|
| stat_wrapper_t file_info;
|
| if (CallFstat(file_.get(), &file_info))
|
| return false;
|
| @@ -351,10 +369,12 @@ bool File::GetInfo(Info* info) {
|
| }
|
|
|
| File::Error File::Lock() {
|
| + ScopedFileTrace trace(path_, "Lock", 0);
|
| return CallFctnlFlock(file_.get(), true);
|
| }
|
|
|
| File::Error File::Unlock() {
|
| + ScopedFileTrace trace(path_, "Unlock", 0);
|
| return CallFctnlFlock(file_.get(), false);
|
| }
|
|
|
| @@ -362,6 +382,8 @@ File File::Duplicate() {
|
| if (!IsValid())
|
| return File();
|
|
|
| + ScopedFileTrace trace(path_, "Duplicate", 0);
|
| +
|
| PlatformFile other_fd = dup(GetPlatformFile());
|
| if (other_fd == -1)
|
| return File(OSErrorToFileError(errno));
|
| @@ -454,10 +476,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());
|
|
|
| + ScopedFileTrace trace(path_, "Initialize", 0);
|
| +
|
| int open_flags = 0;
|
| if (flags & FLAG_CREATE)
|
| open_flags = O_CREAT | O_EXCL;
|
| @@ -509,7 +533,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 +541,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 +556,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 +568,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
|
| + ScopedFileTrace trace(path_, "Flush", 0);
|
| +#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) {
|
|
|