diff options
Diffstat (limited to 'net/disk_cache')
-rw-r--r-- | net/disk_cache/backend_impl.cc | 29 | ||||
-rw-r--r-- | net/disk_cache/backend_impl.h | 14 | ||||
-rw-r--r-- | net/disk_cache/backend_unittest.cc | 22 | ||||
-rw-r--r-- | net/disk_cache/disk_cache.h | 4 | ||||
-rw-r--r-- | net/disk_cache/disk_cache_perftest.cc | 4 | ||||
-rw-r--r-- | net/disk_cache/disk_cache_test_base.cc | 6 | ||||
-rw-r--r-- | net/disk_cache/disk_cache_test_util.cc | 2 | ||||
-rw-r--r-- | net/disk_cache/entry_impl.cc | 165 | ||||
-rw-r--r-- | net/disk_cache/entry_impl.h | 18 | ||||
-rw-r--r-- | net/disk_cache/sparse_control.cc | 52 | ||||
-rw-r--r-- | net/disk_cache/stress_cache.cc | 2 |
11 files changed, 277 insertions, 41 deletions
diff --git a/net/disk_cache/backend_impl.cc b/net/disk_cache/backend_impl.cc index 58a6e9e..223c970 100644 --- a/net/disk_cache/backend_impl.cc +++ b/net/disk_cache/backend_impl.cc @@ -194,11 +194,12 @@ class CacheCreator { public: CacheCreator(const FilePath& path, bool force, int max_bytes, net::CacheType type, uint32 flags, - base::MessageLoopProxy* thread, disk_cache::Backend** backend, + base::MessageLoopProxy* thread, net::NetLog* net_log, + disk_cache::Backend** backend, net::CompletionCallback* callback) : path_(path), force_(force), retry_(false), max_bytes_(max_bytes), type_(type), flags_(flags), thread_(thread), backend_(backend), - callback_(callback), cache_(NULL), + callback_(callback), cache_(NULL), net_log_(net_log), ALLOW_THIS_IN_INITIALIZER_LIST( my_callback_(this, &CacheCreator::OnIOComplete)) { } @@ -223,13 +224,14 @@ class CacheCreator { disk_cache::Backend** backend_; net::CompletionCallback* callback_; disk_cache::BackendImpl* cache_; + net::NetLog* net_log_; net::CompletionCallbackImpl<CacheCreator> my_callback_; DISALLOW_COPY_AND_ASSIGN(CacheCreator); }; int CacheCreator::Run() { - cache_ = new disk_cache::BackendImpl(path_, thread_); + cache_ = new disk_cache::BackendImpl(path_, thread_, net_log_); cache_->SetMaxSize(max_bytes_); cache_->SetType(type_); cache_->SetFlags(flags_); @@ -295,7 +297,8 @@ namespace disk_cache { int CreateCacheBackend(net::CacheType type, const FilePath& path, int max_bytes, bool force, base::MessageLoopProxy* thread, - Backend** backend, CompletionCallback* callback) { + net::NetLog* net_log, Backend** backend, + CompletionCallback* callback) { DCHECK(callback); if (type == net::MEMORY_CACHE) { *backend = MemBackendImpl::CreateBackend(max_bytes); @@ -304,7 +307,7 @@ int CreateCacheBackend(net::CacheType type, const FilePath& path, int max_bytes, DCHECK(thread); return BackendImpl::CreateBackend(path, force, max_bytes, type, kNone, thread, - backend, callback); + net_log, backend, callback); } // Returns the preferred maximum number of bytes for the cache given the @@ -351,11 +354,12 @@ int PreferedCacheSize(int64 available) { int BackendImpl::CreateBackend(const FilePath& full_path, bool force, int max_bytes, net::CacheType type, uint32 flags, base::MessageLoopProxy* thread, - Backend** backend, + net::NetLog* net_log, Backend** backend, CompletionCallback* callback) { DCHECK(callback); CacheCreator* creator = new CacheCreator(full_path, force, max_bytes, type, - flags, thread, backend, callback); + flags, thread, net_log, backend, + callback); // This object will self-destroy when finished. return creator->Run(); } @@ -366,7 +370,8 @@ int BackendImpl::Init(CompletionCallback* callback) { } BackendImpl::BackendImpl(const FilePath& path, - base::MessageLoopProxy* cache_thread) + base::MessageLoopProxy* cache_thread, + net::NetLog* net_log) : ALLOW_THIS_IN_INITIALIZER_LIST(background_queue_(this, cache_thread)), path_(path), block_files_(path), @@ -383,6 +388,7 @@ BackendImpl::BackendImpl(const FilePath& path, new_eviction_(false), first_timer_(true), throttle_requests_(false), + net_log_(net_log), done_(true, false), ALLOW_THIS_IN_INITIALIZER_LIST(factory_(this)), ALLOW_THIS_IN_INITIALIZER_LIST(ptr_factory_(this)) { @@ -390,7 +396,8 @@ BackendImpl::BackendImpl(const FilePath& path, BackendImpl::BackendImpl(const FilePath& path, uint32 mask, - base::MessageLoopProxy* cache_thread) + base::MessageLoopProxy* cache_thread, + net::NetLog* net_log) : ALLOW_THIS_IN_INITIALIZER_LIST(background_queue_(this, cache_thread)), path_(path), block_files_(path), @@ -407,6 +414,7 @@ BackendImpl::BackendImpl(const FilePath& path, new_eviction_(false), first_timer_(true), throttle_requests_(false), + net_log_(net_log), done_(true, false), ALLOW_THIS_IN_INITIALIZER_LIST(factory_(this)), ALLOW_THIS_IN_INITIALIZER_LIST(ptr_factory_(this)) { @@ -848,6 +856,8 @@ EntryImpl* BackendImpl::CreateEntryImpl(const std::string& key) { return NULL; } + cache_entry->BeginLogging(net_log_, true); + // We are not failing the operation; let's add this to the map. open_entries_[entry_address.value()] = cache_entry; @@ -1537,6 +1547,7 @@ int BackendImpl::NewEntry(Addr address, EntryImpl** entry, bool* dirty) { open_entries_[address.value()] = cache_entry; } + cache_entry->BeginLogging(net_log_, false); cache_entry.swap(entry); return 0; } diff --git a/net/disk_cache/backend_impl.h b/net/disk_cache/backend_impl.h index 5637fbd..b481525 100644 --- a/net/disk_cache/backend_impl.h +++ b/net/disk_cache/backend_impl.h @@ -19,6 +19,10 @@ #include "net/disk_cache/stats.h" #include "net/disk_cache/trace.h" +namespace net { +class NetLog; +} // namespace net + namespace disk_cache { enum BackendFlags { @@ -38,10 +42,11 @@ enum BackendFlags { class BackendImpl : public Backend { friend class Eviction; public: - BackendImpl(const FilePath& path, base::MessageLoopProxy* cache_thread); + BackendImpl(const FilePath& path, base::MessageLoopProxy* cache_thread, + net::NetLog* net_log); // mask can be used to limit the usable size of the hash table, for testing. BackendImpl(const FilePath& path, uint32 mask, - base::MessageLoopProxy* cache_thread); + base::MessageLoopProxy* cache_thread, net::NetLog* net_log); ~BackendImpl(); // Returns a new backend with the desired flags. See the declaration of @@ -49,7 +54,8 @@ class BackendImpl : public Backend { static int CreateBackend(const FilePath& full_path, bool force, int max_bytes, net::CacheType type, uint32 flags, base::MessageLoopProxy* thread, - Backend** backend, CompletionCallback* callback); + net::NetLog* net_log, Backend** backend, + CompletionCallback* callback); // Performs general initialization for this current instance of the cache. int Init(CompletionCallback* callback); @@ -357,6 +363,8 @@ class BackendImpl : public Backend { bool first_timer_; // True if the timer has not been called. bool throttle_requests_; + net::NetLog* net_log_; + Stats stats_; // Usage statistcs. base::RepeatingTimer<BackendImpl> timer_; // Usage timer. base::WaitableEvent done_; // Signals the end of background work. diff --git a/net/disk_cache/backend_unittest.cc b/net/disk_cache/backend_unittest.cc index 9077996..eaa00eb 100644 --- a/net/disk_cache/backend_unittest.cc +++ b/net/disk_cache/backend_unittest.cc @@ -195,7 +195,7 @@ TEST_F(DiskCacheTest, CreateBackend) { disk_cache::Backend* cache = NULL; int rv = disk_cache::BackendImpl::CreateBackend( path, false, 0, net::DISK_CACHE, disk_cache::kNoRandom, - cache_thread.message_loop_proxy(), &cache, &cb); + cache_thread.message_loop_proxy(), NULL, &cache, &cb); ASSERT_EQ(net::OK, cb.GetResult(rv)); ASSERT_TRUE(cache); delete cache; @@ -208,14 +208,14 @@ TEST_F(DiskCacheTest, CreateBackend) { // Now test the public API. rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, path, 0, false, cache_thread.message_loop_proxy(), - &cache, &cb); + NULL, &cache, &cb); ASSERT_EQ(net::OK, cb.GetResult(rv)); ASSERT_TRUE(cache); delete cache; cache = NULL; rv = disk_cache::CreateCacheBackend(net::MEMORY_CACHE, FilePath(), 0, false, - NULL, &cache, &cb); + NULL, NULL, &cache, &cb); ASSERT_EQ(net::OK, cb.GetResult(rv)); ASSERT_TRUE(cache); delete cache; @@ -260,7 +260,8 @@ TEST_F(DiskCacheTest, ShutdownWithPendingIO) { disk_cache::Backend* cache; int rv = disk_cache::BackendImpl::CreateBackend( path, false, 0, net::DISK_CACHE, disk_cache::kNoRandom, - base::MessageLoopProxy::CreateForCurrentThread(), &cache, &cb); + base::MessageLoopProxy::CreateForCurrentThread(), NULL, + &cache, &cb); ASSERT_EQ(net::OK, cb.GetResult(rv)); disk_cache::EntryImpl* entry; @@ -311,7 +312,7 @@ TEST_F(DiskCacheTest, ShutdownWithPendingIO2) { disk_cache::Backend* cache; int rv = disk_cache::BackendImpl::CreateBackend( path, false, 0, net::DISK_CACHE, disk_cache::kNoRandom, - cache_thread.message_loop_proxy(), &cache, &cb); + cache_thread.message_loop_proxy(), NULL, &cache, &cb); ASSERT_EQ(net::OK, cb.GetResult(rv)); disk_cache::Entry* entry; @@ -348,7 +349,7 @@ TEST_F(DiskCacheTest, TruncatedIndex) { disk_cache::Backend* backend = NULL; int rv = disk_cache::BackendImpl::CreateBackend( path, false, 0, net::DISK_CACHE, disk_cache::kNone, - cache_thread.message_loop_proxy(), &backend, &cb); + cache_thread.message_loop_proxy(), NULL, &backend, &cb); ASSERT_NE(net::OK, cb.GetResult(rv)); ASSERT_TRUE(backend == NULL); @@ -1278,7 +1279,7 @@ TEST_F(DiskCacheTest, DeleteOld) { disk_cache::Backend* cache; int rv = disk_cache::BackendImpl::CreateBackend( path, true, 0, net::DISK_CACHE, disk_cache::kNoRandom, - cache_thread.message_loop_proxy(), &cache, &cb); + cache_thread.message_loop_proxy(), NULL, &cache, &cb); ASSERT_EQ(net::OK, cb.GetResult(rv)); MessageLoopHelper helper; @@ -1651,7 +1652,8 @@ TEST_F(DiskCacheTest, Backend_UsageStats) { ASSERT_TRUE(DeleteCache(path)); scoped_ptr<disk_cache::BackendImpl> cache; cache.reset(new disk_cache::BackendImpl( - path, base::MessageLoopProxy::CreateForCurrentThread())); + path, base::MessageLoopProxy::CreateForCurrentThread(), + NULL)); ASSERT_TRUE(NULL != cache.get()); cache->SetUnitTestMode(); ASSERT_EQ(net::OK, cache->SyncInit()); @@ -1769,11 +1771,11 @@ TEST_F(DiskCacheTest, MultipleInstances) { int rv = disk_cache::BackendImpl::CreateBackend( store1.path(), false, 0, net::DISK_CACHE, disk_cache::kNone, - cache_thread.message_loop_proxy(), &cache[0], &cb); + cache_thread.message_loop_proxy(), NULL, &cache[0], &cb); ASSERT_EQ(net::OK, cb.GetResult(rv)); rv = disk_cache::BackendImpl::CreateBackend( store2.path(), false, 0, net::MEDIA_CACHE, disk_cache::kNone, - cache_thread.message_loop_proxy(), &cache[1], &cb); + cache_thread.message_loop_proxy(), NULL, &cache[1], &cb); ASSERT_EQ(net::OK, cb.GetResult(rv)); ASSERT_TRUE(cache[0] != NULL && cache[1] != NULL); diff --git a/net/disk_cache/disk_cache.h b/net/disk_cache/disk_cache.h index 59efe06..18dd447 100644 --- a/net/disk_cache/disk_cache.h +++ b/net/disk_cache/disk_cache.h @@ -25,6 +25,7 @@ class MessageLoopProxy; namespace net { class IOBuffer; +class NetLog; } namespace disk_cache { @@ -50,7 +51,8 @@ typedef net::CompletionCallback CompletionCallback; // completes (the callback is notified). int CreateCacheBackend(net::CacheType type, const FilePath& path, int max_bytes, bool force, base::MessageLoopProxy* thread, - Backend** backend, CompletionCallback* callback); + net::NetLog* net_log, Backend** backend, + CompletionCallback* callback); // The root interface for a disk cache instance. class Backend { diff --git a/net/disk_cache/disk_cache_perftest.cc b/net/disk_cache/disk_cache_perftest.cc index 241fc04..14f15c6 100644 --- a/net/disk_cache/disk_cache_perftest.cc +++ b/net/disk_cache/disk_cache_perftest.cc @@ -169,7 +169,7 @@ TEST_F(DiskCacheTest, CacheBackendPerformance) { disk_cache::Backend* cache; int rv = disk_cache::CreateCacheBackend( net::DISK_CACHE, test_cache.path(), 0, false, - cache_thread.message_loop_proxy(), &cache, &cb); + cache_thread.message_loop_proxy(), NULL, &cache, &cb); ASSERT_EQ(net::OK, cb.GetResult(rv)); @@ -198,7 +198,7 @@ TEST_F(DiskCacheTest, CacheBackendPerformance) { rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, test_cache.path(), 0, false, cache_thread.message_loop_proxy(), - &cache, &cb); + NULL, &cache, &cb); ASSERT_EQ(net::OK, cb.GetResult(rv)); ret = TimeRead(num_entries, cache, entries, true); diff --git a/net/disk_cache/disk_cache_test_base.cc b/net/disk_cache/disk_cache_test_base.cc index cffe3fa..6c9b91c 100644 --- a/net/disk_cache/disk_cache_test_base.cc +++ b/net/disk_cache/disk_cache_test_base.cc @@ -75,7 +75,7 @@ void DiskCacheTestWithCache::InitDiskCache() { TestCompletionCallback cb; int rv = disk_cache::BackendImpl::CreateBackend( path, force_creation_, size_, type_, - disk_cache::kNoRandom, thread, &cache_, &cb); + disk_cache::kNoRandom, thread, NULL, &cache_, &cb); ASSERT_EQ(net::OK, cb.GetResult(rv)); } @@ -84,9 +84,9 @@ void DiskCacheTestWithCache::InitDiskCacheImpl(const FilePath& path) { use_current_thread_ ? base::MessageLoopProxy::CreateForCurrentThread() : cache_thread_.message_loop_proxy(); if (mask_) - cache_impl_ = new disk_cache::BackendImpl(path, mask_, thread); + cache_impl_ = new disk_cache::BackendImpl(path, mask_, thread, NULL); else - cache_impl_ = new disk_cache::BackendImpl(path, thread); + cache_impl_ = new disk_cache::BackendImpl(path, thread, NULL); cache_ = cache_impl_; ASSERT_TRUE(NULL != cache_); diff --git a/net/disk_cache/disk_cache_test_util.cc b/net/disk_cache/disk_cache_test_util.cc index 76690e6..ed16db0 100644 --- a/net/disk_cache/disk_cache_test_util.cc +++ b/net/disk_cache/disk_cache_test_util.cc @@ -94,7 +94,7 @@ bool CopyTestCache(const std::string& name) { bool CheckCacheIntegrity(const FilePath& path, bool new_eviction) { scoped_ptr<disk_cache::BackendImpl> cache(new disk_cache::BackendImpl( - path, base::MessageLoopProxy::CreateForCurrentThread())); + path, base::MessageLoopProxy::CreateForCurrentThread(), NULL)); if (!cache.get()) return false; if (new_eviction) diff --git a/net/disk_cache/entry_impl.cc b/net/disk_cache/entry_impl.cc index e5e6482..3cb895f 100644 --- a/net/disk_cache/entry_impl.cc +++ b/net/disk_cache/entry_impl.cc @@ -7,6 +7,7 @@ #include "base/message_loop.h" #include "base/metrics/histogram.h" #include "base/string_util.h" +#include "base/values.h" #include "net/base/io_buffer.h" #include "net/base/net_errors.h" #include "net/disk_cache/backend_impl.h" @@ -24,14 +25,93 @@ namespace { // Index for the file used to store the key, if any (files_[kKeyFileIndex]). const int kKeyFileIndex = 3; +// NetLog parameters for the creation of an EntryImpl. Contains an entry's name +// and whether it was created or opened. +class EntryCreationParameters : public net::NetLog::EventParameters { + public: + EntryCreationParameters(const std::string& key, bool created) + : key_(key), created_(created) { + } + + Value* ToValue() const { + DictionaryValue* dict = new DictionaryValue(); + dict->SetString("key", key_); + dict->SetBoolean("created", created_); + return dict; + } + + private: + const std::string key_; + const bool created_; + + DISALLOW_COPY_AND_ASSIGN(EntryCreationParameters); +}; + +// NetLog parameters for non-sparse reading and writing to an EntryImpl. +class ReadWriteDataParams : public net::NetLog::EventParameters { + public: + // For reads, |truncate| must be false. + ReadWriteDataParams(int index, int offset, int buf_len, bool truncate) + : index_(index), offset_(offset), buf_len_(buf_len), truncate_(truncate) { + } + + Value* ToValue() const { + DictionaryValue* dict = new DictionaryValue(); + dict->SetInteger("index", index_); + dict->SetInteger("offset", offset_); + dict->SetInteger("buf_len", buf_len_); + if (truncate_) + dict->SetBoolean("truncate", truncate_); + return dict; + } + + private: + const int index_; + const int offset_; + const int buf_len_; + const bool truncate_; + + DISALLOW_COPY_AND_ASSIGN(ReadWriteDataParams); +}; + +// NetLog parameters logged when non-sparse reads and writes complete. +class FileIOCompleteParameters : public net::NetLog::EventParameters { + public: + // |bytes_copied| is either the number of bytes copied or a network error + // code. |bytes_copied| must not be ERR_IO_PENDING, as it's not a valid + // result for an operation. + explicit FileIOCompleteParameters(int bytes_copied) + : bytes_copied_(bytes_copied) { + } + + Value* ToValue() const { + DCHECK_NE(bytes_copied_, net::ERR_IO_PENDING); + DictionaryValue* dict = new DictionaryValue(); + if (bytes_copied_ < 0) { + dict->SetInteger("net_error", bytes_copied_); + } else { + dict->SetInteger("bytes_copied", bytes_copied_); + } + return dict; + } + + private: + const int bytes_copied_; + + DISALLOW_COPY_AND_ASSIGN(FileIOCompleteParameters); +}; + // This class implements FileIOCallback to buffer the callback from a file IO // operation from the actual net class. class SyncCallback: public disk_cache::FileIOCallback { public: + // |end_event_type| is the event type to log on completion. Logs nothing on + // discard, or when the NetLog is not set to log all events. SyncCallback(disk_cache::EntryImpl* entry, net::IOBuffer* buffer, - net::CompletionCallback* callback ) + net::CompletionCallback* callback, + net::NetLog::EventType end_event_type) : entry_(entry), callback_(callback), buf_(buffer), - start_(TimeTicks::Now()) { + start_(TimeTicks::Now()), end_event_type_(end_event_type) { entry->AddRef(); entry->IncrementIoCount(); } @@ -39,11 +119,13 @@ class SyncCallback: public disk_cache::FileIOCallback { virtual void OnFileIOComplete(int bytes_copied); void Discard(); + private: disk_cache::EntryImpl* entry_; net::CompletionCallback* callback_; scoped_refptr<net::IOBuffer> buf_; TimeTicks start_; + net::NetLog::EventType end_event_type_; DISALLOW_COPY_AND_ASSIGN(SyncCallback); }; @@ -51,6 +133,11 @@ class SyncCallback: public disk_cache::FileIOCallback { void SyncCallback::OnFileIOComplete(int bytes_copied) { entry_->DecrementIoCount(); if (callback_) { + if (entry_->net_log().IsLoggingAllEvents()) { + entry_->net_log().EndEvent( + end_event_type_, + make_scoped_refptr(new FileIOCompleteParameters(bytes_copied))); + } entry_->ReportIOTime(disk_cache::EntryImpl::kAsyncIO, start_); callback_->Run(bytes_copied); } @@ -308,6 +395,7 @@ EntryImpl::~EntryImpl() { if (doomed_) { DeleteEntryData(true); } else { + net_log_.AddEvent(net::NetLog::TYPE_DISK_CACHE_CLOSE, NULL); bool ret = true; for (int index = 0; index < kNumStreams; index++) { if (user_buffers_[index].get()) { @@ -333,6 +421,7 @@ EntryImpl::~EntryImpl() { } Trace("~EntryImpl out 0x%p", reinterpret_cast<void*>(this)); + net_log_.EndEvent(net::NetLog::TYPE_DISK_CACHE_ENTRY, NULL); backend_->OnEntryDestroyEnd(); } @@ -487,6 +576,46 @@ void EntryImpl::DoomImpl() { int EntryImpl::ReadDataImpl(int index, int offset, net::IOBuffer* buf, int buf_len, CompletionCallback* callback) { + if (net_log_.IsLoggingAllEvents()) { + net_log_.BeginEvent( + net::NetLog::TYPE_DISK_CACHE_READ_DATA, + make_scoped_refptr( + new ReadWriteDataParams(index, offset, buf_len, false))); + } + + int result = InternalReadData(index, offset, buf, buf_len, callback); + + if (result != net::ERR_IO_PENDING && net_log_.IsLoggingAllEvents()) { + net_log_.EndEvent( + net::NetLog::TYPE_DISK_CACHE_READ_DATA, + make_scoped_refptr(new FileIOCompleteParameters(result))); + } + return result; +} + +int EntryImpl::WriteDataImpl(int index, int offset, net::IOBuffer* buf, + int buf_len, CompletionCallback* callback, + bool truncate) { + if (net_log_.IsLoggingAllEvents()) { + net_log_.BeginEvent( + net::NetLog::TYPE_DISK_CACHE_WRITE_DATA, + make_scoped_refptr( + new ReadWriteDataParams(index, offset, buf_len, truncate))); + } + + int result = InternalWriteData(index, offset, buf, buf_len, callback, + truncate); + + if (result != net::ERR_IO_PENDING && net_log_.IsLoggingAllEvents()) { + net_log_.EndEvent( + net::NetLog::TYPE_DISK_CACHE_WRITE_DATA, + make_scoped_refptr(new FileIOCompleteParameters(result))); + } + return result; +} + +int EntryImpl::InternalReadData(int index, int offset, net::IOBuffer* buf, + int buf_len, CompletionCallback* callback) { DCHECK(node_.Data()->dirty || read_only_); DVLOG(2) << "Read from " << index << " at " << offset << " : " << buf_len; if (index < 0 || index >= kNumStreams) @@ -536,8 +665,10 @@ int EntryImpl::ReadDataImpl(int index, int offset, net::IOBuffer* buf, } SyncCallback* io_callback = NULL; - if (callback) - io_callback = new SyncCallback(this, buf, callback); + if (callback) { + io_callback = new SyncCallback(this, buf, callback, + net::NetLog::TYPE_DISK_CACHE_READ_DATA); + } bool completed; if (!file->Read(buf->data(), buf_len, file_offset, io_callback, &completed)) { @@ -553,9 +684,9 @@ int EntryImpl::ReadDataImpl(int index, int offset, net::IOBuffer* buf, return (completed || !callback) ? buf_len : net::ERR_IO_PENDING; } -int EntryImpl::WriteDataImpl(int index, int offset, net::IOBuffer* buf, - int buf_len, CompletionCallback* callback, - bool truncate) { +int EntryImpl::InternalWriteData(int index, int offset, net::IOBuffer* buf, + int buf_len, CompletionCallback* callback, + bool truncate) { DCHECK(node_.Data()->dirty || read_only_); DVLOG(2) << "Write to " << index << " at " << offset << " : " << buf_len; if (index < 0 || index >= kNumStreams) @@ -628,8 +759,10 @@ int EntryImpl::WriteDataImpl(int index, int offset, net::IOBuffer* buf, return 0; SyncCallback* io_callback = NULL; - if (callback) - io_callback = new SyncCallback(this, buf, callback); + if (callback) { + io_callback = new SyncCallback(this, buf, callback, + net::NetLog::TYPE_DISK_CACHE_WRITE_DATA); + } bool completed; if (!file->Write(buf->data(), buf_len, file_offset, io_callback, @@ -757,6 +890,7 @@ bool EntryImpl::IsSameEntry(const std::string& key, uint32 hash) { } void EntryImpl::InternalDoom() { + net_log_.AddEvent(net::NetLog::TYPE_DISK_CACHE_DOOM, NULL); DCHECK(node_.HasData()); if (!node_.Data()->dirty) { node_.Data()->dirty = backend_->GetCurrentEntryId(); @@ -914,6 +1048,19 @@ void EntryImpl::ReportIOTime(Operation op, const base::TimeTicks& start) { } } +void EntryImpl::BeginLogging(net::NetLog* net_log, bool created) { + DCHECK(!net_log_.net_log()); + net_log_ = net::BoundNetLog::Make( + net_log, net::NetLog::SOURCE_DISK_CACHE_ENTRY); + net_log_.BeginEvent( + net::NetLog::TYPE_DISK_CACHE_ENTRY, + make_scoped_refptr(new EntryCreationParameters(GetKey(), created))); +} + +const net::BoundNetLog& EntryImpl::net_log() const { + return net_log_; +} + // ------------------------------------------------------------------------ bool EntryImpl::CreateDataBlock(int index, int size) { diff --git a/net/disk_cache/entry_impl.h b/net/disk_cache/entry_impl.h index e27f23a..d24e861 100644 --- a/net/disk_cache/entry_impl.h +++ b/net/disk_cache/entry_impl.h @@ -7,6 +7,7 @@ #pragma once #include "base/scoped_ptr.h" +#include "net/base/net_log.h" #include "net/disk_cache/disk_cache.h" #include "net/disk_cache/storage_block.h" #include "net/disk_cache/storage_block-inl.h" @@ -129,6 +130,14 @@ class EntryImpl : public Entry, public base::RefCounted<EntryImpl> { // Generates a histogram for the time spent working on this operation. void ReportIOTime(Operation op, const base::TimeTicks& start); + // Logs a begin event and enables logging for the EntryImpl. Will also cause + // an end event to be logged on destruction. The EntryImpl must have its key + // initialized before this is called. |created| is true if the Entry was + // created rather than opened. + void BeginLogging(net::NetLog* net_log, bool created); + + const net::BoundNetLog& net_log() const; + private: enum { kNumStreams = 3 @@ -137,6 +146,13 @@ class EntryImpl : public Entry, public base::RefCounted<EntryImpl> { ~EntryImpl(); + // Do all the work for ReadDataImpl and WriteDataImpl. Implemented as + // separate functions to make logging of results simpler. + int InternalReadData(int index, int offset, net::IOBuffer* buf, + int buf_len, CompletionCallback* callback); + int InternalWriteData(int index, int offset, net::IOBuffer* buf, int buf_len, + CompletionCallback* callback, bool truncate); + // Initializes the storage for an internal or external data block. bool CreateDataBlock(int index, int size); @@ -220,6 +236,8 @@ class EntryImpl : public Entry, public base::RefCounted<EntryImpl> { bool read_only_; // True if not yet writing. scoped_ptr<SparseControl> sparse_; // Support for sparse entries. + net::BoundNetLog net_log_; + DISALLOW_COPY_AND_ASSIGN(EntryImpl); }; diff --git a/net/disk_cache/sparse_control.cc b/net/disk_cache/sparse_control.cc index 32f44ab..c200b82 100644 --- a/net/disk_cache/sparse_control.cc +++ b/net/disk_cache/sparse_control.cc @@ -138,6 +138,29 @@ void ChildrenDeleter::DeleteChildren() { this, &ChildrenDeleter::DeleteChildren)); } +// Logs the end event for |operation|, if all events are being logged. +void LogOperationEnd(const net::BoundNetLog& net_log, + disk_cache::SparseControl::SparseOperation operation, + int result) { + if (net_log.IsLoggingAllEvents()) { + net::NetLog::EventType event_type; + switch (operation) { + case disk_cache::SparseControl::kReadOperation: + event_type = net::NetLog::TYPE_SPARSE_CONTROL_READ; + break; + case disk_cache::SparseControl::kWriteOperation: + event_type = net::NetLog::TYPE_SPARSE_CONTROL_WRITE; + break; + case disk_cache::SparseControl::kGetRangeOperation: + event_type = net::NetLog::TYPE_SPARSE_CONTROL_GET_RANGE; + break; + default: + NOTREACHED(); + } + net_log.EndEventWithNetErrorCode(event_type, result); + } +} + } // namespace. namespace disk_cache { @@ -223,6 +246,7 @@ int SparseControl::StartIO(SparseOperation op, int64 offset, net::IOBuffer* buf, finished_ = false; abort_ = false; + entry_->net_log().BeginEvent(net::NetLog::TYPE_SPARSE_CONTROL, NULL); DoChildrenIO(); if (!pending_) { @@ -610,8 +634,11 @@ void SparseControl::InitChildData() { void SparseControl::DoChildrenIO() { while (DoChildIO()) continue; - if (pending_ && finished_) - DoUserCallback(); + if (finished_) { + entry_->net_log().EndEvent(net::NetLog::TYPE_SPARSE_CONTROL, NULL); + if (pending_) + DoUserCallback(); + } } bool SparseControl::DoChildIO() { @@ -632,14 +659,32 @@ bool SparseControl::DoChildIO() { int rv = 0; switch (operation_) { case kReadOperation: + if (entry_->net_log().IsLoggingAllEvents()) { + entry_->net_log().BeginEvent( + net::NetLog::TYPE_SPARSE_CONTROL_READ, + make_scoped_refptr(new net::NetLogSourceParameter( + "source_dependency", + child_->net_log().source()))); + } rv = child_->ReadDataImpl(kSparseData, child_offset_, user_buf_, child_len_, callback); break; case kWriteOperation: + if (entry_->net_log().IsLoggingAllEvents()) { + entry_->net_log().BeginEvent( + net::NetLog::TYPE_SPARSE_CONTROL_WRITE, + make_scoped_refptr(new net::NetLogSourceParameter( + "source_dependency", + child_->net_log().source()))); + } rv = child_->WriteDataImpl(kSparseData, child_offset_, user_buf_, child_len_, callback, false); break; case kGetRangeOperation: + if (entry_->net_log().IsLoggingAllEvents()) { + entry_->net_log().BeginEvent(net::NetLog::TYPE_SPARSE_CONTROL_GET_RANGE, + NULL); + } rv = DoGetAvailableRange(); break; default: @@ -712,6 +757,7 @@ int SparseControl::DoGetAvailableRange() { } void SparseControl::DoChildIOCompleted(int result) { + LogOperationEnd(entry_->net_log(), operation_, result); if (result < 0) { // We fail the whole operation if we encounter an error. result_ = result; @@ -737,6 +783,8 @@ void SparseControl::OnChildIOCompleted(int result) { // We'll return the current result of the operation, which may be less than // the bytes to read or write, but the user cancelled the operation. abort_ = false; + entry_->net_log().AddEvent(net::NetLog::TYPE_CANCELLED, NULL); + entry_->net_log().EndEvent(net::NetLog::TYPE_SPARSE_CONTROL, NULL); DoUserCallback(); return DoAbortCallbacks(); } diff --git a/net/disk_cache/stress_cache.cc b/net/disk_cache/stress_cache.cc index 41a98c9..ee2db24 100644 --- a/net/disk_cache/stress_cache.cc +++ b/net/disk_cache/stress_cache.cc @@ -104,7 +104,7 @@ void StressTheCache(int iteration) { int rv = disk_cache::BackendImpl::CreateBackend( path, false, cache_size, net::DISK_CACHE, disk_cache::kNoLoadProtection | disk_cache::kNoRandom, - cache_thread.message_loop_proxy(), &cache, &cb); + cache_thread.message_loop_proxy(), NULL, &cache, &cb); if (cb.GetResult(rv) != net::OK) { printf("Unable to initialize cache.\n"); |