Index: chrome/browser/task_manager/providers/task.cc |
diff --git a/chrome/browser/task_manager/providers/task.cc b/chrome/browser/task_manager/providers/task.cc |
index a49032f6875cd6612cc2777b5606b34ff56d9356..950c958f4959d4299a1b143d08415ca121886b66 100644 |
--- a/chrome/browser/task_manager/providers/task.cc |
+++ b/chrome/browser/task_manager/providers/task.cc |
@@ -30,8 +30,12 @@ Task::Task(const base::string16& title, |
base::ProcessHandle handle, |
base::ProcessId process_id) |
: task_id_(g_last_id++), |
- network_usage_(-1), |
- current_byte_count_(-1), |
+ last_refresh_cumulative_bytes_sent_(0), |
+ last_refresh_cumulative_bytes_read_(0), |
+ 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
|
+ cumulative_bytes_read_(-1), |
+ network_sent_rate_(0), |
+ network_read_rate_(0), |
title_(title), |
rappor_sample_name_(rappor_sample), |
icon_(icon ? *icon : gfx::ImageSkia()), |
@@ -73,21 +77,44 @@ void Task::Refresh(const base::TimeDelta& update_interval, |
if ((refresh_flags & REFRESH_TYPE_NETWORK_USAGE) == 0) |
return; |
- if (current_byte_count_ == -1) |
+ if (cumulative_bytes_sent_ == -1 && cumulative_bytes_read_ == -1) |
return; |
- network_usage_ = |
- (current_byte_count_ * base::TimeDelta::FromSeconds(1)) / update_interval; |
+ int64_t current_cycle_read_byte_count = |
+ cumulative_bytes_read_ - last_refresh_cumulative_bytes_read_; |
+ network_read_rate_ = 0; |
+ if (cumulative_bytes_read_ != -1) { |
+ network_read_rate_ = |
+ (current_cycle_read_byte_count * base::TimeDelta::FromSeconds(1)) / |
+ update_interval; |
+ } |
- // Reset the current byte count for this task. |
- current_byte_count_ = 0; |
+ int64_t current_cycle_sent_byte_count = |
+ cumulative_bytes_sent_ - last_refresh_cumulative_bytes_sent_; |
+ network_sent_rate_ = 0; |
+ if (cumulative_bytes_sent_ != -1) { |
+ network_sent_rate_ = |
+ (current_cycle_sent_byte_count * base::TimeDelta::FromSeconds(1)) / |
+ update_interval; |
+ } |
+ last_refresh_cumulative_bytes_read_ = cumulative_bytes_read_; |
+ last_refresh_cumulative_bytes_sent_ = cumulative_bytes_sent_; |
} |
void Task::OnNetworkBytesRead(int64_t bytes_read) { |
- if (current_byte_count_ == -1) |
- current_byte_count_ = 0; |
+ if (cumulative_bytes_read_ == -1) { |
+ cumulative_bytes_read_ = 0; |
+ } |
+ |
+ cumulative_bytes_read_ += bytes_read; |
+} |
+ |
+void Task::OnNetworkBytesSent(int64_t bytes_sent) { |
+ if (cumulative_bytes_sent_ == -1) { |
+ cumulative_bytes_sent_ = 0; |
+ } |
- current_byte_count_ += bytes_read; |
+ cumulative_bytes_sent_ += bytes_sent; |
} |
void Task::GetTerminationStatus(base::TerminationStatus* out_status, |
@@ -147,8 +174,10 @@ int Task::GetKeepaliveCount() const { |
return -1; |
} |
+// If either bytes have been sent or bytes have been read by the task |
+// 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.
|
bool Task::ReportsNetworkUsage() const { |
- return network_usage_ != -1; |
+ return cumulative_bytes_read_ != -1 || cumulative_bytes_sent_ != -1; |
} |
} // namespace task_manager |