| 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; |
| 11 static int _count = 0; | 11 static int _count = 0; |
| 12 | 12 |
| 13 static final Stopwatch _sw = new Stopwatch()..start(); | 13 static final Stopwatch _sw = new Stopwatch()..start(); |
| 14 static final _startTime = new DateTime.now().millisecondsSinceEpoch; |
| 15 |
| 16 static double get timestamp => _startTime + _sw.elapsedMicroseconds/1000; |
| 14 | 17 |
| 15 _IOResourceInfo(this.type) : id = _IOResourceInfo.getNextID(); | 18 _IOResourceInfo(this.type) : id = _IOResourceInfo.getNextID(); |
| 16 | 19 |
| 17 /// Get the full set of values for a specific implementation. This is normally | 20 /// Get the full set of values for a specific implementation. This is normally |
| 18 /// looked up based on an id from a referenceValueMap. | 21 /// looked up based on an id from a referenceValueMap. |
| 19 Map<String, String> get fullValueMap; | 22 Map<String, String> get fullValueMap; |
| 20 | 23 |
| 21 /// The reference map, used to return a list of values, e.g., getting | 24 /// The reference map, used to return a list of values, e.g., getting |
| 22 /// all open sockets. The structure of this is shared among all subclasses. | 25 /// all open sockets. The structure of this is shared among all subclasses. |
| 23 Map<String, String> get referenceValueMap => | 26 Map<String, String> get referenceValueMap => |
| 24 { | 27 { |
| 25 // The type for a reference object is prefixed with @ in observatory. | 28 // The type for a reference object is prefixed with @ in observatory. |
| 26 'type': '@$type', | 29 'type': '@$type', |
| 27 'id': id, | 30 'id': id, |
| 28 'name': name, | 31 'name': name, |
| 29 }; | 32 }; |
| 30 | 33 |
| 31 static int getNextID() => _count++; | 34 static int getNextID() => _count++; |
| 32 } | 35 } |
| 33 | 36 |
| 34 abstract class _ReadWriteResourceInfo extends _IOResourceInfo { | 37 abstract class _ReadWriteResourceInfo extends _IOResourceInfo { |
| 35 int totalRead; | 38 int totalRead; |
| 36 int totalWritten; | 39 int totalWritten; |
| 37 int readCount; | 40 int readCount; |
| 38 int writeCount; | 41 int writeCount; |
| 39 double lastRead; | 42 double lastRead; |
| 40 double lastWrite; | 43 double lastWrite; |
| 41 | 44 |
| 42 static double get timestamp => | |
| 43 _IOResourceInfo._sw.elapsedMicroseconds / 1000000.0; | |
| 44 | |
| 45 // Not all call sites use this. In some cases, e.g., a socket, a read does | 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 | 46 // not always mean that we actually read some bytes (we may do a read to see |
| 47 // if there are some bytes available). | 47 // if there are some bytes available). |
| 48 void addRead(int bytes) { | 48 void addRead(int bytes) { |
| 49 totalRead += bytes; | 49 totalRead += bytes; |
| 50 readCount++; | 50 readCount++; |
| 51 lastRead = timestamp; | 51 lastRead = _IOResourceInfo.timestamp; |
| 52 } | 52 } |
| 53 | 53 |
| 54 // In cases where we read but did not neccesarily get any bytes, use this to | 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 | 55 // update the readCount and timestamp. Manually update totalRead if any bytes |
| 56 // where acutally read. | 56 // where acutally read. |
| 57 void didRead() => addRead(0); | 57 void didRead() => addRead(0); |
| 58 | 58 |
| 59 void addWrite(int bytes) { | 59 void addWrite(int bytes) { |
| 60 totalWritten += bytes; | 60 totalWritten += bytes; |
| 61 writeCount++; | 61 writeCount++; |
| 62 lastWrite = timestamp; | 62 lastWrite = _IOResourceInfo.timestamp; |
| 63 } | 63 } |
| 64 | 64 |
| 65 _ReadWriteResourceInfo(String type) : | 65 _ReadWriteResourceInfo(String type) : |
| 66 totalRead = 0, | 66 totalRead = 0, |
| 67 totalWritten = 0, | 67 totalWritten = 0, |
| 68 readCount = 0, | 68 readCount = 0, |
| 69 writeCount = 0, | 69 writeCount = 0, |
| 70 lastRead = 0.0, | 70 lastRead = 0.0, |
| 71 lastWrite = 0.0, | 71 lastWrite = 0.0, |
| 72 super(type); | 72 super(type); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 } | 133 } |
| 134 | 134 |
| 135 String get name { | 135 String get name { |
| 136 return '${file.path}'; | 136 return '${file.path}'; |
| 137 } | 137 } |
| 138 } | 138 } |
| 139 | 139 |
| 140 class _ProcessResourceInfo extends _IOResourceInfo{ | 140 class _ProcessResourceInfo extends _IOResourceInfo{ |
| 141 static const String TYPE = '_process'; | 141 static const String TYPE = '_process'; |
| 142 final process; | 142 final process; |
| 143 final int startedAt; | 143 final double startedAt; |
| 144 | 144 |
| 145 static Map<int, _ProcessResourceInfo> startedProcesses = | 145 static Map<int, _ProcessResourceInfo> startedProcesses = |
| 146 new Map<int, _ProcessResourceInfo>(); | 146 new Map<int, _ProcessResourceInfo>(); |
| 147 | 147 |
| 148 _ProcessResourceInfo(this.process) : | 148 _ProcessResourceInfo(this.process) : |
| 149 startedAt = new DateTime.now().millisecondsSinceEpoch, | 149 startedAt = _IOResourceInfo.timestamp, |
| 150 super(TYPE) { | 150 super(TYPE) { |
| 151 ProcessStarted(this); | 151 ProcessStarted(this); |
| 152 } | 152 } |
| 153 | 153 |
| 154 String get name => process._path; | 154 String get name => process._path; |
| 155 | 155 |
| 156 void stopped() => ProcessStopped(this); | 156 void stopped() => ProcessStopped(this); |
| 157 | 157 |
| 158 Map<String, String> get fullValueMap => | 158 Map<String, String> get fullValueMap => |
| 159 { | 159 { |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 assert(!openSockets.containsKey(info.id)); | 274 assert(!openSockets.containsKey(info.id)); |
| 275 openSockets[info.id] = info; | 275 openSockets[info.id] = info; |
| 276 } | 276 } |
| 277 | 277 |
| 278 static SocketClosed(_SocketResourceInfo info) { | 278 static SocketClosed(_SocketResourceInfo info) { |
| 279 assert(openSockets.containsKey(info.id)); | 279 assert(openSockets.containsKey(info.id)); |
| 280 openSockets.remove(info.id); | 280 openSockets.remove(info.id); |
| 281 } | 281 } |
| 282 | 282 |
| 283 } | 283 } |
| OLD | NEW |