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

Side by Side Diff: chrome/browser/task_manager/providers/task.cc

Issue 2905403002: plumb network upload into the task manager (Closed)
Patch Set: fixed spelling/parellelism issues 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/providers/task.h" 5 #include "chrome/browser/task_manager/providers/task.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/process/process.h" 9 #include "base/process/process.h"
10 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
(...skipping 12 matching lines...) Expand all
23 int64_t g_last_id = 0; 23 int64_t g_last_id = 0;
24 24
25 } // namespace 25 } // namespace
26 26
27 Task::Task(const base::string16& title, 27 Task::Task(const base::string16& title,
28 const std::string& rappor_sample, 28 const std::string& rappor_sample,
29 const gfx::ImageSkia* icon, 29 const gfx::ImageSkia* icon,
30 base::ProcessHandle handle, 30 base::ProcessHandle handle,
31 base::ProcessId process_id) 31 base::ProcessId process_id)
32 : task_id_(g_last_id++), 32 : task_id_(g_last_id++),
33 network_usage_(-1), 33 last_refresh_cumulative_bytes_sent_(0),
34 current_byte_count_(-1), 34 last_refresh_cumulative_bytes_read_(0),
35 cumulative_bytes_sent_(-1),
ncarter (slow) 2017/06/14 20:20:58 I have a hunch that this code would come out easie
cburn 2017/06/16 21:52:26 I agree that this makes more sense. I am unsure if
36 cumulative_bytes_read_(-1),
37 network_sent_rate_(0),
38 network_read_rate_(0),
35 title_(title), 39 title_(title),
36 rappor_sample_name_(rappor_sample), 40 rappor_sample_name_(rappor_sample),
37 icon_(icon ? *icon : gfx::ImageSkia()), 41 icon_(icon ? *icon : gfx::ImageSkia()),
38 process_handle_(handle), 42 process_handle_(handle),
39 process_id_(process_id != base::kNullProcessId 43 process_id_(process_id != base::kNullProcessId
40 ? process_id 44 ? process_id
41 : base::GetProcId(handle)) {} 45 : base::GetProcId(handle)) {}
42 46
43 Task::~Task() {} 47 Task::~Task() {}
44 48
(...skipping 21 matching lines...) Expand all
66 DCHECK_NE(process_id(), base::GetCurrentProcId()); 70 DCHECK_NE(process_id(), base::GetCurrentProcId());
67 base::Process process = base::Process::Open(process_id()); 71 base::Process process = base::Process::Open(process_id());
68 process.Terminate(content::RESULT_CODE_KILLED, false); 72 process.Terminate(content::RESULT_CODE_KILLED, false);
69 } 73 }
70 74
71 void Task::Refresh(const base::TimeDelta& update_interval, 75 void Task::Refresh(const base::TimeDelta& update_interval,
72 int64_t refresh_flags) { 76 int64_t refresh_flags) {
73 if ((refresh_flags & REFRESH_TYPE_NETWORK_USAGE) == 0) 77 if ((refresh_flags & REFRESH_TYPE_NETWORK_USAGE) == 0)
74 return; 78 return;
75 79
76 if (current_byte_count_ == -1) 80 if (cumulative_bytes_sent_ == -1 && cumulative_bytes_read_ == -1)
77 return; 81 return;
78 82
79 network_usage_ = 83 int64_t current_cycle_read_byte_count =
80 (current_byte_count_ * base::TimeDelta::FromSeconds(1)) / update_interval; 84 cumulative_bytes_read_ - last_refresh_cumulative_bytes_read_;
85 network_read_rate_ = 0;
86 if (cumulative_bytes_read_ != -1) {
87 network_read_rate_ =
88 (current_cycle_read_byte_count * base::TimeDelta::FromSeconds(1)) /
89 update_interval;
90 }
81 91
82 // Reset the current byte count for this task. 92 int64_t current_cycle_sent_byte_count =
83 current_byte_count_ = 0; 93 cumulative_bytes_sent_ - last_refresh_cumulative_bytes_sent_;
94 network_sent_rate_ = 0;
95 if (cumulative_bytes_sent_ != -1) {
96 network_sent_rate_ =
97 (current_cycle_sent_byte_count * base::TimeDelta::FromSeconds(1)) /
98 update_interval;
99 }
100 last_refresh_cumulative_bytes_read_ = cumulative_bytes_read_;
101 last_refresh_cumulative_bytes_sent_ = cumulative_bytes_sent_;
84 } 102 }
85 103
86 void Task::OnNetworkBytesRead(int64_t bytes_read) { 104 void Task::OnNetworkBytesRead(int64_t bytes_read) {
87 if (current_byte_count_ == -1) 105 if (cumulative_bytes_read_ == -1) {
88 current_byte_count_ = 0; 106 cumulative_bytes_read_ = 0;
107 }
89 108
90 current_byte_count_ += bytes_read; 109 cumulative_bytes_read_ += bytes_read;
110 }
111
112 void Task::OnNetworkBytesSent(int64_t bytes_sent) {
113 if (cumulative_bytes_sent_ == -1) {
114 cumulative_bytes_sent_ = 0;
115 }
116
117 cumulative_bytes_sent_ += bytes_sent;
91 } 118 }
92 119
93 void Task::GetTerminationStatus(base::TerminationStatus* out_status, 120 void Task::GetTerminationStatus(base::TerminationStatus* out_status,
94 int* out_error_code) const { 121 int* out_error_code) const {
95 DCHECK(out_status); 122 DCHECK(out_status);
96 DCHECK(out_error_code); 123 DCHECK(out_error_code);
97 124
98 *out_status = base::TERMINATION_STATUS_STILL_RUNNING; 125 *out_status = base::TERMINATION_STATUS_STILL_RUNNING;
99 *out_error_code = 0; 126 *out_error_code = 0;
100 } 127 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 } 167 }
141 168
142 blink::WebCache::ResourceTypeStats Task::GetWebCacheStats() const { 169 blink::WebCache::ResourceTypeStats Task::GetWebCacheStats() const {
143 return blink::WebCache::ResourceTypeStats(); 170 return blink::WebCache::ResourceTypeStats();
144 } 171 }
145 172
146 int Task::GetKeepaliveCount() const { 173 int Task::GetKeepaliveCount() const {
147 return -1; 174 return -1;
148 } 175 }
149 176
177 // If either bytes have been sent or bytes have been read by the task
178 // the network has been used
ncarter (slow) 2017/06/14 20:20:58 I think this comment is probably better moved to i
cburn 2017/06/16 21:52:26 Deleted since we removed the -1 flag.
150 bool Task::ReportsNetworkUsage() const { 179 bool Task::ReportsNetworkUsage() const {
151 return network_usage_ != -1; 180 return cumulative_bytes_read_ != -1 || cumulative_bytes_sent_ != -1;
152 } 181 }
153 182
154 } // namespace task_manager 183 } // namespace task_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698