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

Unified Diff: sdk/lib/io/io_resource_info.dart

Issue 1320023008: Refactor the io resource classes (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: address comments Created 5 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/io/file_impl.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..31c57a2efdc55e428a8deac2e4f9343f33fbcc30 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,29 @@ 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() => addRead(0);
+
+ void addWrite(int bytes) {
+ totalWritten += bytes;
+ writeCount++;
+ lastWrite = timestamp;
+ }
+
_ReadWriteResourceInfo(String type) :
totalRead = 0,
totalWritten = 0,
« no previous file with comments | « sdk/lib/io/file_impl.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698