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() { | |
Søren Gjesse
2015/09/09 07:12:21
Maybe just implement like this:
void didRead() =>
ricow1
2015/09/09 07:14:24
Done.
| |
58 readCount++; | |
59 lastRead = timestamp; | |
60 } | |
61 | |
62 void addWrite(int bytes) { | |
63 totalWritten += bytes; | |
64 writeCount++; | |
65 lastWrite = timestamp; | |
66 } | |
67 | |
45 _ReadWriteResourceInfo(String type) : | 68 _ReadWriteResourceInfo(String type) : |
46 totalRead = 0, | 69 totalRead = 0, |
47 totalWritten = 0, | 70 totalWritten = 0, |
48 readCount = 0, | 71 readCount = 0, |
49 writeCount = 0, | 72 writeCount = 0, |
50 lastRead = 0.0, | 73 lastRead = 0.0, |
51 lastWrite = 0.0, | 74 lastWrite = 0.0, |
52 super(type); | 75 super(type); |
53 | 76 |
54 Map<String, String> get fullValueMap => | 77 Map<String, String> get fullValueMap => |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
196 assert(!openSockets.containsKey(info.id)); | 219 assert(!openSockets.containsKey(info.id)); |
197 openSockets[info.id] = info; | 220 openSockets[info.id] = info; |
198 } | 221 } |
199 | 222 |
200 static SocketClosed(_SocketResourceInfo info) { | 223 static SocketClosed(_SocketResourceInfo info) { |
201 assert(openSockets.containsKey(info.id)); | 224 assert(openSockets.containsKey(info.id)); |
202 openSockets.remove(info.id); | 225 openSockets.remove(info.id); |
203 } | 226 } |
204 | 227 |
205 } | 228 } |
OLD | NEW |