| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of dart.io; | 5 part of dart.io; |
| 6 | 6 |
| 7 abstract class _IOResourceInfo { | 7 abstract class _IOResourceInfo { |
| 8 final String type; | 8 final String type; |
| 9 final int id; | 9 final int id; |
| 10 String get name; | 10 String get name; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 { | 24 { |
| 25 // The type for a reference object is prefixed with @ in observatory. | 25 // The type for a reference object is prefixed with @ in observatory. |
| 26 'type': '@$type', | 26 'type': '@$type', |
| 27 'id': id, | 27 'id': id, |
| 28 'name': name, | 28 'name': name, |
| 29 }; | 29 }; |
| 30 | 30 |
| 31 static int getNextID() => _count++; | 31 static int getNextID() => _count++; |
| 32 } | 32 } |
| 33 | 33 |
| 34 // TODO(ricow): Move stopwatch into this class and use it for both files | |
| 35 // and sockets (by using setters on totalRead/totalWritten). Also, consider | |
| 36 // setting readCount and writeCount in those setters. | |
| 37 abstract class _ReadWriteResourceInfo extends _IOResourceInfo { | 34 abstract class _ReadWriteResourceInfo extends _IOResourceInfo { |
| 38 int totalRead; | 35 int totalRead; |
| 39 int totalWritten; | 36 int totalWritten; |
| 40 int readCount; | 37 int readCount; |
| 41 int writeCount; | 38 int writeCount; |
| 42 double lastRead; | 39 double lastRead; |
| 43 double lastWrite; | 40 double lastWrite; |
| 44 | 41 |
| 42 static final Stopwatch _sw = new Stopwatch()..start(); |
| 43 static double get timestamp => _sw.elapsedMicroseconds / 1000000.0; |
| 44 |
| 45 // Not all call sites use this. In some cases, e.g., a socket, a read does |
| 46 // not always mean that we actually read some bytes (we may do a read to see |
| 47 // if there are some bytes available). |
| 48 void addRead(int bytes) { |
| 49 totalRead += bytes; |
| 50 readCount++; |
| 51 lastRead = timestamp; |
| 52 } |
| 53 |
| 54 // In cases where we read but did not neccesarily get any bytes, use this to |
| 55 // update the readCount and timestamp. Manually update totalRead if any bytes |
| 56 // where acutally read. |
| 57 void didRead() => addRead(0); |
| 58 |
| 59 void addWrite(int bytes) { |
| 60 totalWritten += bytes; |
| 61 writeCount++; |
| 62 lastWrite = timestamp; |
| 63 } |
| 64 |
| 45 _ReadWriteResourceInfo(String type) : | 65 _ReadWriteResourceInfo(String type) : |
| 46 totalRead = 0, | 66 totalRead = 0, |
| 47 totalWritten = 0, | 67 totalWritten = 0, |
| 48 readCount = 0, | 68 readCount = 0, |
| 49 writeCount = 0, | 69 writeCount = 0, |
| 50 lastRead = 0.0, | 70 lastRead = 0.0, |
| 51 lastWrite = 0.0, | 71 lastWrite = 0.0, |
| 52 super(type); | 72 super(type); |
| 53 | 73 |
| 54 Map<String, String> get fullValueMap => | 74 Map<String, String> get fullValueMap => |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 assert(!openSockets.containsKey(info.id)); | 216 assert(!openSockets.containsKey(info.id)); |
| 197 openSockets[info.id] = info; | 217 openSockets[info.id] = info; |
| 198 } | 218 } |
| 199 | 219 |
| 200 static SocketClosed(_SocketResourceInfo info) { | 220 static SocketClosed(_SocketResourceInfo info) { |
| 201 assert(openSockets.containsKey(info.id)); | 221 assert(openSockets.containsKey(info.id)); |
| 202 openSockets.remove(info.id); | 222 openSockets.remove(info.id); |
| 203 } | 223 } |
| 204 | 224 |
| 205 } | 225 } |
| OLD | NEW |