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

Side by Side Diff: chrome/browser/task_manager/sampling/task_manager_io_thread_helper.cc

Issue 2905403002: plumb network upload into the task manager (Closed)
Patch Set: added refresh timer tests Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 52
53 delete g_io_thread_helper; 53 delete g_io_thread_helper;
54 g_io_thread_helper = nullptr; 54 g_io_thread_helper = nullptr;
55 } 55 }
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 int64_t bytes_sent = 0;
64 g_io_thread_helper->OnNetworkBytesTransfered(request, bytes_read,
65 bytes_sent);
ncarter (slow) 2017/06/17 00:21:01 You can also consider using this style: OnNetwork
cburn 2017/06/19 22:07:08 Acknowledged.
66 }
67 }
68
69 // static
70 void TaskManagerIoThreadHelper::OnRawBytesSent(const net::URLRequest& request,
71 int64_t bytes_sent) {
72 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
73
74 if (g_io_thread_helper) {
75 int64_t bytes_read = 0;
76 g_io_thread_helper->OnNetworkBytesTransfered(request, bytes_read,
77 bytes_sent);
78 }
64 } 79 }
65 80
66 TaskManagerIoThreadHelper::TaskManagerIoThreadHelper() : weak_factory_(this) { 81 TaskManagerIoThreadHelper::TaskManagerIoThreadHelper() : weak_factory_(this) {
67 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 82 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
68 } 83 }
69 84
70 TaskManagerIoThreadHelper::~TaskManagerIoThreadHelper() { 85 TaskManagerIoThreadHelper::~TaskManagerIoThreadHelper() {
71 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 86 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
72 } 87 }
73 88
74 void TaskManagerIoThreadHelper::OnMultipleBytesReadIO() { 89 void TaskManagerIoThreadHelper::OnMultipleBytesTransferedIO() {
75 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 90 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
76 91
77 DCHECK(!bytes_read_buffer_.empty()); 92 DCHECK(!bytes_transfered_buffer_.empty());
78 93
79 std::vector<BytesReadParam>* bytes_read_buffer = 94 std::vector<BytesTransferedParam>* bytes_read_buffer =
80 new std::vector<BytesReadParam>(); 95 new std::vector<BytesTransferedParam>();
81 bytes_read_buffer_.swap(*bytes_read_buffer); 96 bytes_transfered_buffer_.swap(*bytes_read_buffer);
82 97
83 content::BrowserThread::PostTask( 98 content::BrowserThread::PostTask(
84 content::BrowserThread::UI, 99 content::BrowserThread::UI, FROM_HERE,
85 FROM_HERE, 100 base::Bind(&TaskManagerImpl::OnMultipleBytesTransferedUI,
86 base::Bind(&TaskManagerImpl::OnMultipleBytesReadUI,
87 base::Owned(bytes_read_buffer))); 101 base::Owned(bytes_read_buffer)));
88 } 102 }
89 103
90 void TaskManagerIoThreadHelper::OnNetworkBytesRead( 104 void TaskManagerIoThreadHelper::OnNetworkBytesTransfered(
91 const net::URLRequest& request, int64_t bytes_read) { 105 const net::URLRequest& request,
106 int64_t bytes_read,
107 int64_t bytes_sent) {
92 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 108 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
93 109
94 // Only net::URLRequestJob instances created by the ResourceDispatcherHost 110 // Only net::URLRequestJob instances created by the ResourceDispatcherHost
95 // have an associated ResourceRequestInfo and a render frame associated. 111 // have an associated ResourceRequestInfo and a render frame associated.
96 // All other jobs will have -1 returned for the render process child and 112 // All other jobs will have -1 returned for the render process child and
97 // routing ids - the jobs may still match a resource based on their origin id, 113 // routing ids - the jobs may still match a resource based on their origin id,
98 // otherwise BytesRead() will attribute the activity to the Browser resource. 114 // otherwise BytesRead() will attribute the activity to the Browser resource.
99 const content::ResourceRequestInfo* info = 115 const content::ResourceRequestInfo* info =
100 content::ResourceRequestInfo::ForRequest(&request); 116 content::ResourceRequestInfo::ForRequest(&request);
101 int child_id = -1; 117 int child_id = -1;
102 int route_id = -1; 118 int route_id = -1;
103 if (info) 119 if (info)
104 info->GetAssociatedRenderFrame(&child_id, &route_id); 120 info->GetAssociatedRenderFrame(&child_id, &route_id);
105 121
106 // Get the origin PID of the request's originator. This will only be set for 122 // Get the origin PID of the request's originator. This will only be set for
107 // plugins - for renderer or browser initiated requests it will be zero. 123 // plugins - for renderer or browser initiated requests it will be zero.
108 int origin_pid = info ? info->GetOriginPID() : 0; 124 int origin_pid = info ? info->GetOriginPID() : 0;
109 125
110 if (bytes_read_buffer_.empty()) { 126 if (bytes_transfered_buffer_.empty()) {
111 // Schedule a task to process the received bytes requests a second from now. 127 // Schedule a task to process the received bytes requests a second from now.
112 // We're trying to calculate the tasks' network usage speed as bytes per 128 // 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 129 // second so we collect as many requests during one seconds before the below
114 // delayed TaskManagerIoThreadHelper::OnMultipleBytesReadIO() process them 130 // delayed TaskManagerIoThreadHelper::OnMultipleBytesReadIO() process them
115 // after one second from now. 131 // after one second from now.
116 content::BrowserThread::PostDelayedTask( 132 content::BrowserThread::PostDelayedTask(
117 content::BrowserThread::IO, FROM_HERE, 133 content::BrowserThread::IO, FROM_HERE,
118 base::Bind(&TaskManagerIoThreadHelper::OnMultipleBytesReadIO, 134 base::Bind(&TaskManagerIoThreadHelper::OnMultipleBytesTransferedIO,
119 weak_factory_.GetWeakPtr()), 135 weak_factory_.GetWeakPtr()),
120 base::TimeDelta::FromSeconds(1)); 136 base::TimeDelta::FromSeconds(1));
121 } 137 }
122 138
123 bytes_read_buffer_.push_back( 139 bytes_transfered_buffer_.push_back(BytesTransferedParam(
124 BytesReadParam(origin_pid, child_id, route_id, bytes_read)); 140 origin_pid, child_id, route_id, bytes_read, bytes_sent));
125 } 141 }
126 142
127 } // namespace task_manager 143 } // namespace task_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698