OLD | NEW |
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium OS 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 "src/procfs_byte_counter.h" | 5 #include "src/procfs_byte_counter.h" |
6 | 6 |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 | 8 |
9 #include <glog/logging.h> | 9 #include <glog/logging.h> |
10 | 10 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 } | 58 } |
59 | 59 |
60 const std::string& ProcfsByteCounter::GetInterface() const { | 60 const std::string& ProcfsByteCounter::GetInterface() const { |
61 return interface_; | 61 return interface_; |
62 } | 62 } |
63 | 63 |
64 uint64 ProcfsByteCounter::GetRxBytes() const { | 64 uint64 ProcfsByteCounter::GetRxBytes() const { |
65 return counter_rx_bytes_; | 65 return counter_rx_bytes_; |
66 } | 66 } |
67 | 67 |
| 68 void ProcfsByteCounter::SetRxBytes(uint64 rx_bytes) { |
| 69 DLOG(INFO) << interface_ << ": SetRxBytes: rx_bytes = " << rx_bytes; |
| 70 counter_rx_bytes_ = rx_bytes; |
| 71 } |
| 72 |
68 uint64 ProcfsByteCounter::GetTxBytes() const { | 73 uint64 ProcfsByteCounter::GetTxBytes() const { |
69 return counter_tx_bytes_; | 74 return counter_tx_bytes_; |
70 } | 75 } |
71 | 76 |
| 77 void ProcfsByteCounter::SetTxBytes(uint64 tx_bytes) { |
| 78 DLOG(INFO) << interface_ << ": SetTxBytes: tx_bytes = " << tx_bytes; |
| 79 counter_tx_bytes_ = tx_bytes; |
| 80 } |
| 81 |
72 void ProcfsByteCounter::SetDelegate(ByteCounterDelegate *delegate) { | 82 void ProcfsByteCounter::SetDelegate(ByteCounterDelegate *delegate) { |
73 DLOG(INFO) << interface_ << ": SetDelegate"; | 83 DLOG(INFO) << interface_ << ": SetDelegate"; |
74 delegate_ = delegate; | 84 delegate_ = delegate; |
75 } | 85 } |
76 | 86 |
77 // private methods | 87 // private methods |
78 | 88 |
79 bool ProcfsByteCounter::OpenProcNetDev() { | 89 bool ProcfsByteCounter::OpenProcNetDev() { |
80 DCHECK(proc_net_dev_fp_ == NULL); | 90 DCHECK(proc_net_dev_fp_ == NULL); |
81 if ((proc_net_dev_fp_ = fopen(kProcNetDevPath, "r")) == NULL) { | 91 if ((proc_net_dev_fp_ = fopen(kProcNetDevPath, "r")) == NULL) { |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 baseline_initialized_ = true; | 228 baseline_initialized_ = true; |
219 } | 229 } |
220 // We update the baseline on each new sample so that we aren't confused about | 230 // We update the baseline on each new sample so that we aren't confused about |
221 // how many times the device counter has wrapped around since we've started. | 231 // how many times the device counter has wrapped around since we've started. |
222 // This works as long as the sample interval is short enough to prevent wrap | 232 // This works as long as the sample interval is short enough to prevent wrap |
223 // around between consecutive samples. | 233 // around between consecutive samples. |
224 baseline_stats_ = stats; | 234 baseline_stats_ = stats; |
225 } | 235 } |
226 | 236 |
227 } // namespace cashew | 237 } // namespace cashew |
OLD | NEW |