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

Side by Side Diff: base/files/file.cc

Issue 1072133006: Add granular file tracing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@do-initialize
Patch Set: herp Created 5 years, 7 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/files/file.h" 5 #include "base/files/file.h"
6 #include "base/files/file_path.h" 6 #include "base/files/file_path.h"
7 #include "base/metrics/histogram.h" 7 #include "base/metrics/histogram.h"
8 #include "base/timer/elapsed_timer.h" 8 #include "base/timer/elapsed_timer.h"
9 #include "base/trace_event/trace_event.h"
9 10
10 namespace base { 11 namespace base {
11 12
12 File::Info::Info() 13 File::Info::Info()
13 : size(0), 14 : size(0),
14 is_directory(false), 15 is_directory(false),
15 is_symbolic_link(false) { 16 is_symbolic_link(false) {
16 } 17 }
17 18
18 File::Info::~Info() { 19 File::Info::~Info() {
19 } 20 }
20 21
21 File::File() 22 File::File()
22 : error_details_(FILE_ERROR_FAILED), 23 : error_details_(FILE_ERROR_FAILED),
23 created_(false), 24 created_(false),
24 async_(false) { 25 async_(false) {
26 TRACE_EVENT_ASYNC_BEGIN0(kTraceGroup, "File", this);
25 } 27 }
26 28
27 #if !defined(OS_NACL) 29 #if !defined(OS_NACL)
28 File::File(const FilePath& name, uint32 flags) 30 File::File(const FilePath& path, uint32 flags)
29 : error_details_(FILE_OK), 31 : error_details_(FILE_OK), created_(false), async_(false) {
30 created_(false), 32 TRACE_EVENT_ASYNC_BEGIN0(kTraceGroup, "File", this);
31 async_(false) { 33 Initialize(path, flags);
32 Initialize(name, flags);
33 } 34 }
34 #endif 35 #endif
35 36
36 File::File(PlatformFile platform_file) 37 File::File(PlatformFile platform_file)
37 : file_(platform_file), 38 : file_(platform_file),
38 error_details_(FILE_OK), 39 error_details_(FILE_OK),
39 created_(false), 40 created_(false),
40 async_(false) { 41 async_(false) {
41 #if defined(OS_POSIX) 42 #if defined(OS_POSIX)
42 DCHECK_GE(platform_file, -1); 43 DCHECK_GE(platform_file, -1);
43 #endif 44 #endif
45 TRACE_EVENT_ASYNC_BEGIN0(kTraceGroup, "File", this);
44 } 46 }
45 47
46 File::File(Error error_details) 48 File::File(Error error_details)
47 : error_details_(error_details), 49 : error_details_(error_details),
48 created_(false), 50 created_(false),
49 async_(false) { 51 async_(false) {
52 TRACE_EVENT_ASYNC_BEGIN0(kTraceGroup, "File", this);
50 } 53 }
51 54
52 File::File(RValue other) 55 File::File(RValue other)
53 : file_(other.object->TakePlatformFile()), 56 : file_(other.object->TakePlatformFile()),
57 unsafe_path_(other.object->unsafe_path_),
54 error_details_(other.object->error_details()), 58 error_details_(other.object->error_details()),
55 created_(other.object->created()), 59 created_(other.object->created()),
56 async_(other.object->async_) { 60 async_(other.object->async_) {
61 TRACE_EVENT_ASYNC_BEGIN0(kTraceGroup, "File", this);
57 } 62 }
58 63
59 File::~File() { 64 File::~File() {
60 // Go through the AssertIOAllowed logic. 65 // Go through the AssertIOAllowed logic.
61 Close(); 66 Close();
67 TRACE_EVENT_ASYNC_END0(kTraceGroup, "File", this);
62 } 68 }
63 69
64 File& File::operator=(RValue other) { 70 File& File::operator=(RValue other) {
65 if (this != other.object) { 71 if (this != other.object) {
66 Close(); 72 Close();
67 SetPlatformFile(other.object->TakePlatformFile()); 73 SetPlatformFile(other.object->TakePlatformFile());
74 unsafe_path_ = other.object->unsafe_path_;
68 error_details_ = other.object->error_details(); 75 error_details_ = other.object->error_details();
69 created_ = other.object->created(); 76 created_ = other.object->created();
70 async_ = other.object->async_; 77 async_ = other.object->async_;
71 } 78 }
72 return *this; 79 return *this;
73 } 80 }
74 81
75 #if !defined(OS_NACL) 82 #if !defined(OS_NACL)
76 void File::Initialize(const FilePath& name, uint32 flags) { 83 void File::Initialize(const FilePath& path, uint32 flags) {
77 if (name.ReferencesParent()) { 84 unsafe_path_ = path;
85 if (unsafe_path_.ReferencesParent()) {
78 error_details_ = FILE_ERROR_ACCESS_DENIED; 86 error_details_ = FILE_ERROR_ACCESS_DENIED;
79 return; 87 return;
80 } 88 }
81 DoInitialize(name, flags); 89 TRACE_EVENT_ID1(kTraceGroup, "Initialize", this, "path",
90 unsafe_path_.AsUTF8Unsafe());
91 DoInitialize(flags);
82 } 92 }
83 #endif 93 #endif
84 94
85 std::string File::ErrorToString(Error error) { 95 std::string File::ErrorToString(Error error) {
86 switch (error) { 96 switch (error) {
87 case FILE_OK: 97 case FILE_OK:
88 return "FILE_OK"; 98 return "FILE_OK";
89 case FILE_ERROR_FAILED: 99 case FILE_ERROR_FAILED:
90 return "FILE_ERROR_FAILED"; 100 return "FILE_ERROR_FAILED";
91 case FILE_ERROR_IN_USE: 101 case FILE_ERROR_IN_USE:
(...skipping 27 matching lines...) Expand all
119 case FILE_ERROR_IO: 129 case FILE_ERROR_IO:
120 return "FILE_ERROR_IO"; 130 return "FILE_ERROR_IO";
121 case FILE_ERROR_MAX: 131 case FILE_ERROR_MAX:
122 break; 132 break;
123 } 133 }
124 134
125 NOTREACHED(); 135 NOTREACHED();
126 return ""; 136 return "";
127 } 137 }
128 138
139 // static
140 const char File::kTraceGroup[] = TRACE_DISABLED_BY_DEFAULT("file");
141
129 bool File::Flush() { 142 bool File::Flush() {
130 ElapsedTimer timer; 143 ElapsedTimer timer;
131 bool return_value = DoFlush(); 144 bool return_value = DoFlush();
132 UMA_HISTOGRAM_TIMES("PlatformFile.FlushTime", timer.Elapsed()); 145 UMA_HISTOGRAM_TIMES("PlatformFile.FlushTime", timer.Elapsed());
133 return return_value; 146 return return_value;
134 } 147 }
135 148
136 } // namespace base 149 } // namespace base
OLDNEW
« no previous file with comments | « base/files/file.h ('k') | base/files/file_posix.cc » ('j') | base/trace_event/trace_event.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698