diff options
author | mmenke@chromium.org <mmenke@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-17 18:53:02 +0000 |
---|---|---|
committer | mmenke@chromium.org <mmenke@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-17 18:53:02 +0000 |
commit | 9eb8cdff6c4e93d2609ee9a12cbd6b3dfa8b7d7f (patch) | |
tree | a3024687f2041d1f464aeb073d289c1bb7daae74 /net | |
parent | d767b2c624529faef3bf78230f8873e91b244868 (diff) | |
download | chromium_src-9eb8cdff6c4e93d2609ee9a12cbd6b3dfa8b7d7f.zip chromium_src-9eb8cdff6c4e93d2609ee9a12cbd6b3dfa8b7d7f.tar.gz chromium_src-9eb8cdff6c4e93d2609ee9a12cbd6b3dfa8b7d7f.tar.bz2 |
Adds memory cache logging, and updates disk cache logging.
Memory and disk cache use the same set of events, with the same parameters (Though the disk cache has a couple events the memory cache does not). Most disk cache events were renamed so as to no longer imply a connection to the disk cache, and all disk cache-related NetLog parameter class definitions were moved to a new file, since they're shared by both entry type.
BUG=59382
TEST=none
Review URL: http://codereview.chromium.org/6613027
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@78572 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r-- | net/base/net_log_event_type_list.h | 234 | ||||
-rw-r--r-- | net/base/net_log_source_type_list.h | 5 | ||||
-rw-r--r-- | net/disk_cache/backend_impl.cc | 2 | ||||
-rw-r--r-- | net/disk_cache/backend_unittest.cc | 2 | ||||
-rw-r--r-- | net/disk_cache/disk_cache_test_base.cc | 4 | ||||
-rw-r--r-- | net/disk_cache/entry_impl.cc | 111 | ||||
-rw-r--r-- | net/disk_cache/mem_backend_impl.cc | 9 | ||||
-rw-r--r-- | net/disk_cache/mem_backend_impl.h | 10 | ||||
-rw-r--r-- | net/disk_cache/mem_entry_impl.cc | 196 | ||||
-rw-r--r-- | net/disk_cache/mem_entry_impl.h | 23 | ||||
-rw-r--r-- | net/disk_cache/net_log_parameters.cc | 100 | ||||
-rw-r--r-- | net/disk_cache/net_log_parameters.h | 99 | ||||
-rw-r--r-- | net/disk_cache/sparse_control.cc | 85 | ||||
-rw-r--r-- | net/net.gyp | 2 |
14 files changed, 613 insertions, 269 deletions
diff --git a/net/base/net_log_event_type_list.h b/net/base/net_log_event_type_list.h index fa96247..3febe64 100644 --- a/net/base/net_log_event_type_list.h +++ b/net/base/net_log_event_type_list.h @@ -25,7 +25,7 @@ EVENT_TYPE(REQUEST_ALIVE) // The BEGIN phase contains the following parameters: // // { -// "source_dependency": <Source id of the request being waited on> +// "source_dependency": <Source id of the request being waited on>, // } EVENT_TYPE(HOST_RESOLVER_IMPL) @@ -36,8 +36,8 @@ EVENT_TYPE(HOST_RESOLVER_IMPL) // The BEGIN phase contains the following parameters: // // { -// "host": <Hostname associated with the request> -// "source_dependency": <Source id, if any, of what created the request> +// "host": <Hostname associated with the request>, +// "source_dependency": <Source id, if any, of what created the request>, // } // // If an error occurred, the END phase will contain these parameters: @@ -57,7 +57,7 @@ EVENT_TYPE(HOST_RESOLVER_IMPL_CACHE_HIT) // The BEGIN phase contains the following parameters: // // { -// "priority": <Priority of the queued request> +// "priority": <Priority of the queued request>, // } EVENT_TYPE(HOST_RESOLVER_IMPL_JOB_POOL_QUEUE) @@ -79,7 +79,7 @@ EVENT_TYPE(HOST_RESOLVER_IMPL_CREATE_JOB) // phase contains the following parameters: // // { -// "source_dependency": <Source identifier for the attached Job> +// "source_dependency": <Source identifier for the attached Job>, // } EVENT_TYPE(HOST_RESOLVER_IMPL_JOB_ATTACH) @@ -87,8 +87,8 @@ EVENT_TYPE(HOST_RESOLVER_IMPL_JOB_ATTACH) // The BEGIN phase contains the following parameters: // // { -// "host": <Hostname associated with the request> -// "source_dependency": <Source id, if any, of what created the request> +// "host": <Hostname associated with the request>, +// "source_dependency": <Source id, if any, of what created the request>, // } // // On success, the END phase has these parameters: @@ -119,12 +119,12 @@ EVENT_TYPE(INIT_PROXY_RESOLVER_WAIT) // // The START event has the parameters: // { -// "url": <URL string of script being fetched> +// "url": <URL string of script being fetched>, // } // // If the fetch failed, then the END phase has these parameters: // { -// "error_code": <Net error code integer> +// "error_code": <Net error code integer>, // } EVENT_TYPE(INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT) @@ -133,7 +133,7 @@ EVENT_TYPE(INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT) // // If the parsing of the script failed, the END phase will have parameters: // { -// "error_code": <Net error code integer> +// "error_code": <Net error code integer>, // } EVENT_TYPE(INIT_PROXY_RESOLVER_SET_PAC_SCRIPT) @@ -160,12 +160,12 @@ EVENT_TYPE(PROXY_SERVICE_WAITING_FOR_INIT_PAC) // This event is emitted to show what the PAC script returned. It can contain // extra parameters that are either: // { -// "pac_string": <List of valid proxy servers, in PAC format> +// "pac_string": <List of valid proxy servers, in PAC format>, // } // // Or if the the resolver failed: // { -// "net_error": <Net error code that resolver failed with> +// "net_error": <Net error code that resolver failed with>, // } EVENT_TYPE(PROXY_SERVICE_RESOLVED_PROXY_LIST) @@ -175,7 +175,7 @@ EVENT_TYPE(PROXY_SERVICE_RESOLVED_PROXY_LIST) // It contains these parameters: // { // "old_config": <Dump of the previous proxy settings>, -// "new_config": <Dump of the new proxy settings> +// "new_config": <Dump of the new proxy settings>, // } // // Note that the "old_config" key will be omitted on the first fetch of the @@ -203,14 +203,14 @@ EVENT_TYPE(PAC_JAVASCRIPT_DNS_RESOLVE_EX) // { // "line_number": <The line number in the PAC script // (or -1 if not applicable)>, -// "message": <The error message> +// "message": <The error message>, // } EVENT_TYPE(PAC_JAVASCRIPT_ERROR) // This event is emitted when a PAC script called alert(). It contains the // following event parameters: // { -// "message": <The string of the alert> +// "message": <The string of the alert>, // } EVENT_TYPE(PAC_JAVASCRIPT_ALERT) @@ -223,7 +223,7 @@ EVENT_TYPE(WAITING_FOR_PROXY_RESOLVER_THREAD) // // { // "thread_number": <Identifier for the PAC thread that is going to -// run this request> +// run this request>, // } EVENT_TYPE(SUBMITTED_TO_RESOLVER_THREAD) @@ -237,13 +237,13 @@ EVENT_TYPE(SUBMITTED_TO_RESOLVER_THREAD) // The START event contains these parameters: // // { -// "address_list": <List of network address strings> +// "address_list": <List of network address strings>, // } // // And the END event will contain the following parameters on failure: // // { -// "net_error": <Net integer error code> +// "net_error": <Net integer error code>, // } EVENT_TYPE(TCP_CONNECT) @@ -252,13 +252,13 @@ EVENT_TYPE(TCP_CONNECT) // address the attempt is for: // // { -// "address": <String of the network address> +// "address": <String of the network address>, // } // // And the END event will contain the system error code if it failed: // // { -// "os_error": <Integer error code the operating system returned> +// "os_error": <Integer error code the operating system returned>, // } EVENT_TYPE(TCP_CONNECT_ATTEMPT) @@ -271,7 +271,7 @@ EVENT_TYPE(SOCKET_ALIVE) // The BEGIN phase contains the following parameters: // // { -// "source_dependency": <Source identifier for the controlling entity> +// "source_dependency": <Source identifier for the controlling entity>, // } EVENT_TYPE(SOCKET_IN_USE) @@ -294,7 +294,7 @@ EVENT_TYPE(SOCKS_UNEXPECTEDLY_CLOSED_DURING_HANDSHAKE) // This event indicates that a bad version number was received in the // proxy server's response. The extra parameters show its value: // { -// "version": <Integer version number in the response> +// "version": <Integer version number in the response>, // } EVENT_TYPE(SOCKS_UNEXPECTED_VERSION) @@ -302,7 +302,7 @@ EVENT_TYPE(SOCKS_UNEXPECTED_VERSION) // trying to create a connection. The following parameters will be attached // to the event: // { -// "error_code": <Integer error code returned by the server> +// "error_code": <Integer error code returned by the server>, // } EVENT_TYPE(SOCKS_SERVER_ERROR) @@ -310,7 +310,7 @@ EVENT_TYPE(SOCKS_SERVER_ERROR) // method that we don't support. The following parameters are attached to the // event: // { -// "method": <Integer method code> +// "method": <Integer method code>, // } EVENT_TYPE(SOCKS_UNEXPECTED_AUTH) @@ -318,7 +318,7 @@ EVENT_TYPE(SOCKS_UNEXPECTED_AUTH) // address type which we are not prepared to handle. // The following parameters are attached to the event: // { -// "address_type": <Integer code for the address type> +// "address_type": <Integer code for the address type>, // } EVENT_TYPE(SOCKS_UNKNOWN_ADDRESS_TYPE) @@ -364,7 +364,7 @@ EVENT_TYPE(SSL_NSS_ERROR) // { // "byte_count": <Number of bytes that were just sent>, // "hex_encoded_bytes": <The exact bytes sent, as a hexadecimal string. -// Only present when byte logging is enabled> +// Only present when byte logging is enabled>, // } EVENT_TYPE(SOCKET_BYTES_SENT) @@ -373,7 +373,7 @@ EVENT_TYPE(SOCKET_BYTES_SENT) // { // "byte_count": <Number of bytes that were just received>, // "hex_encoded_bytes": <The exact bytes received, as a hexadecimal string. -// Only present when byte logging is enabled> +// Only present when byte logging is enabled>, // } EVENT_TYPE(SOCKET_BYTES_RECEIVED) @@ -389,7 +389,7 @@ EVENT_TYPE(SOCKET_POOL_CONNECT_JOB) // The BEGIN phase has these parameters: // // { -// "group_name": <The group name for the socket request.> +// "group_name": <The group name for the socket request.>, // } EVENT_TYPE(SOCKET_POOL_CONNECT_JOB_CONNECT) @@ -397,7 +397,7 @@ EVENT_TYPE(SOCKET_POOL_CONNECT_JOB_CONNECT) // association. The event parameters point to that socket: // // { -// "source_dependency": <The source identifier for the new socket.> +// "source_dependency": <The source identifier for the new socket.>, // } EVENT_TYPE(CONNECT_JOB_SET_SOCKET) @@ -420,21 +420,21 @@ EVENT_TYPE(SOCKET_POOL_STALLED_MAX_SOCKETS_PER_GROUP) // Indicates that we reused an existing socket. Attached to the event are // the parameters: // { -// "idle_ms": <The number of milliseconds the socket was sitting idle for> +// "idle_ms": <The number of milliseconds the socket was sitting idle for>, // } EVENT_TYPE(SOCKET_POOL_REUSED_AN_EXISTING_SOCKET) // This event simply describes the host:port that were requested from the // socket pool. Its parameters are: // { -// "host_and_port": <String encoding the host and port> +// "host_and_port": <String encoding the host and port>, // } EVENT_TYPE(TCP_CLIENT_SOCKET_POOL_REQUESTED_SOCKET) // This event simply describes the host:port that were requested from the // socket pool. Its parameters are: // { -// "host_and_port": <String encoding the host and port> +// "host_and_port": <String encoding the host and port>, // } EVENT_TYPE(TCP_CLIENT_SOCKET_POOL_REQUESTED_SOCKETS) @@ -449,21 +449,21 @@ EVENT_TYPE(SOCKET_BACKUP_CREATED) // The event parameters are: // { // "source_dependency": <Source identifer for the connect job we are -// bound to> +// bound to>, // } EVENT_TYPE(SOCKET_POOL_BOUND_TO_CONNECT_JOB) // Identifies the NetLog::Source() for the Socket assigned to the pending // request. The event parameters are: // { -// "source_dependency": <Source identifier for the socket we acquired> +// "source_dependency": <Source identifier for the socket we acquired>, // } EVENT_TYPE(SOCKET_POOL_BOUND_TO_SOCKET) // The start/end of a client socket pool request for multiple sockets. // The event parameters are: // { -// "num_sockets": <Number of sockets we're trying to ensure are connected> +// "num_sockets": <Number of sockets we're trying to ensure are connected>, // } EVENT_TYPE(SOCKET_POOL_CONNECTING_N_SOCKETS) @@ -480,20 +480,20 @@ EVENT_TYPE(SOCKET_POOL_CONNECTING_N_SOCKETS) // { // "url": <String of URL being loaded>, // "method": <The method ("POST" or "GET" or "HEAD" etc..)>, -// "load_flags": <Numeric value of the combined load flags> +// "load_flags": <Numeric value of the combined load flags>, // } // // For the END phase, if there was an error, the following parameters are // attached: // { -// "net_error": <Net error code of the failure> +// "net_error": <Net error code of the failure>, // } EVENT_TYPE(URL_REQUEST_START_JOB) // This event is sent once a net::URLRequest receives a redirect. The parameters // attached to the event are: // { -// "location": <The URL that was redirected to> +// "location": <The URL that was redirected to>, // } EVENT_TYPE(URL_REQUEST_REDIRECTED) @@ -531,59 +531,89 @@ EVENT_TYPE(HTTP_CACHE_READ_DATA) EVENT_TYPE(HTTP_CACHE_WRITE_DATA) // ------------------------------------------------------------------------ -// Disk Cache +// Disk Cache / Memory Cache // ------------------------------------------------------------------------ // The creation/destruction of a disk_cache::EntryImpl object. The "creation" // is considered to be the point at which an Entry is first considered to be -// good and associated with a key. +// good and associated with a key. Note that disk and memory cache entries +// share event types. // // For the BEGIN phase, the following parameters are attached: // { -// "created": <true if the Entry was created, rather than being opened>; -// "key": <The Entry's key>; +// "created": <true if the Entry was created, rather than being opened>, +// "key": <The Entry's key>, // } -EVENT_TYPE(DISK_CACHE_ENTRY) +EVENT_TYPE(DISK_CACHE_ENTRY_IMPL) +EVENT_TYPE(DISK_CACHE_MEM_ENTRY_IMPL) // Logs the time required to read/write data from/to a cache entry. // // For the BEGIN phase, the following parameters are attached: // { -// "index": <Index being read/written>; -// "offset": <Offset being read/written>; -// "buf_len": <Length of buffer being read to/written from>; +// "index": <Index being read/written>, +// "offset": <Offset being read/written>, +// "buf_len": <Length of buffer being read to/written from>, // "truncate": <If present for a write, the truncate flag is set to true. -// Not present in reads or writes where it is false> +// Not present in reads or writes where it is false>, // } // // For the END phase, the following parameters are attached: // { -// "bytes_copied": <Number of bytes copied. Not present on error>; -// "net_error": <Network error code. Only present on error>; +// "bytes_copied": <Number of bytes copied. Not present on error>, +// "net_error": <Network error code. Only present on error>, // } -EVENT_TYPE(DISK_CACHE_READ_DATA) -EVENT_TYPE(DISK_CACHE_WRITE_DATA) +EVENT_TYPE(ENTRY_READ_DATA) +EVENT_TYPE(ENTRY_WRITE_DATA) -// Logged when SparseControl starts/stops handling IO for an Entry. -EVENT_TYPE(SPARSE_CONTROL) +// Logged when sparse read/write operation starts/stops for an Entry. +// +// For the BEGIN phase, the following parameters are attached: +// { +// "offset": <Offset at which to start reading>, +// "buff_len": <Bytes to read/write>, +// } +EVENT_TYPE(SPARSE_READ) +EVENT_TYPE(SPARSE_WRITE) -// Logged when SparseControl starts/stops reading/writing a child Entry's data +// Logged when a parent Entry starts/stops reading/writing a child Entry's data. // // For the BEGIN phase, the following parameters are attached: // { -// "source_dependency": <Source id of the child entry> +// "source_dependency": <Source id of the child entry>, +// "child_len": <Bytes to read/write from/to child>, // } -EVENT_TYPE(SPARSE_CONTROL_READ) -EVENT_TYPE(SPARSE_CONTROL_WRITE) +EVENT_TYPE(SPARSE_READ_CHILD_DATA) +EVENT_TYPE(SPARSE_WRITE_CHILD_DATA) -// Indicates the time taken by a sparse control to get a range. -EVENT_TYPE(SPARSE_CONTROL_GET_RANGE) +// Logged when sparse GetAvailableRange operation starts/stops for an Entry. +// +// For the BEGIN phase, the following parameters are attached: +// { +// "buff_len": <Bytes to read/write>, +// "offset": <Offset at which to start reading>, +// } +// +// For the END phase, the following parameters are attached. No parameters are +// attached when cancelled: +// { +// "length": <Length of returned range. Only present on success>, +// "start": <Position where returned range starts. Only present on success>, +// "net_error": <Resulting error code. Only present on failure. This may be +// "OK" when there's no error, but no available bytes in the +// range>, +// } +EVENT_TYPE(SPARSE_GET_RANGE) -// Logged when an entry is closed. -EVENT_TYPE(DISK_CACHE_CLOSE) +// Indicates the children of a sparse EntryImpl are about to be deleted. +// Not logged for MemEntryImpls. +EVENT_TYPE(SPARSE_DELETE_CHILDREN) + +// Logged when an EntryImpl is closed. Not logged for MemEntryImpls. +EVENT_TYPE(ENTRY_CLOSE) // Logged when an entry is doomed. -EVENT_TYPE(DISK_CACHE_DOOM) +EVENT_TYPE(ENTRY_DOOM) // ------------------------------------------------------------------------ // HttpStreamFactoryImpl @@ -598,7 +628,7 @@ EVENT_TYPE(HTTP_STREAM_JOB) // Identifies the NetLog::Source() for the Job that fulfilled the request. // request. The event parameters are: // { -// "source_dependency": <Source identifier for the job we acquired> +// "source_dependency": <Source identifier for the job we acquired>, // } EVENT_TYPE(HTTP_STREAM_REQUEST_BOUND_TO_JOB) @@ -613,7 +643,7 @@ EVENT_TYPE(HTTP_TRANSACTION_TUNNEL_SEND_REQUEST) // The following parameters are attached: // { // "line": <The HTTP request line, CRLF terminated>, -// "headers": <The list of header:value pairs> +// "headers": <The list of header:value pairs>, // } EVENT_TYPE(HTTP_TRANSACTION_SEND_TUNNEL_HEADERS) @@ -624,7 +654,7 @@ EVENT_TYPE(HTTP_TRANSACTION_TUNNEL_READ_HEADERS) // request. // The following parameters are attached: // { -// "headers": <The list of header:value pairs> +// "headers": <The list of header:value pairs>, // } EVENT_TYPE(HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS) @@ -635,7 +665,7 @@ EVENT_TYPE(HTTP_TRANSACTION_SEND_REQUEST) // The following parameters are attached: // { // "line": <The HTTP request line, CRLF terminated>, -// "headers": <The list of header:value pairs> +// "headers": <The list of header:value pairs>, // } EVENT_TYPE(HTTP_TRANSACTION_SEND_REQUEST_HEADERS) @@ -645,7 +675,7 @@ EVENT_TYPE(HTTP_TRANSACTION_READ_HEADERS) // This event is sent on receipt of the HTTP response headers. // The following parameters are attached: // { -// "headers": <The list of header:value pairs> +// "headers": <The list of header:value pairs>, // } EVENT_TYPE(HTTP_TRANSACTION_READ_RESPONSE_HEADERS) @@ -672,7 +702,7 @@ EVENT_TYPE(SPDY_SESSION) // { // "flags": <The control frame flags>, // "headers": <The list of header:value pairs>, -// "id": <The stream id> +// "id": <The stream id>, // } EVENT_TYPE(SPDY_SESSION_SYN_STREAM) @@ -680,19 +710,19 @@ EVENT_TYPE(SPDY_SESSION_SYN_STREAM) // net::URLRequest is already waiting for the stream. // The following parameters are attached: // { -// "flags": <The control frame flags> -// "headers": <The list of header:value pairs> -// "id": <The stream id> -// "associated_stream": <The stream id> +// "flags": <The control frame flags>, +// "headers": <The list of header:value pairs>, +// "id": <The stream id>, +// "associated_stream": <The stream id>, // } EVENT_TYPE(SPDY_SESSION_PUSHED_SYN_STREAM) // This event is sent for a SPDY HEADERS frame. // The following parameters are attached: // { -// "flags": <The control frame flags> -// "headers": <The list of header:value pairs> -// "id": <The stream id> +// "flags": <The control frame flags>, +// "headers": <The list of header:value pairs>, +// "id": <The stream id>, // } EVENT_TYPE(SPDY_SESSION_HEADERS) @@ -701,78 +731,78 @@ EVENT_TYPE(SPDY_SESSION_HEADERS) // { // "flags": <The control frame flags>, // "headers": <The list of header:value pairs>, -// "id": <The stream id> +// "id": <The stream id>, // } EVENT_TYPE(SPDY_SESSION_SYN_REPLY) // On sending a SPDY SETTINGS frame. // The following parameters are attached: // { -// "settings": <The list of setting id:value pairs> +// "settings": <The list of setting id:value pairs>, // } EVENT_TYPE(SPDY_SESSION_SEND_SETTINGS) // Receipt of a SPDY SETTINGS frame. // The following parameters are attached: // { -// "settings": <The list of setting id:value pairs> +// "settings": <The list of setting id:value pairs>, // } EVENT_TYPE(SPDY_SESSION_RECV_SETTINGS) // The receipt of a RST_STREAM // The following parameters are attached: // { -// "stream_id": <The stream ID for the window update> -// "status": <The reason for the RST_STREAM> +// "stream_id": <The stream ID for the window update>, +// "status": <The reason for the RST_STREAM>, // } EVENT_TYPE(SPDY_SESSION_RST_STREAM) // Sending of a RST_STREAM // The following parameters are attached: // { -// "stream_id": <The stream ID for the window update> -// "status": <The reason for the RST_STREAM> +// "stream_id": <The stream ID for the window update>, +// "status": <The reason for the RST_STREAM>, // } EVENT_TYPE(SPDY_SESSION_SEND_RST_STREAM) // Receipt of a SPDY GOAWAY frame. // The following parameters are attached: // { -// "last_accepted_stream_id": <Last stream id accepted by the server, duh> -// "active_streams": <Number of active streams> -// "unclaimed_streams": <Number of unclaimed push streams> +// "last_accepted_stream_id": <Last stream id accepted by the server, duh>, +// "active_streams": <Number of active streams>, +// "unclaimed_streams": <Number of unclaimed push streams>, // } EVENT_TYPE(SPDY_SESSION_GOAWAY) // Receipt of a SPDY WINDOW_UPDATE frame (which controls the send window). // { -// "stream_id": <The stream ID for the window update> -// "delta" : <The delta window size> -// "new_size" : <The new window size (computed)> +// "stream_id": <The stream ID for the window update>, +// "delta" : <The delta window size>, +// "new_size" : <The new window size (computed)>, // } EVENT_TYPE(SPDY_SESSION_SEND_WINDOW_UPDATE) // Sending of a SPDY WINDOW_UPDATE frame (which controls the receive window). // { -// "stream_id": <The stream ID for the window update> -// "delta" : <The delta window size> -// "new_size" : <The new window size (computed)> +// "stream_id": <The stream ID for the window update>, +// "delta" : <The delta window size>, +// "new_size" : <The new window size (computed)>, // } EVENT_TYPE(SPDY_SESSION_RECV_WINDOW_UPDATE) // Sending a data frame // { -// "stream_id": <The stream ID for the window update> -// "length" : <The size of data sent> -// "flags" : <Send data flags> +// "stream_id": <The stream ID for the window update>, +// "length" : <The size of data sent>, +// "flags" : <Send data flags>, // } EVENT_TYPE(SPDY_SESSION_SEND_DATA) // Receiving a data frame // { -// "stream_id": <The stream ID for the window update> -// "length" : <The size of data sent> -// "flags" : <Send data flags> +// "stream_id": <The stream ID for the window update>, +// "length" : <The size of data sent>, +// "flags" : <Send data flags>, // } EVENT_TYPE(SPDY_SESSION_RECV_DATA) @@ -781,7 +811,7 @@ EVENT_TYPE(SPDY_SESSION_STALLED_ON_SEND_WINDOW) // Session is closing // { -// "status": <The error status of the closure> +// "status": <The error status of the closure>, // } EVENT_TYPE(SPDY_SESSION_CLOSE) @@ -859,13 +889,13 @@ EVENT_TYPE(HTTP_STREAM_PARSER_READ_HEADERS) // // For the BEGIN phase, the following parameters are attached: // { -// "url": <String of URL being loaded> +// "url": <String of URL being loaded>, // } // // For the END phase, if there was an error, the following parameters are // attached: // { -// "net_error": <Net error code of the failure> +// "net_error": <Net error code of the failure>, // } EVENT_TYPE(SOCKET_STREAM_CONNECT) @@ -882,14 +912,14 @@ EVENT_TYPE(SOCKET_STREAM_RECEIVED) // This event is sent for a WebSocket handshake request. // The following parameters are attached: // { -// "headers": <handshake request message> +// "headers": <handshake request message>, // } EVENT_TYPE(WEB_SOCKET_SEND_REQUEST_HEADERS) // This event is sent on receipt of the WebSocket handshake response headers. // The following parameters are attached: // { -// "headers": <handshake response message> +// "headers": <handshake response message>, // } EVENT_TYPE(WEB_SOCKET_READ_RESPONSE_HEADERS) diff --git a/net/base/net_log_source_type_list.h b/net/base/net_log_source_type_list.h index d25986c..d5fed96 100644 --- a/net/base/net_log_source_type_list.h +++ b/net/base/net_log_source_type_list.h @@ -16,6 +16,7 @@ SOURCE_TYPE(SPDY_SESSION, 6) SOURCE_TYPE(HOST_RESOLVER_IMPL_REQUEST, 7) SOURCE_TYPE(HOST_RESOLVER_IMPL_JOB, 8) SOURCE_TYPE(DISK_CACHE_ENTRY, 9) -SOURCE_TYPE(HTTP_STREAM_JOB, 10) +SOURCE_TYPE(MEMORY_CACHE_ENTRY, 10) +SOURCE_TYPE(HTTP_STREAM_JOB, 11) -SOURCE_TYPE(COUNT, 11) // Always keep this as the last entry. +SOURCE_TYPE(COUNT, 12) // Always keep this as the last entry. diff --git a/net/disk_cache/backend_impl.cc b/net/disk_cache/backend_impl.cc index cac4656..16e1a76 100644 --- a/net/disk_cache/backend_impl.cc +++ b/net/disk_cache/backend_impl.cc @@ -295,7 +295,7 @@ int CreateCacheBackend(net::CacheType type, const FilePath& path, int max_bytes, CompletionCallback* callback) { DCHECK(callback); if (type == net::MEMORY_CACHE) { - *backend = MemBackendImpl::CreateBackend(max_bytes); + *backend = MemBackendImpl::CreateBackend(max_bytes, net_log); return *backend ? net::OK : net::ERR_FAILED; } DCHECK(thread); diff --git a/net/disk_cache/backend_unittest.cc b/net/disk_cache/backend_unittest.cc index aab0ccb..185d29c 100644 --- a/net/disk_cache/backend_unittest.cc +++ b/net/disk_cache/backend_unittest.cc @@ -206,7 +206,7 @@ TEST_F(DiskCacheTest, CreateBackend) { ASSERT_TRUE(cache); delete cache; - cache = disk_cache::MemBackendImpl::CreateBackend(0); + cache = disk_cache::MemBackendImpl::CreateBackend(0, NULL); ASSERT_TRUE(cache); delete cache; cache = NULL; diff --git a/net/disk_cache/disk_cache_test_base.cc b/net/disk_cache/disk_cache_test_base.cc index 41d1caf..bbcb65d 100644 --- a/net/disk_cache/disk_cache_test_base.cc +++ b/net/disk_cache/disk_cache_test_base.cc @@ -221,11 +221,11 @@ void DiskCacheTestWithCache::TearDown() { void DiskCacheTestWithCache::InitMemoryCache() { if (!implementation_) { - cache_ = disk_cache::MemBackendImpl::CreateBackend(size_); + cache_ = disk_cache::MemBackendImpl::CreateBackend(size_, NULL); return; } - mem_cache_ = new disk_cache::MemBackendImpl(); + mem_cache_ = new disk_cache::MemBackendImpl(NULL); cache_ = mem_cache_; ASSERT_TRUE(NULL != cache_); diff --git a/net/disk_cache/entry_impl.cc b/net/disk_cache/entry_impl.cc index 085efd2..2db4988 100644 --- a/net/disk_cache/entry_impl.cc +++ b/net/disk_cache/entry_impl.cc @@ -7,13 +7,13 @@ #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" #include "net/disk_cache/bitmap.h" #include "net/disk_cache/cache_util.h" #include "net/disk_cache/histogram_macros.h" +#include "net/disk_cache/net_log_parameters.h" #include "net/disk_cache/sparse_control.h" using base::Time; @@ -25,82 +25,6 @@ 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 { @@ -125,7 +49,7 @@ class SyncCallback: public disk_cache::FileIOCallback { net::CompletionCallback* callback_; scoped_refptr<net::IOBuffer> buf_; TimeTicks start_; - net::NetLog::EventType end_event_type_; + const net::NetLog::EventType end_event_type_; DISALLOW_COPY_AND_ASSIGN(SyncCallback); }; @@ -136,7 +60,8 @@ void SyncCallback::OnFileIOComplete(int bytes_copied) { if (entry_->net_log().IsLoggingAllEvents()) { entry_->net_log().EndEvent( end_event_type_, - make_scoped_refptr(new FileIOCompleteParameters(bytes_copied))); + make_scoped_refptr( + new disk_cache::ReadWriteCompleteParameters(bytes_copied))); } entry_->ReportIOTime(disk_cache::EntryImpl::kAsyncIO, start_); callback_->Run(bytes_copied); @@ -386,17 +311,17 @@ 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, + net::NetLog::TYPE_ENTRY_READ_DATA, make_scoped_refptr( - new ReadWriteDataParams(index, offset, buf_len, false))); + new ReadWriteDataParameters(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))); + net::NetLog::TYPE_ENTRY_READ_DATA, + make_scoped_refptr(new ReadWriteCompleteParameters(result))); } return result; } @@ -406,9 +331,9 @@ int EntryImpl::WriteDataImpl(int index, int offset, net::IOBuffer* buf, bool truncate) { if (net_log_.IsLoggingAllEvents()) { net_log_.BeginEvent( - net::NetLog::TYPE_DISK_CACHE_WRITE_DATA, + net::NetLog::TYPE_ENTRY_WRITE_DATA, make_scoped_refptr( - new ReadWriteDataParams(index, offset, buf_len, truncate))); + new ReadWriteDataParameters(index, offset, buf_len, truncate))); } int result = InternalWriteData(index, offset, buf, buf_len, callback, @@ -416,8 +341,8 @@ int EntryImpl::WriteDataImpl(int index, int offset, net::IOBuffer* buf, 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))); + net::NetLog::TYPE_ENTRY_WRITE_DATA, + make_scoped_refptr(new ReadWriteCompleteParameters(result))); } return result; } @@ -531,7 +456,7 @@ bool EntryImpl::IsSameEntry(const std::string& key, uint32 hash) { } void EntryImpl::InternalDoom() { - net_log_.AddEvent(net::NetLog::TYPE_DISK_CACHE_DOOM, NULL); + net_log_.AddEvent(net::NetLog::TYPE_ENTRY_DOOM, NULL); DCHECK(node_.HasData()); if (!node_.Data()->dirty) { node_.Data()->dirty = backend_->GetCurrentEntryId(); @@ -692,7 +617,7 @@ void EntryImpl::BeginLogging(net::NetLog* net_log, bool created) { net_log_ = net::BoundNetLog::Make( net_log, net::NetLog::SOURCE_DISK_CACHE_ENTRY); net_log_.BeginEvent( - net::NetLog::TYPE_DISK_CACHE_ENTRY, + net::NetLog::TYPE_DISK_CACHE_ENTRY_IMPL, make_scoped_refptr(new EntryCreationParameters(GetKey(), created))); } @@ -859,7 +784,7 @@ EntryImpl::~EntryImpl() { if (doomed_) { DeleteEntryData(true); } else { - net_log_.AddEvent(net::NetLog::TYPE_DISK_CACHE_CLOSE, NULL); + net_log_.AddEvent(net::NetLog::TYPE_ENTRY_CLOSE, NULL); bool ret = true; for (int index = 0; index < kNumStreams; index++) { if (user_buffers_[index].get()) { @@ -885,7 +810,7 @@ EntryImpl::~EntryImpl() { } Trace("~EntryImpl out 0x%p", reinterpret_cast<void*>(this)); - net_log_.EndEvent(net::NetLog::TYPE_DISK_CACHE_ENTRY, NULL); + net_log_.EndEvent(net::NetLog::TYPE_DISK_CACHE_ENTRY_IMPL, NULL); backend_->OnEntryDestroyEnd(); } @@ -944,7 +869,7 @@ int EntryImpl::InternalReadData(int index, int offset, net::IOBuffer* buf, SyncCallback* io_callback = NULL; if (callback) { io_callback = new SyncCallback(this, buf, callback, - net::NetLog::TYPE_DISK_CACHE_READ_DATA); + net::NetLog::TYPE_ENTRY_READ_DATA); } bool completed; @@ -1038,7 +963,7 @@ int EntryImpl::InternalWriteData(int index, int offset, net::IOBuffer* buf, SyncCallback* io_callback = NULL; if (callback) { io_callback = new SyncCallback(this, buf, callback, - net::NetLog::TYPE_DISK_CACHE_WRITE_DATA); + net::NetLog::TYPE_ENTRY_WRITE_DATA); } bool completed; diff --git a/net/disk_cache/mem_backend_impl.cc b/net/disk_cache/mem_backend_impl.cc index 1122bca..c2f0438 100644 --- a/net/disk_cache/mem_backend_impl.cc +++ b/net/disk_cache/mem_backend_impl.cc @@ -28,7 +28,8 @@ int LowWaterAdjust(int high_water) { namespace disk_cache { -MemBackendImpl::MemBackendImpl() : max_size_(0), current_size_(0) {} +MemBackendImpl::MemBackendImpl(net::NetLog* net_log) + : max_size_(0), current_size_(0), net_log_(net_log) {} MemBackendImpl::~MemBackendImpl() { EntryMap::iterator it = entries_.begin(); @@ -40,8 +41,8 @@ MemBackendImpl::~MemBackendImpl() { } // Static. -Backend* MemBackendImpl::CreateBackend(int max_bytes) { - MemBackendImpl* cache = new MemBackendImpl(); +Backend* MemBackendImpl::CreateBackend(int max_bytes, net::NetLog* net_log) { + MemBackendImpl* cache = new MemBackendImpl(net_log); cache->SetMaxSize(max_bytes); if (cache->Init()) return cache; @@ -204,7 +205,7 @@ bool MemBackendImpl::CreateEntry(const std::string& key, Entry** entry) { return false; MemEntryImpl* cache_entry = new MemEntryImpl(this); - if (!cache_entry->CreateEntry(key)) { + if (!cache_entry->CreateEntry(key, net_log_)) { delete entry; return false; } diff --git a/net/disk_cache/mem_backend_impl.h b/net/disk_cache/mem_backend_impl.h index 9b920ac5..01f68d3 100644 --- a/net/disk_cache/mem_backend_impl.h +++ b/net/disk_cache/mem_backend_impl.h @@ -13,6 +13,10 @@ #include "net/disk_cache/disk_cache.h" #include "net/disk_cache/mem_rankings.h" +namespace net { +class NetLog; +} // namespace net + namespace disk_cache { class MemEntryImpl; @@ -21,7 +25,7 @@ class MemEntryImpl; // the operations of the cache without writing to disk. class MemBackendImpl : public Backend { public: - MemBackendImpl(); + explicit MemBackendImpl(net::NetLog* net_log); ~MemBackendImpl(); // Returns an instance of a Backend implemented only in memory. The returned @@ -29,7 +33,7 @@ class MemBackendImpl : public Backend { // size the cache can grow to. If zero is passed in as max_bytes, the cache // will determine the value to use based on the available memory. The returned // pointer can be NULL if a fatal error is found. - static Backend* CreateBackend(int max_bytes); + static Backend* CreateBackend(int max_bytes, net::NetLog* net_log); // Performs general initialization for this current instance of the cache. bool Init(); @@ -104,6 +108,8 @@ class MemBackendImpl : public Backend { int32 max_size_; // Maximum data size for this instance. int32 current_size_; + net::NetLog* net_log_; + DISALLOW_COPY_AND_ASSIGN(MemBackendImpl); }; diff --git a/net/disk_cache/mem_entry_impl.cc b/net/disk_cache/mem_entry_impl.cc index 2b37f36..9df7306 100644 --- a/net/disk_cache/mem_entry_impl.cc +++ b/net/disk_cache/mem_entry_impl.cc @@ -5,9 +5,11 @@ #include "net/disk_cache/mem_entry_impl.h" #include "base/logging.h" +#include "base/stringprintf.h" #include "net/base/io_buffer.h" #include "net/base/net_errors.h" #include "net/disk_cache/mem_backend_impl.h" +#include "net/disk_cache/net_log_parameters.h" using base::Time; @@ -31,7 +33,15 @@ inline int ToChildOffset(int64 offset) { return static_cast<int>(offset & (kMaxSparseEntrySize - 1)); } -} // nemespace +// Returns a name for a child entry given the base_name of the parent and the +// child_id. This name is only used for logging purposes. +// If the entry is called entry_name, child entries will be named something +// like Range_entry_name:YYY where YYY is the number of the particular child. +std::string GenerateChildName(const std::string& base_name, int child_id) { + return base::StringPrintf("Range_%s:%i", base_name.c_str(), child_id); +} + +} // namespace namespace disk_cache { @@ -50,7 +60,12 @@ MemEntryImpl::MemEntryImpl(MemBackendImpl* backend) { // ------------------------------------------------------------------------ -bool MemEntryImpl::CreateEntry(const std::string& key) { +bool MemEntryImpl::CreateEntry(const std::string& key, net::NetLog* net_log) { + net_log_ = net::BoundNetLog::Make(net_log, + net::NetLog::SOURCE_MEMORY_CACHE_ENTRY); + net_log_.BeginEvent( + net::NetLog::TYPE_DISK_CACHE_MEM_ENTRY_IMPL, + make_scoped_refptr(new EntryCreationParameters(key, true))); key_ = key; Time current = Time::Now(); last_modified_ = current; @@ -61,6 +76,7 @@ bool MemEntryImpl::CreateEntry(const std::string& key) { } void MemEntryImpl::InternalDoom() { + net_log_.AddEvent(net::NetLog::TYPE_ENTRY_DOOM, NULL); doomed_ = true; if (!ref_count_) { if (type() == kParentEntry) { @@ -152,6 +168,108 @@ int32 MemEntryImpl::GetDataSize(int index) const { int MemEntryImpl::ReadData(int index, int offset, net::IOBuffer* buf, int buf_len, net::CompletionCallback* completion_callback) { + if (net_log_.IsLoggingAllEvents()) { + net_log_.BeginEvent( + net::NetLog::TYPE_ENTRY_READ_DATA, + make_scoped_refptr( + new ReadWriteDataParameters(index, offset, buf_len, false))); + } + + int result = InternalReadData(index, offset, buf, buf_len); + + if (net_log_.IsLoggingAllEvents()) { + net_log_.EndEvent( + net::NetLog::TYPE_ENTRY_READ_DATA, + make_scoped_refptr(new ReadWriteCompleteParameters(result))); + } + return result; +} + +int MemEntryImpl::WriteData(int index, int offset, net::IOBuffer* buf, + int buf_len, net::CompletionCallback* completion_callback, bool truncate) { + if (net_log_.IsLoggingAllEvents()) { + net_log_.BeginEvent( + net::NetLog::TYPE_ENTRY_WRITE_DATA, + make_scoped_refptr( + new ReadWriteDataParameters(index, offset, buf_len, truncate))); + } + + int result = InternalWriteData(index, offset, buf, buf_len, truncate); + + if (net_log_.IsLoggingAllEvents()) { + net_log_.EndEvent( + net::NetLog::TYPE_ENTRY_WRITE_DATA, + make_scoped_refptr(new ReadWriteCompleteParameters(result))); + } + return result; +} + +int MemEntryImpl::ReadSparseData(int64 offset, net::IOBuffer* buf, int buf_len, + net::CompletionCallback* completion_callback) { + if (net_log_.IsLoggingAllEvents()) { + net_log_.BeginEvent( + net::NetLog::TYPE_SPARSE_READ, + make_scoped_refptr( + new SparseOperationParameters(offset, buf_len))); + } + int result = InternalReadSparseData(offset, buf, buf_len); + if (net_log_.IsLoggingAllEvents()) + net_log_.EndEvent(net::NetLog::TYPE_SPARSE_READ, NULL); + return result; +} + +int MemEntryImpl::WriteSparseData(int64 offset, net::IOBuffer* buf, int buf_len, + net::CompletionCallback* completion_callback) { + if (net_log_.IsLoggingAllEvents()) { + net_log_.BeginEvent(net::NetLog::TYPE_SPARSE_WRITE, + make_scoped_refptr( + new SparseOperationParameters(offset, buf_len))); + } + int result = InternalWriteSparseData(offset, buf, buf_len); + if (net_log_.IsLoggingAllEvents()) + net_log_.EndEvent(net::NetLog::TYPE_SPARSE_WRITE, NULL); + return result; +} + +int MemEntryImpl::GetAvailableRange(int64 offset, int len, int64* start, + CompletionCallback* callback) { + if (net_log_.IsLoggingAllEvents()) { + net_log_.BeginEvent( + net::NetLog::TYPE_SPARSE_GET_RANGE, + make_scoped_refptr( + new SparseOperationParameters(offset, len))); + } + int result = GetAvailableRange(offset, len, start); + if (net_log_.IsLoggingAllEvents()) { + net_log_.EndEvent( + net::NetLog::TYPE_SPARSE_GET_RANGE, + make_scoped_refptr( + new GetAvailableRangeResultParameters(*start, result))); + } + return result; +} + +bool MemEntryImpl::CouldBeSparse() const { + DCHECK_EQ(kParentEntry, type()); + return (children_.get() != NULL); +} + +int MemEntryImpl::ReadyForSparseIO( + net::CompletionCallback* completion_callback) { + return net::OK; +} + +// ------------------------------------------------------------------------ + +MemEntryImpl::~MemEntryImpl() { + for (int i = 0; i < NUM_STREAMS; i++) + backend_->ModifyStorageSize(data_size_[i], 0); + backend_->ModifyStorageSize(static_cast<int32>(key_.size()), 0); + net_log_.EndEvent(net::NetLog::TYPE_DISK_CACHE_MEM_ENTRY_IMPL, NULL); +} + +int MemEntryImpl::InternalReadData(int index, int offset, net::IOBuffer* buf, + int buf_len) { DCHECK(type() == kParentEntry || index == kSparseData); if (index < 0 || index >= NUM_STREAMS) @@ -169,12 +287,12 @@ int MemEntryImpl::ReadData(int index, int offset, net::IOBuffer* buf, UpdateRank(false); - memcpy(buf->data() , &(data_[index])[offset], buf_len); + memcpy(buf->data(), &(data_[index])[offset], buf_len); return buf_len; } -int MemEntryImpl::WriteData(int index, int offset, net::IOBuffer* buf, - int buf_len, net::CompletionCallback* completion_callback, bool truncate) { +int MemEntryImpl::InternalWriteData(int index, int offset, net::IOBuffer* buf, + int buf_len, bool truncate) { DCHECK(type() == kParentEntry || index == kSparseData); if (index < 0 || index >= NUM_STREAMS) @@ -215,8 +333,8 @@ int MemEntryImpl::WriteData(int index, int offset, net::IOBuffer* buf, return buf_len; } -int MemEntryImpl::ReadSparseData(int64 offset, net::IOBuffer* buf, int buf_len, - net::CompletionCallback* completion_callback) { +int MemEntryImpl::InternalReadSparseData(int64 offset, net::IOBuffer* buf, + int buf_len) { DCHECK(type() == kParentEntry); if (!InitSparseInfo()) @@ -244,8 +362,19 @@ int MemEntryImpl::ReadSparseData(int64 offset, net::IOBuffer* buf, int buf_len, // we should stop. if (child_offset < child->child_first_pos_) break; + if (net_log_.IsLoggingAllEvents()) { + net_log_.BeginEvent( + net::NetLog::TYPE_SPARSE_READ_CHILD_DATA, + make_scoped_refptr(new SparseReadWriteParameters( + child->net_log().source(), + io_buf->BytesRemaining()))); + } int ret = child->ReadData(kSparseData, child_offset, io_buf, io_buf->BytesRemaining(), NULL); + if (net_log_.IsLoggingAllEvents()) { + net_log_.EndEventWithNetErrorCode( + net::NetLog::TYPE_SPARSE_READ_CHILD_DATA, ret); + } // If we encounter an error in one entry, return immediately. if (ret < 0) @@ -262,8 +391,8 @@ int MemEntryImpl::ReadSparseData(int64 offset, net::IOBuffer* buf, int buf_len, return io_buf->BytesConsumed(); } -int MemEntryImpl::WriteSparseData(int64 offset, net::IOBuffer* buf, int buf_len, - net::CompletionCallback* completion_callback) { +int MemEntryImpl::InternalWriteSparseData(int64 offset, net::IOBuffer* buf, + int buf_len) { DCHECK(type() == kParentEntry); if (!InitSparseInfo()) @@ -291,12 +420,24 @@ int MemEntryImpl::WriteSparseData(int64 offset, net::IOBuffer* buf, int buf_len, // Keep a record of the last byte position (exclusive) in the child. int data_size = child->GetDataSize(kSparseData); + if (net_log_.IsLoggingAllEvents()) { + net_log_.BeginEvent( + net::NetLog::TYPE_SPARSE_WRITE_CHILD_DATA, + make_scoped_refptr(new SparseReadWriteParameters( + child->net_log().source(), + write_len))); + } + // Always writes to the child entry. This operation may overwrite data // previously written. // TODO(hclam): if there is data in the entry and this write is not // continuous we may want to discard this write. int ret = child->WriteData(kSparseData, child_offset, io_buf, write_len, NULL, true); + if (net_log_.IsLoggingAllEvents()) { + net_log_.EndEventWithNetErrorCode( + net::NetLog::TYPE_SPARSE_WRITE_CHILD_DATA, ret); + } if (ret < 0) return ret; else if (ret == 0) @@ -317,29 +458,6 @@ int MemEntryImpl::WriteSparseData(int64 offset, net::IOBuffer* buf, int buf_len, return io_buf->BytesConsumed(); } -int MemEntryImpl::GetAvailableRange(int64 offset, int len, int64* start, - CompletionCallback* callback) { - return GetAvailableRange(offset, len, start); -} - -bool MemEntryImpl::CouldBeSparse() const { - DCHECK_EQ(kParentEntry, type()); - return (children_.get() != NULL); -} - -int MemEntryImpl::ReadyForSparseIO( - net::CompletionCallback* completion_callback) { - return net::OK; -} - -// ------------------------------------------------------------------------ - -MemEntryImpl::~MemEntryImpl() { - for (int i = 0; i < NUM_STREAMS; i++) - backend_->ModifyStorageSize(data_size_[i], 0); - backend_->ModifyStorageSize(static_cast<int32>(key_.size()), 0); -} - int MemEntryImpl::GetAvailableRange(int64 offset, int len, int64* start) { DCHECK(type() == kParentEntry); DCHECK(start); @@ -429,9 +547,19 @@ bool MemEntryImpl::InitSparseInfo() { return true; } -bool MemEntryImpl::InitChildEntry(MemEntryImpl* parent, int child_id) { +bool MemEntryImpl::InitChildEntry(MemEntryImpl* parent, int child_id, + net::NetLog* net_log) { DCHECK(!parent_); DCHECK(!child_id_); + + net_log_ = net::BoundNetLog::Make(net_log, + net::NetLog::SOURCE_MEMORY_CACHE_ENTRY); + net_log_.BeginEvent( + net::NetLog::TYPE_DISK_CACHE_MEM_ENTRY_IMPL, + make_scoped_refptr(new EntryCreationParameters( + GenerateChildName(parent->key(), child_id_), + true))); + parent_ = parent; child_id_ = child_id; Time current = Time::Now(); @@ -450,7 +578,7 @@ MemEntryImpl* MemEntryImpl::OpenChild(int64 offset, bool create) { return i->second; } else if (create) { MemEntryImpl* child = new MemEntryImpl(backend_); - child->InitChildEntry(this, index); + child->InitChildEntry(this, index, net_log_.net_log()); (*children_)[index] = child; return child; } diff --git a/net/disk_cache/mem_entry_impl.h b/net/disk_cache/mem_entry_impl.h index f4ac4ef..f195b75 100644 --- a/net/disk_cache/mem_entry_impl.h +++ b/net/disk_cache/mem_entry_impl.h @@ -8,6 +8,7 @@ #include "base/hash_tables.h" #include "base/scoped_ptr.h" +#include "net/base/net_log.h" #include "net/disk_cache/disk_cache.h" #include "testing/gtest/include/gtest/gtest_prod.h" @@ -54,7 +55,7 @@ class MemEntryImpl : public Entry { // Performs the initialization of a EntryImpl that will be added to the // cache. - bool CreateEntry(const std::string& key); + bool CreateEntry(const std::string& key, net::NetLog* net_log); // Permanently destroys this entry. void InternalDoom(); @@ -82,6 +83,14 @@ class MemEntryImpl : public Entry { return parent_ ? kChildEntry : kParentEntry; } + std::string& key() { + return key_; + } + + net::BoundNetLog& net_log() { + return net_log_; + } + // Entry interface. virtual void Doom(); virtual void Close(); @@ -113,6 +122,14 @@ class MemEntryImpl : public Entry { ~MemEntryImpl(); + // Do all the work for corresponding public functions. Implemented as + // separate functions to make logging of results simpler. + int InternalReadData(int index, int offset, net::IOBuffer* buf, int buf_len); + int InternalWriteData(int index, int offset, net::IOBuffer* buf, int buf_len, + bool truncate); + int InternalReadSparseData(int64 offset, net::IOBuffer* buf, int buf_len); + int InternalWriteSparseData(int64 offset, net::IOBuffer* buf, int buf_len); + // Old Entry interface. int GetAvailableRange(int64 offset, int len, int64* start); @@ -129,7 +146,7 @@ class MemEntryImpl : public Entry { // Performs the initialization of a MemEntryImpl as a child entry. // |parent| is the pointer to the parent entry. |child_id| is the ID of // the new child. - bool InitChildEntry(MemEntryImpl* parent, int child_id); + bool InitChildEntry(MemEntryImpl* parent, int child_id, net::NetLog* net_log); // Returns an entry responsible for |offset|. The returned entry can be a // child entry or this entry itself if |offset| points to the first range. @@ -163,6 +180,8 @@ class MemEntryImpl : public Entry { MemBackendImpl* backend_; // Back pointer to the cache. bool doomed_; // True if this entry was removed from the cache. + net::BoundNetLog net_log_; + DISALLOW_COPY_AND_ASSIGN(MemEntryImpl); }; diff --git a/net/disk_cache/net_log_parameters.cc b/net/disk_cache/net_log_parameters.cc new file mode 100644 index 0000000..76d79d7 --- /dev/null +++ b/net/disk_cache/net_log_parameters.cc @@ -0,0 +1,100 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "net/disk_cache/net_log_parameters.h" + +#include "base/logging.h" +#include "base/string_number_conversions.h" +#include "base/values.h" +#include "net/base/net_errors.h" + +namespace disk_cache { + +EntryCreationParameters::EntryCreationParameters( + const std::string& key, bool created) + : key_(key), created_(created) { +} + +Value* EntryCreationParameters::ToValue() const { + DictionaryValue* dict = new DictionaryValue(); + dict->SetString("key", key_); + dict->SetBoolean("created", created_); + return dict; +} + +ReadWriteDataParameters::ReadWriteDataParameters( + int index, int offset, int buf_len, bool truncate) + : index_(index), offset_(offset), buf_len_(buf_len), truncate_(truncate) { +} + +Value* ReadWriteDataParameters::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; +} + + +// NetLog parameters logged when non-sparse reads and writes complete. +ReadWriteCompleteParameters::ReadWriteCompleteParameters(int bytes_copied) + : bytes_copied_(bytes_copied) { +} + +Value* ReadWriteCompleteParameters::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; +} + +SparseOperationParameters::SparseOperationParameters( + int64 offset, int buff_len) + : offset_(offset), buff_len_(buff_len) { +} + +Value* SparseOperationParameters::ToValue() const { + DictionaryValue* dict = new DictionaryValue(); + // Values can only be created with at most 32-bit integers. Using a string + // instead circumvents that restriction. + dict->SetString("offset", base::Int64ToString(offset_)); + dict->SetInteger("buff_len", buff_len_); + return dict; +} + +SparseReadWriteParameters::SparseReadWriteParameters( + const net::NetLog::Source& source, int child_len) + : source_(source), child_len_(child_len) { +} + +Value* SparseReadWriteParameters::ToValue() const { + DictionaryValue* dict = new DictionaryValue(); + dict->Set("source_dependency", source_.ToValue()); + dict->SetInteger("child_len", child_len_); + return dict; +} + +GetAvailableRangeResultParameters::GetAvailableRangeResultParameters( + int64 start, int result) + : start_(start), result_(result) { +} + +Value* GetAvailableRangeResultParameters::ToValue() const { + DictionaryValue* dict = new DictionaryValue(); + if (result_ > 0) { + dict->SetInteger("length", result_); + dict->SetString("start", base::Int64ToString(start_)); + } else { + dict->SetInteger("net_error", result_); + } + return dict; +} + +} // namespace disk_cache diff --git a/net/disk_cache/net_log_parameters.h b/net/disk_cache/net_log_parameters.h new file mode 100644 index 0000000..f708c79 --- /dev/null +++ b/net/disk_cache/net_log_parameters.h @@ -0,0 +1,99 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef NET_DISK_CACHE_NET_LOG_PARAMETERS_H_ +#define NET_DISK_CACHE_NET_LOG_PARAMETERS_H_ +#pragma once + +#include <string> + +#include "net/base/net_log.h" + +// This file contains a set of NetLog::EventParameters shared by EntryImpls and +// MemEntryImpls. +namespace disk_cache { + +// NetLog parameters for the creation of an Entry. Contains the Entry's name +// and whether it was created or opened. +class EntryCreationParameters : public net::NetLog::EventParameters { + public: + EntryCreationParameters(const std::string& key, bool created); + virtual Value* ToValue() const; + + private: + const std::string key_; + const bool created_; + + DISALLOW_COPY_AND_ASSIGN(EntryCreationParameters); +}; + +// NetLog parameters for non-sparse reading and writing to an Entry. +class ReadWriteDataParameters : public net::NetLog::EventParameters { + public: + // For reads, |truncate| must be false. + ReadWriteDataParameters(int index, int offset, int buf_len, bool truncate); + virtual Value* ToValue() const; + + private: + const int index_; + const int offset_; + const int buf_len_; + const bool truncate_; + + DISALLOW_COPY_AND_ASSIGN(ReadWriteDataParameters); +}; + +// NetLog parameters for when a non-sparse read or write completes. +class ReadWriteCompleteParameters : 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 ReadWriteCompleteParameters(int bytes_copied); + virtual Value* ToValue() const; + + private: + const int bytes_copied_; + + DISALLOW_COPY_AND_ASSIGN(ReadWriteCompleteParameters); +}; + +// NetLog parameters for when a sparse operation is started. +class SparseOperationParameters : public net::NetLog::EventParameters { + public: + SparseOperationParameters(int64 offset, int buff_len); + virtual Value* ToValue() const; + + private: + const int64 offset_; + const int buff_len_; +}; + +// NetLog parameters for when a read or write for a sparse entry's child is +// started. +class SparseReadWriteParameters : public net::NetLog::EventParameters { + public: + SparseReadWriteParameters(const net::NetLog::Source& source, int child_len); + virtual Value* ToValue() const; + + private: + const net::NetLog::Source source_; + const int child_len_; +}; + +// NetLog parameters for when a call to GetAvailableRange returns. +class GetAvailableRangeResultParameters : public net::NetLog::EventParameters { + public: + // |start| is ignored when |result| < 0. + GetAvailableRangeResultParameters(int64 start, int result); + virtual Value* ToValue() const; + + private: + const int64 start_; + const int result_; +}; + +} // namespace disk_cache + +#endif // NET_DISK_CACHE_NET_LOG_CACHE_PARAMETERS_H_ diff --git a/net/disk_cache/sparse_control.cc b/net/disk_cache/sparse_control.cc index bd8908f..887d78d 100644 --- a/net/disk_cache/sparse_control.cc +++ b/net/disk_cache/sparse_control.cc @@ -15,6 +15,7 @@ #include "net/disk_cache/backend_impl.h" #include "net/disk_cache/entry_impl.h" #include "net/disk_cache/file.h" +#include "net/disk_cache/net_log_parameters.h" using base::Time; @@ -35,7 +36,7 @@ const int kMaxEntrySize = 0x100000; // The size of each data block (tracked by the child allocation bitmap). const int kBlockSize = 1024; -// Returns the name of of a child entry given the base_name and signature of the +// Returns the name of a child entry given the base_name and signature of the // parent and the child_id. // If the entry is called entry_name, child entries will be named something // like Range_entry_name:XXX:YYY where XXX is the entry signature and YYY is the @@ -138,22 +139,38 @@ 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) { +// Returns the NetLog event type corresponding to a SparseOperation. +net::NetLog::EventType GetSparseEventType( + disk_cache::SparseControl::SparseOperation operation) { + switch (operation) { + case disk_cache::SparseControl::kReadOperation: + return net::NetLog::TYPE_SPARSE_READ; + case disk_cache::SparseControl::kWriteOperation: + return net::NetLog::TYPE_SPARSE_WRITE; + case disk_cache::SparseControl::kGetRangeOperation: + return net::NetLog::TYPE_SPARSE_GET_RANGE; + default: + NOTREACHED(); + return net::NetLog::TYPE_CANCELLED; + } +} + +// Logs the end event for |operation| on a child entry. Range operations log +// no events for each child they search through. +void LogChildOperationEnd(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; + event_type = net::NetLog::TYPE_SPARSE_READ_CHILD_DATA; break; case disk_cache::SparseControl::kWriteOperation: - event_type = net::NetLog::TYPE_SPARSE_CONTROL_WRITE; + event_type = net::NetLog::TYPE_SPARSE_WRITE_CHILD_DATA; break; case disk_cache::SparseControl::kGetRangeOperation: - event_type = net::NetLog::TYPE_SPARSE_CONTROL_GET_RANGE; - break; + return; default: NOTREACHED(); return; @@ -247,7 +264,11 @@ int SparseControl::StartIO(SparseOperation op, int64 offset, net::IOBuffer* buf, finished_ = false; abort_ = false; - entry_->net_log().BeginEvent(net::NetLog::TYPE_SPARSE_CONTROL, NULL); + if (entry_->net_log().IsLoggingAllEvents()) { + entry_->net_log().BeginEvent( + GetSparseEventType(operation_), + make_scoped_refptr(new SparseOperationParameters(offset_, buf_len_))); + } DoChildrenIO(); if (!pending_) { @@ -317,6 +338,8 @@ void SparseControl::DeleteChildren(EntryImpl* entry) { if (!buffer && !address.is_initialized()) return; + entry->net_log().AddEvent(net::NetLog::TYPE_SPARSE_DELETE_CHILDREN, NULL); + ChildrenDeleter* deleter = new ChildrenDeleter(entry->backend_, entry->GetKey()); // The object will self destruct when finished. @@ -635,8 +658,20 @@ void SparseControl::InitChildData() { void SparseControl::DoChildrenIO() { while (DoChildIO()) continue; + // Range operations are finished synchronously, often without setting + // |finished_| to true. + if (kGetRangeOperation == operation_ && + entry_->net_log().IsLoggingAllEvents()) { + entry_->net_log().EndEvent( + net::NetLog::TYPE_SPARSE_GET_RANGE, + make_scoped_refptr( + new GetAvailableRangeResultParameters(offset_, result_))); + } if (finished_) { - entry_->net_log().EndEvent(net::NetLog::TYPE_SPARSE_CONTROL, NULL); + if (kGetRangeOperation != operation_ && + entry_->net_log().IsLoggingAllEvents()) { + entry_->net_log().EndEvent(GetSparseEventType(operation_), NULL); + } if (pending_) DoUserCallback(); } @@ -662,10 +697,10 @@ bool SparseControl::DoChildIO() { 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()))); + net::NetLog::TYPE_SPARSE_READ_CHILD_DATA, + make_scoped_refptr(new SparseReadWriteParameters( + child_->net_log().source(), + child_len_))); } rv = child_->ReadDataImpl(kSparseData, child_offset_, user_buf_, child_len_, callback); @@ -673,19 +708,15 @@ bool SparseControl::DoChildIO() { 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()))); + net::NetLog::TYPE_SPARSE_WRITE_CHILD_DATA, + make_scoped_refptr(new SparseReadWriteParameters( + child_->net_log().source(), + child_len_))); } 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: @@ -758,7 +789,7 @@ int SparseControl::DoGetAvailableRange() { } void SparseControl::DoChildIOCompleted(int result) { - LogOperationEnd(entry_->net_log(), operation_, result); + LogChildOperationEnd(entry_->net_log(), operation_, result); if (result < 0) { // We fail the whole operation if we encounter an error. result_ = result; @@ -784,8 +815,10 @@ 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); + if (entry_->net_log().IsLoggingAllEvents()) { + entry_->net_log().AddEvent(net::NetLog::TYPE_CANCELLED, NULL); + entry_->net_log().EndEvent(GetSparseEventType(operation_), NULL); + } DoUserCallback(); return DoAbortCallbacks(); } diff --git a/net/net.gyp b/net/net.gyp index 3443c83..4bb30b5 100644 --- a/net/net.gyp +++ b/net/net.gyp @@ -385,6 +385,8 @@ 'disk_cache/eviction.cc', 'disk_cache/eviction.h', 'disk_cache/experiments.h', + 'disk_cache/net_log_parameters.cc', + 'disk_cache/net_log_parameters.h', 'disk_cache/file.cc', 'disk_cache/file.h', 'disk_cache/file_block.h', |