Chromium Code Reviews| 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 31c57a2efdc55e428a8deac2e4f9343f33fbcc30..e5e018b6ae1fd0848c05c0b947dad28c2f9ead10 100644 |
| --- a/sdk/lib/io/io_resource_info.dart |
| +++ b/sdk/lib/io/io_resource_info.dart |
| @@ -10,9 +10,9 @@ abstract class _IOResourceInfo { |
| String get name; |
| static int _count = 0; |
| - _IOResourceInfo(this.type) : id = _IOResourceInfo.getNextID(); |
| + static final Stopwatch _sw = new Stopwatch()..start(); |
| - String toJSON(); |
| + _IOResourceInfo(this.type) : id = _IOResourceInfo.getNextID(); |
| /// Get the full set of values for a specific implementation. This is normally |
| /// looked up based on an id from a referenceValueMap. |
| @@ -39,8 +39,8 @@ abstract class _ReadWriteResourceInfo extends _IOResourceInfo { |
| double lastRead; |
| double lastWrite; |
| - static final Stopwatch _sw = new Stopwatch()..start(); |
| - static double get timestamp => _sw.elapsedMicroseconds / 1000000.0; |
| + static double get timestamp => |
| + _IOResourceInfo._sw.elapsedMicroseconds / 1000000.0; |
|
Cutch
2015/09/10 16:49:41
All times reported over the service protocol shoul
ricow1
2015/09/14 07:01:17
I will change this in a follow up to be consistent
|
| // 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 |
| @@ -83,10 +83,6 @@ abstract class _ReadWriteResourceInfo extends _IOResourceInfo { |
| 'last_read': lastRead, |
| 'last_write': lastWrite |
| }; |
| - |
| - String toJSON() { |
| - return JSON.encode(fullValueMap); |
| - } |
| } |
| class _FileResourceInfo extends _ReadWriteResourceInfo { |
| @@ -141,6 +137,68 @@ class _FileResourceInfo extends _ReadWriteResourceInfo { |
| } |
| } |
| +class _ProcessResourceInfo extends _IOResourceInfo{ |
| + static const String TYPE = '_process'; |
| + final process; |
| + final double startedAt; |
| + |
| + static Map<int, _ProcessResourceInfo> startedProcesses = |
| + new Map<int, _ProcessResourceInfo>(); |
| + |
| + _ProcessResourceInfo(this.process) : |
| + startedAt = _IOResourceInfo._sw.elapsedMicroseconds / 1000000.0, |
|
Søren Gjesse
2015/09/10 17:43:35
This looks more like the current running time inst
ricow1
2015/09/14 07:01:17
done
|
| + super(TYPE) { |
| + ProcessStarted(this); |
| + } |
| + |
| + String get name => process._path; |
| + |
| + void stopped() => ProcessStopped(this); |
| + |
| + Map<String, String> get fullValueMap => |
| + { |
| + 'type': type, |
| + 'id': id, |
| + 'name': name, |
| + 'pid': process.pid, |
| + 'started_at': startedAt, |
| + 'arguments': process._arguments, |
| + 'working_directory': |
| + process._workingDirectory == null ? '.' : process._workingDirectory, |
| + }; |
| + |
| + static ProcessStarted(_ProcessResourceInfo info) { |
| + assert(!startedProcesses.containsKey(info.id)); |
| + startedProcesses[info.id] = info; |
| + } |
| + |
| + static ProcessStopped(_ProcessResourceInfo info) { |
| + assert(startedProcesses.containsKey(info.id)); |
| + startedProcesses.remove(info.id); |
| + } |
| + |
| + static Iterable<Map<String, String>> getStartedProcessesList() => |
| + new List.from(startedProcesses.values.map((e) => e.referenceValueMap)); |
| + |
| + static Future<ServiceExtensionResponse> getStartedProcesses( |
| + String function, Map<String, String> params) { |
| + assert(function == '__getStartedProcesses'); |
| + var data = {'type': '_startedprocesses', 'data': getStartedProcessesList()}; |
| + var json = JSON.encode(data); |
| + return new Future.value(new ServiceExtensionResponse.result(json)); |
| + } |
| + |
| + static Future<ServiceExtensionResponse> getProcessInfoMapById( |
| + String function, Map<String, String> params) { |
| + var id = int.parse(params['id']); |
| + var result = startedProcesses.containsKey(id) |
| + ? startedProcesses[id].fullValueMap |
| + : {}; |
| + var json = JSON.encode(result); |
| + return new Future.value(new ServiceExtensionResponse.result(json)); |
| + } |
| +} |
| + |
| class _SocketResourceInfo extends _ReadWriteResourceInfo { |
| static const String TCP_STRING = 'TCP'; |
| static const String UDP_STRING = 'UDP'; |