Chromium Code Reviews| Index: sdk/lib/io/io_resource_info.dart |
| diff --git a/sdk/lib/io/io_resource_info.dart b/sdk/lib/io/io_resource_info.dart |
| index 8c30c646995627e7bead00ebca152a04ef2a87a1..d5aa539b921bde881f481c59d41d073527b754d6 100644 |
| --- a/sdk/lib/io/io_resource_info.dart |
| +++ b/sdk/lib/io/io_resource_info.dart |
| @@ -31,9 +31,6 @@ abstract class _IOResourceInfo { |
| static int getNextID() => _count++; |
| } |
| -// TODO(ricow): Move stopwatch into this class and use it for both files |
| -// and sockets (by using setters on totalRead/totalWritten). Also, consider |
| -// setting readCount and writeCount in those setters. |
| abstract class _ReadWriteResourceInfo extends _IOResourceInfo { |
| int totalRead; |
| int totalWritten; |
| @@ -42,6 +39,32 @@ abstract class _ReadWriteResourceInfo extends _IOResourceInfo { |
| double lastRead; |
| double lastWrite; |
| + static final Stopwatch _sw = new Stopwatch()..start(); |
| + static double get timestamp => _sw.elapsedMicroseconds / 1000000.0; |
| + |
| + // Not all call sites use this. In some cases, e.g., a socket, a read does |
| + // not always mean that we actually read some bytes (we may do a read to see |
| + // if there are some bytes available). |
| + void addRead(int bytes) { |
| + totalRead += bytes; |
| + readCount++; |
| + lastRead = timestamp; |
| + } |
| + |
| + // In cases where we read but did not neccesarily get any bytes, use this to |
| + // update the readCount and timestamp. Manually update totalRead if any bytes |
| + // where acutally read. |
| + void didRead() { |
|
Søren Gjesse
2015/09/09 07:12:21
Maybe just implement like this:
void didRead() =>
ricow1
2015/09/09 07:14:24
Done.
|
| + readCount++; |
| + lastRead = timestamp; |
| + } |
| + |
| + void addWrite(int bytes) { |
| + totalWritten += bytes; |
| + writeCount++; |
| + lastWrite = timestamp; |
| + } |
| + |
| _ReadWriteResourceInfo(String type) : |
| totalRead = 0, |
| totalWritten = 0, |