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

Side by Side Diff: net/disk_cache/entry_impl.cc

Issue 650068: Disk cache: Use TimeTicks instead of Time for some of the... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « net/disk_cache/entry_impl.h ('k') | net/disk_cache/eviction.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 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 "net/disk_cache/entry_impl.h" 5 #include "net/disk_cache/entry_impl.h"
6 6
7 #include "base/histogram.h" 7 #include "base/histogram.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "net/base/io_buffer.h" 10 #include "net/base/io_buffer.h"
11 #include "net/base/net_errors.h" 11 #include "net/base/net_errors.h"
12 #include "net/disk_cache/backend_impl.h" 12 #include "net/disk_cache/backend_impl.h"
13 #include "net/disk_cache/bitmap.h" 13 #include "net/disk_cache/bitmap.h"
14 #include "net/disk_cache/cache_util.h" 14 #include "net/disk_cache/cache_util.h"
15 #include "net/disk_cache/histogram_macros.h" 15 #include "net/disk_cache/histogram_macros.h"
16 #include "net/disk_cache/sparse_control.h" 16 #include "net/disk_cache/sparse_control.h"
17 17
18 using base::Time; 18 using base::Time;
19 using base::TimeDelta; 19 using base::TimeDelta;
20 using base::TimeTicks;
20 21
21 namespace { 22 namespace {
22 23
23 // Index for the file used to store the key, if any (files_[kKeyFileIndex]). 24 // Index for the file used to store the key, if any (files_[kKeyFileIndex]).
24 const int kKeyFileIndex = 3; 25 const int kKeyFileIndex = 3;
25 26
26 // This class implements FileIOCallback to buffer the callback from a file IO 27 // This class implements FileIOCallback to buffer the callback from a file IO
27 // operation from the actual net class. 28 // operation from the actual net class.
28 class SyncCallback: public disk_cache::FileIOCallback { 29 class SyncCallback: public disk_cache::FileIOCallback {
29 public: 30 public:
30 SyncCallback(disk_cache::EntryImpl* entry, net::IOBuffer* buffer, 31 SyncCallback(disk_cache::EntryImpl* entry, net::IOBuffer* buffer,
31 net::CompletionCallback* callback ) 32 net::CompletionCallback* callback )
32 : entry_(entry), callback_(callback), buf_(buffer), start_(Time::Now()) { 33 : entry_(entry), callback_(callback), buf_(buffer),
34 start_(TimeTicks::Now()) {
33 entry->AddRef(); 35 entry->AddRef();
34 entry->IncrementIoCount(); 36 entry->IncrementIoCount();
35 } 37 }
36 ~SyncCallback() {} 38 ~SyncCallback() {}
37 39
38 virtual void OnFileIOComplete(int bytes_copied); 40 virtual void OnFileIOComplete(int bytes_copied);
39 void Discard(); 41 void Discard();
40 private: 42 private:
41 disk_cache::EntryImpl* entry_; 43 disk_cache::EntryImpl* entry_;
42 net::CompletionCallback* callback_; 44 net::CompletionCallback* callback_;
43 scoped_refptr<net::IOBuffer> buf_; 45 scoped_refptr<net::IOBuffer> buf_;
44 Time start_; 46 TimeTicks start_;
45 47
46 DISALLOW_EVIL_CONSTRUCTORS(SyncCallback); 48 DISALLOW_EVIL_CONSTRUCTORS(SyncCallback);
47 }; 49 };
48 50
49 void SyncCallback::OnFileIOComplete(int bytes_copied) { 51 void SyncCallback::OnFileIOComplete(int bytes_copied) {
50 entry_->DecrementIoCount(); 52 entry_->DecrementIoCount();
51 if (callback_) { 53 if (callback_) {
52 entry_->ReportIOTime(disk_cache::EntryImpl::kAsyncIO, start_); 54 entry_->ReportIOTime(disk_cache::EntryImpl::kAsyncIO, start_);
53 callback_->Run(bytes_copied); 55 callback_->Run(bytes_copied);
54 } 56 }
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 if (index < 0 || index >= kNumStreams) 194 if (index < 0 || index >= kNumStreams)
193 return net::ERR_INVALID_ARGUMENT; 195 return net::ERR_INVALID_ARGUMENT;
194 196
195 int entry_size = entry_.Data()->data_size[index]; 197 int entry_size = entry_.Data()->data_size[index];
196 if (offset >= entry_size || offset < 0 || !buf_len) 198 if (offset >= entry_size || offset < 0 || !buf_len)
197 return 0; 199 return 0;
198 200
199 if (buf_len < 0) 201 if (buf_len < 0)
200 return net::ERR_INVALID_ARGUMENT; 202 return net::ERR_INVALID_ARGUMENT;
201 203
202 Time start = Time::Now(); 204 TimeTicks start = TimeTicks::Now();
203 205
204 if (offset + buf_len > entry_size) 206 if (offset + buf_len > entry_size)
205 buf_len = entry_size - offset; 207 buf_len = entry_size - offset;
206 208
207 UpdateRank(false); 209 UpdateRank(false);
208 210
209 backend_->OnEvent(Stats::READ_DATA); 211 backend_->OnEvent(Stats::READ_DATA);
210 212
211 if (user_buffers_[index].get()) { 213 if (user_buffers_[index].get()) {
212 // Complete the operation locally. 214 // Complete the operation locally.
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 // offset of buf_len could be negative numbers. 265 // offset of buf_len could be negative numbers.
264 if (offset > max_file_size || buf_len > max_file_size || 266 if (offset > max_file_size || buf_len > max_file_size ||
265 offset + buf_len > max_file_size) { 267 offset + buf_len > max_file_size) {
266 int size = offset + buf_len; 268 int size = offset + buf_len;
267 if (size <= max_file_size) 269 if (size <= max_file_size)
268 size = kint32max; 270 size = kint32max;
269 backend_->TooMuchStorageRequested(size); 271 backend_->TooMuchStorageRequested(size);
270 return net::ERR_FAILED; 272 return net::ERR_FAILED;
271 } 273 }
272 274
273 Time start = Time::Now(); 275 TimeTicks start = TimeTicks::Now();
274 276
275 // Read the size at this point (it may change inside prepare). 277 // Read the size at this point (it may change inside prepare).
276 int entry_size = entry_.Data()->data_size[index]; 278 int entry_size = entry_.Data()->data_size[index];
277 if (!PrepareTarget(index, offset, buf_len, truncate)) 279 if (!PrepareTarget(index, offset, buf_len, truncate))
278 return net::ERR_FAILED; 280 return net::ERR_FAILED;
279 281
280 if (entry_size < offset + buf_len) { 282 if (entry_size < offset + buf_len) {
281 unreported_size_[index] += offset + buf_len - entry_size; 283 unreported_size_[index] += offset + buf_len - entry_size;
282 entry_.Data()->data_size[index] = offset + buf_len; 284 entry_.Data()->data_size[index] = offset + buf_len;
283 entry_.set_modified(); 285 entry_.set_modified();
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 return (completed || !completion_callback) ? buf_len : net::ERR_IO_PENDING; 350 return (completed || !completion_callback) ? buf_len : net::ERR_IO_PENDING;
349 } 351 }
350 352
351 int EntryImpl::ReadSparseData(int64 offset, net::IOBuffer* buf, int buf_len, 353 int EntryImpl::ReadSparseData(int64 offset, net::IOBuffer* buf, int buf_len,
352 net::CompletionCallback* completion_callback) { 354 net::CompletionCallback* completion_callback) {
353 DCHECK(node_.Data()->dirty); 355 DCHECK(node_.Data()->dirty);
354 int result = InitSparseData(); 356 int result = InitSparseData();
355 if (net::OK != result) 357 if (net::OK != result)
356 return result; 358 return result;
357 359
358 Time start = Time::Now(); 360 TimeTicks start = TimeTicks::Now();
359 result = sparse_->StartIO(SparseControl::kReadOperation, offset, buf, buf_len, 361 result = sparse_->StartIO(SparseControl::kReadOperation, offset, buf, buf_len,
360 completion_callback); 362 completion_callback);
361 ReportIOTime(kSparseRead, start); 363 ReportIOTime(kSparseRead, start);
362 return result; 364 return result;
363 } 365 }
364 366
365 int EntryImpl::WriteSparseData(int64 offset, net::IOBuffer* buf, int buf_len, 367 int EntryImpl::WriteSparseData(int64 offset, net::IOBuffer* buf, int buf_len,
366 net::CompletionCallback* completion_callback) { 368 net::CompletionCallback* completion_callback) {
367 DCHECK(node_.Data()->dirty); 369 DCHECK(node_.Data()->dirty);
368 int result = InitSparseData(); 370 int result = InitSparseData();
369 if (net::OK != result) 371 if (net::OK != result)
370 return result; 372 return result;
371 373
372 Time start = Time::Now(); 374 TimeTicks start = TimeTicks::Now();
373 result = sparse_->StartIO(SparseControl::kWriteOperation, offset, buf, 375 result = sparse_->StartIO(SparseControl::kWriteOperation, offset, buf,
374 buf_len, completion_callback); 376 buf_len, completion_callback);
375 ReportIOTime(kSparseWrite, start); 377 ReportIOTime(kSparseWrite, start);
376 return result; 378 return result;
377 } 379 }
378 380
379 int EntryImpl::GetAvailableRange(int64 offset, int len, int64* start) { 381 int EntryImpl::GetAvailableRange(int64 offset, int len, int64* start) {
380 int result = InitSparseData(); 382 int result = InitSparseData();
381 if (net::OK != result) 383 if (net::OK != result)
382 return result; 384 return result;
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 void EntryImpl::DecrementIoCount() { 591 void EntryImpl::DecrementIoCount() {
590 backend_->DecrementIoCount(); 592 backend_->DecrementIoCount();
591 } 593 }
592 594
593 void EntryImpl::SetTimes(base::Time last_used, base::Time last_modified) { 595 void EntryImpl::SetTimes(base::Time last_used, base::Time last_modified) {
594 node_.Data()->last_used = last_used.ToInternalValue(); 596 node_.Data()->last_used = last_used.ToInternalValue();
595 node_.Data()->last_modified = last_modified.ToInternalValue(); 597 node_.Data()->last_modified = last_modified.ToInternalValue();
596 node_.set_modified(); 598 node_.set_modified();
597 } 599 }
598 600
599 void EntryImpl::ReportIOTime(Operation op, const base::Time& start) { 601 void EntryImpl::ReportIOTime(Operation op, const base::TimeTicks& start) {
600 int group = backend_->GetSizeGroup(); 602 int group = backend_->GetSizeGroup();
601 switch (op) { 603 switch (op) {
602 case kRead: 604 case kRead:
603 CACHE_UMA(AGE_MS, "ReadTime", group, start); 605 CACHE_UMA(AGE_MS, "ReadTime", group, start);
604 break; 606 break;
605 case kWrite: 607 case kWrite:
606 CACHE_UMA(AGE_MS, "WriteTime", group, start); 608 CACHE_UMA(AGE_MS, "WriteTime", group, start);
607 break; 609 break;
608 case kSparseRead: 610 case kSparseRead:
609 CACHE_UMA(AGE_MS, "SparseReadTime", 0, start); 611 CACHE_UMA(AGE_MS, "SparseReadTime", 0, start);
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
923 Trace("%s 0x%p 0x%x 0x%x", msg, reinterpret_cast<void*>(this), 925 Trace("%s 0x%p 0x%x 0x%x", msg, reinterpret_cast<void*>(this),
924 entry_.address().value(), node_.address().value()); 926 entry_.address().value(), node_.address().value());
925 927
926 Trace(" data: 0x%x 0x%x 0x%x", entry_.Data()->data_addr[0], 928 Trace(" data: 0x%x 0x%x 0x%x", entry_.Data()->data_addr[0],
927 entry_.Data()->data_addr[1], entry_.Data()->long_key); 929 entry_.Data()->data_addr[1], entry_.Data()->long_key);
928 930
929 Trace(" doomed: %d 0x%x", doomed_, dirty); 931 Trace(" doomed: %d 0x%x", doomed_, dirty);
930 } 932 }
931 933
932 } // namespace disk_cache 934 } // namespace disk_cache
OLDNEW
« no previous file with comments | « net/disk_cache/entry_impl.h ('k') | net/disk_cache/eviction.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698