Index: chrome/browser/task_manager/sampling/task_manager_io_thread_helper.cc |
diff --git a/chrome/browser/task_manager/sampling/task_manager_io_thread_helper.cc b/chrome/browser/task_manager/sampling/task_manager_io_thread_helper.cc |
index ae0166762d8d73d1407e48ed7fe0246422266962..1352a3eddc15814c3cfc54c0c5dc4884964df04c 100644 |
--- a/chrome/browser/task_manager/sampling/task_manager_io_thread_helper.cc |
+++ b/chrome/browser/task_manager/sampling/task_manager_io_thread_helper.cc |
@@ -63,6 +63,15 @@ void TaskManagerIoThreadHelper::OnRawBytesRead(const net::URLRequest& request, |
g_io_thread_helper->OnNetworkBytesRead(request, bytes_read); |
} |
+// static |
+void TaskManagerIoThreadHelper::OnRawBytesSent(const net::URLRequest& request, |
+ int64_t bytes_sent) { |
+ DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
+ |
+ if (g_io_thread_helper) |
+ g_io_thread_helper->OnNetworkBytesSent(request, bytes_sent); |
+} |
+ |
TaskManagerIoThreadHelper::TaskManagerIoThreadHelper() : weak_factory_(this) { |
DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
} |
@@ -76,8 +85,8 @@ void TaskManagerIoThreadHelper::OnMultipleBytesReadIO() { |
DCHECK(!bytes_read_buffer_.empty()); |
- std::vector<BytesReadParam>* bytes_read_buffer = |
- new std::vector<BytesReadParam>(); |
+ std::vector<BytesTransferedParam>* bytes_read_buffer = |
+ new std::vector<BytesTransferedParam>(); |
bytes_read_buffer_.swap(*bytes_read_buffer); |
content::BrowserThread::PostTask( |
@@ -121,7 +130,60 @@ void TaskManagerIoThreadHelper::OnNetworkBytesRead( |
} |
ncarter (slow)
2017/06/08 23:37:19
There's a potential optimization here we can consi
cburn
2017/06/14 18:04:38
Done.
|
bytes_read_buffer_.push_back( |
- BytesReadParam(origin_pid, child_id, route_id, bytes_read)); |
+ BytesTransferedParam(origin_pid, child_id, route_id, bytes_read)); |
+} |
+ |
+void TaskManagerIoThreadHelper::OnMultipleBytesSentIO() { |
+ DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
+ |
+ DCHECK(!bytes_sent_buffer_.empty()); |
+ |
+ std::vector<BytesTransferedParam>* bytes_sent_buffer = |
+ new std::vector<BytesTransferedParam>(); |
+ bytes_sent_buffer_.swap(*bytes_sent_buffer); |
ncarter (slow)
2017/06/08 23:37:19
Because this whole dance with the vectors, swappin
cburn
2017/06/14 18:04:38
Done.
|
+ |
+ content::BrowserThread::PostTask( |
+ content::BrowserThread::UI, FROM_HERE, |
+ base::Bind(&TaskManagerImpl::OnMultipleBytesSentUI, |
+ base::Owned(bytes_sent_buffer))); |
+} |
+ |
+void TaskManagerIoThreadHelper::OnNetworkBytesSent( |
+ const net::URLRequest& request, |
+ int64_t bytes_sent) { |
+ DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
+ |
+ // Only net::URLRequestJob instances created by the ResourceDispatcherHost |
+ // have an associated ResourceRequestInfo and a render frame associated. |
+ // All other jobs will have -1 returned for the render process child and |
+ // routing ids - the jobs may still match a resource based on their origin id, |
+ // otherwise BytesRead() will attribute the activity to the Browser resource. |
+ const content::ResourceRequestInfo* info = |
+ content::ResourceRequestInfo::ForRequest(&request); |
+ int child_id = -1; |
+ int route_id = -1; |
+ if (info) |
+ info->GetAssociatedRenderFrame(&child_id, &route_id); |
+ |
+ // Get the origin PID of the request's originator. This will only be set for |
+ // plugins - for renderer or browser initiated requests it will be zero. |
+ int origin_pid = info ? info->GetOriginPID() : 0; |
+ |
+ if (bytes_sent_buffer_.empty()) { |
+ // Schedule a task to process the received bytes requests a second from now. |
+ // We're trying to calculate the tasks' network usage speed as bytes per |
+ // second so we collect as many requests during one seconds before the below |
+ // delayed TaskManagerIoThreadHelper::OnMultipleBytesReadIO() process them |
+ // after one second from now. |
+ content::BrowserThread::PostDelayedTask( |
+ content::BrowserThread::IO, FROM_HERE, |
+ base::Bind(&TaskManagerIoThreadHelper::OnMultipleBytesSentIO, |
+ weak_factory_.GetWeakPtr()), |
+ base::TimeDelta::FromSeconds(1)); |
+ } |
+ |
+ bytes_sent_buffer_.push_back( |
+ BytesTransferedParam(origin_pid, child_id, route_id, bytes_sent)); |
} |
} // namespace task_manager |