Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/task_manager/sampling/task_manager_io_thread_helper.h" | 5 #include "chrome/browser/task_manager/sampling/task_manager_io_thread_helper.h" |
| 6 | 6 |
| 7 #include "chrome/browser/task_manager/sampling/task_manager_impl.h" | 7 #include "chrome/browser/task_manager/sampling/task_manager_impl.h" |
| 8 #include "content/public/browser/browser_thread.h" | 8 #include "content/public/browser/browser_thread.h" |
| 9 #include "content/public/browser/resource_request_info.h" | 9 #include "content/public/browser/resource_request_info.h" |
| 10 | 10 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 56 | 56 |
| 57 // static | 57 // static |
| 58 void TaskManagerIoThreadHelper::OnRawBytesRead(const net::URLRequest& request, | 58 void TaskManagerIoThreadHelper::OnRawBytesRead(const net::URLRequest& request, |
| 59 int64_t bytes_read) { | 59 int64_t bytes_read) { |
| 60 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 60 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 61 | 61 |
| 62 if (g_io_thread_helper) | 62 if (g_io_thread_helper) |
| 63 g_io_thread_helper->OnNetworkBytesRead(request, bytes_read); | 63 g_io_thread_helper->OnNetworkBytesRead(request, bytes_read); |
| 64 } | 64 } |
| 65 | 65 |
| 66 // static | |
| 67 void TaskManagerIoThreadHelper::OnRawBytesSent(const net::URLRequest& request, | |
| 68 int64_t bytes_sent) { | |
| 69 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | |
| 70 | |
| 71 if (g_io_thread_helper) | |
| 72 g_io_thread_helper->OnNetworkBytesSent(request, bytes_sent); | |
| 73 } | |
| 74 | |
| 66 TaskManagerIoThreadHelper::TaskManagerIoThreadHelper() : weak_factory_(this) { | 75 TaskManagerIoThreadHelper::TaskManagerIoThreadHelper() : weak_factory_(this) { |
| 67 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 76 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 68 } | 77 } |
| 69 | 78 |
| 70 TaskManagerIoThreadHelper::~TaskManagerIoThreadHelper() { | 79 TaskManagerIoThreadHelper::~TaskManagerIoThreadHelper() { |
| 71 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 80 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 72 } | 81 } |
| 73 | 82 |
| 74 void TaskManagerIoThreadHelper::OnMultipleBytesReadIO() { | 83 void TaskManagerIoThreadHelper::OnMultipleBytesReadIO() { |
| 75 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 84 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 76 | 85 |
| 77 DCHECK(!bytes_read_buffer_.empty()); | 86 DCHECK(!bytes_read_buffer_.empty()); |
| 78 | 87 |
| 79 std::vector<BytesReadParam>* bytes_read_buffer = | 88 std::vector<BytesTransferedParam>* bytes_read_buffer = |
| 80 new std::vector<BytesReadParam>(); | 89 new std::vector<BytesTransferedParam>(); |
| 81 bytes_read_buffer_.swap(*bytes_read_buffer); | 90 bytes_read_buffer_.swap(*bytes_read_buffer); |
| 82 | 91 |
| 83 content::BrowserThread::PostTask( | 92 content::BrowserThread::PostTask( |
| 84 content::BrowserThread::UI, | 93 content::BrowserThread::UI, |
| 85 FROM_HERE, | 94 FROM_HERE, |
| 86 base::Bind(&TaskManagerImpl::OnMultipleBytesReadUI, | 95 base::Bind(&TaskManagerImpl::OnMultipleBytesReadUI, |
| 87 base::Owned(bytes_read_buffer))); | 96 base::Owned(bytes_read_buffer))); |
| 88 } | 97 } |
| 89 | 98 |
| 90 void TaskManagerIoThreadHelper::OnNetworkBytesRead( | 99 void TaskManagerIoThreadHelper::OnNetworkBytesRead( |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 112 // We're trying to calculate the tasks' network usage speed as bytes per | 121 // We're trying to calculate the tasks' network usage speed as bytes per |
| 113 // second so we collect as many requests during one seconds before the below | 122 // second so we collect as many requests during one seconds before the below |
| 114 // delayed TaskManagerIoThreadHelper::OnMultipleBytesReadIO() process them | 123 // delayed TaskManagerIoThreadHelper::OnMultipleBytesReadIO() process them |
| 115 // after one second from now. | 124 // after one second from now. |
| 116 content::BrowserThread::PostDelayedTask( | 125 content::BrowserThread::PostDelayedTask( |
| 117 content::BrowserThread::IO, FROM_HERE, | 126 content::BrowserThread::IO, FROM_HERE, |
| 118 base::Bind(&TaskManagerIoThreadHelper::OnMultipleBytesReadIO, | 127 base::Bind(&TaskManagerIoThreadHelper::OnMultipleBytesReadIO, |
| 119 weak_factory_.GetWeakPtr()), | 128 weak_factory_.GetWeakPtr()), |
| 120 base::TimeDelta::FromSeconds(1)); | 129 base::TimeDelta::FromSeconds(1)); |
| 121 } | 130 } |
| 122 | 131 |
|
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.
| |
| 123 bytes_read_buffer_.push_back( | 132 bytes_read_buffer_.push_back( |
| 124 BytesReadParam(origin_pid, child_id, route_id, bytes_read)); | 133 BytesTransferedParam(origin_pid, child_id, route_id, bytes_read)); |
| 134 } | |
| 135 | |
| 136 void TaskManagerIoThreadHelper::OnMultipleBytesSentIO() { | |
| 137 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | |
| 138 | |
| 139 DCHECK(!bytes_sent_buffer_.empty()); | |
| 140 | |
| 141 std::vector<BytesTransferedParam>* bytes_sent_buffer = | |
| 142 new std::vector<BytesTransferedParam>(); | |
| 143 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.
| |
| 144 | |
| 145 content::BrowserThread::PostTask( | |
| 146 content::BrowserThread::UI, FROM_HERE, | |
| 147 base::Bind(&TaskManagerImpl::OnMultipleBytesSentUI, | |
| 148 base::Owned(bytes_sent_buffer))); | |
| 149 } | |
| 150 | |
| 151 void TaskManagerIoThreadHelper::OnNetworkBytesSent( | |
| 152 const net::URLRequest& request, | |
| 153 int64_t bytes_sent) { | |
| 154 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | |
| 155 | |
| 156 // Only net::URLRequestJob instances created by the ResourceDispatcherHost | |
| 157 // have an associated ResourceRequestInfo and a render frame associated. | |
| 158 // All other jobs will have -1 returned for the render process child and | |
| 159 // routing ids - the jobs may still match a resource based on their origin id, | |
| 160 // otherwise BytesRead() will attribute the activity to the Browser resource. | |
| 161 const content::ResourceRequestInfo* info = | |
| 162 content::ResourceRequestInfo::ForRequest(&request); | |
| 163 int child_id = -1; | |
| 164 int route_id = -1; | |
| 165 if (info) | |
| 166 info->GetAssociatedRenderFrame(&child_id, &route_id); | |
| 167 | |
| 168 // Get the origin PID of the request's originator. This will only be set for | |
| 169 // plugins - for renderer or browser initiated requests it will be zero. | |
| 170 int origin_pid = info ? info->GetOriginPID() : 0; | |
| 171 | |
| 172 if (bytes_sent_buffer_.empty()) { | |
| 173 // Schedule a task to process the received bytes requests a second from now. | |
| 174 // We're trying to calculate the tasks' network usage speed as bytes per | |
| 175 // second so we collect as many requests during one seconds before the below | |
| 176 // delayed TaskManagerIoThreadHelper::OnMultipleBytesReadIO() process them | |
| 177 // after one second from now. | |
| 178 content::BrowserThread::PostDelayedTask( | |
| 179 content::BrowserThread::IO, FROM_HERE, | |
| 180 base::Bind(&TaskManagerIoThreadHelper::OnMultipleBytesSentIO, | |
| 181 weak_factory_.GetWeakPtr()), | |
| 182 base::TimeDelta::FromSeconds(1)); | |
| 183 } | |
| 184 | |
| 185 bytes_sent_buffer_.push_back( | |
| 186 BytesTransferedParam(origin_pid, child_id, route_id, bytes_sent)); | |
| 125 } | 187 } |
| 126 | 188 |
| 127 } // namespace task_manager | 189 } // namespace task_manager |
| OLD | NEW |