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

Side by Side 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: remove todo 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 unified diff | Download patch
« no previous file with comments | « sdk/lib/io/file_impl.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 }
OLDNEW
« 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