| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 service; | 5 part of service; |
| 6 | 6 |
| 7 /// A [ServiceObject] is an object known to the VM service and is tied | 7 /// A [ServiceObject] is an object known to the VM service and is tied |
| 8 /// to an owning [Isolate]. | 8 /// to an owning [Isolate]. |
| 9 abstract class ServiceObject extends Observable { | 9 abstract class ServiceObject extends Observable { |
| 10 /// The owner of this [ServiceObject]. This can be an [Isolate], a | 10 /// The owner of this [ServiceObject]. This can be an [Isolate], a |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 break; | 81 break; |
| 82 case 'ServiceError': | 82 case 'ServiceError': |
| 83 obj = new ServiceError._empty(owner); | 83 obj = new ServiceError._empty(owner); |
| 84 break; | 84 break; |
| 85 case 'ServiceException': | 85 case 'ServiceException': |
| 86 obj = new ServiceException._empty(owner); | 86 obj = new ServiceException._empty(owner); |
| 87 break; | 87 break; |
| 88 case 'Script': | 88 case 'Script': |
| 89 obj = new Script._empty(owner); | 89 obj = new Script._empty(owner); |
| 90 break; | 90 break; |
| 91 case 'Socket': |
| 92 obj = new Socket._empty(owner); |
| 93 break; |
| 91 default: | 94 default: |
| 92 obj = new ServiceMap._empty(owner); | 95 obj = new ServiceMap._empty(owner); |
| 93 } | 96 } |
| 94 obj.update(map); | 97 obj.update(map); |
| 95 return obj; | 98 return obj; |
| 96 } | 99 } |
| 97 | 100 |
| 98 /// If [this] was created from a reference, load the full object | 101 /// If [this] was created from a reference, load the full object |
| 99 /// from the service by calling [reload]. Else, return [this]. | 102 /// from the service by calling [reload]. Else, return [this]. |
| 100 Future<ServiceObject> load() { | 103 Future<ServiceObject> load() { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 } | 165 } |
| 163 | 166 |
| 164 abstract class ServiceObjectOwner extends ServiceObject { | 167 abstract class ServiceObjectOwner extends ServiceObject { |
| 165 /// Creates an empty [ServiceObjectOwner]. | 168 /// Creates an empty [ServiceObjectOwner]. |
| 166 ServiceObjectOwner._empty(ServiceObjectOwner owner) : super._empty(owner); | 169 ServiceObjectOwner._empty(ServiceObjectOwner owner) : super._empty(owner); |
| 167 | 170 |
| 168 /// Builds a [ServiceObject] corresponding to the [id] from [map]. | 171 /// Builds a [ServiceObject] corresponding to the [id] from [map]. |
| 169 /// The result may come from the cache. The result will not necessarily | 172 /// The result may come from the cache. The result will not necessarily |
| 170 /// be [loaded]. | 173 /// be [loaded]. |
| 171 ServiceObject getFromMap(ObservableMap map); | 174 ServiceObject getFromMap(ObservableMap map); |
| 175 |
| 176 /// Creates a link to [id] relative to [this]. |
| 177 String relativeLink(String id); |
| 172 } | 178 } |
| 173 | 179 |
| 174 /// State for a VM being inspected. | 180 /// State for a VM being inspected. |
| 175 abstract class VM extends ServiceObjectOwner { | 181 abstract class VM extends ServiceObjectOwner { |
| 176 @reflectable VM get vm => this; | 182 @reflectable VM get vm => this; |
| 177 @reflectable Isolate get isolate => null; | 183 @reflectable Isolate get isolate => null; |
| 178 | 184 |
| 179 @reflectable Iterable<Isolate> get isolates => _isolateCache.values; | 185 @reflectable Iterable<Isolate> get isolates => _isolateCache.values; |
| 180 | 186 |
| 181 @reflectable String get link => '$id'; | 187 @reflectable String get link => '$id'; |
| (...skipping 1288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1470 if (caller.code == code) { | 1476 if (caller.code == code) { |
| 1471 return caller.count; | 1477 return caller.count; |
| 1472 } | 1478 } |
| 1473 } | 1479 } |
| 1474 return 0; | 1480 return 0; |
| 1475 } | 1481 } |
| 1476 | 1482 |
| 1477 @reflectable bool get isDartCode => kind == CodeKind.Dart; | 1483 @reflectable bool get isDartCode => kind == CodeKind.Dart; |
| 1478 } | 1484 } |
| 1479 | 1485 |
| 1486 |
| 1487 class SocketKind { |
| 1488 final _value; |
| 1489 const SocketKind._internal(this._value); |
| 1490 String toString() => '$_value'; |
| 1491 |
| 1492 static SocketKind fromString(String s) { |
| 1493 if (s == 'Listening') { |
| 1494 return Listening; |
| 1495 } else if (s == 'Normal') { |
| 1496 return Normal; |
| 1497 } else if (s == 'Pipe') { |
| 1498 return Pipe; |
| 1499 } else if (s == 'Internal') { |
| 1500 return Internal; |
| 1501 } |
| 1502 Logger.root.warning('Unknown socket kind $s'); |
| 1503 throw new FallThroughError(); |
| 1504 } |
| 1505 static const Listening = const SocketKind._internal('Listening'); |
| 1506 static const Normal = const SocketKind._internal('Normal'); |
| 1507 static const Pipe = const SocketKind._internal('Pipe'); |
| 1508 static const Internal = const SocketKind._internal('Internal'); |
| 1509 } |
| 1510 |
| 1511 /// A snapshot of statistics associated with a [Socket]. |
| 1512 class SocketStats { |
| 1513 @reflectable final int bytesRead; |
| 1514 @reflectable final int bytesWritten; |
| 1515 @reflectable final int readCalls; |
| 1516 @reflectable final int writeCalls; |
| 1517 @reflectable final int available; |
| 1518 |
| 1519 SocketStats(this.bytesRead, this.bytesWritten, |
| 1520 this.readCalls, this.writeCalls, |
| 1521 this.available); |
| 1522 } |
| 1523 |
| 1524 /// A peer to a Socket in dart:io. Sockets can represent network sockets or |
| 1525 /// OS pipes. Each socket is owned by another ServceObject, for example, |
| 1526 /// a process or an HTTP server. |
| 1527 class Socket extends ServiceObject { |
| 1528 Socket._empty(ServiceObjectOwner owner) : super._empty(owner); |
| 1529 |
| 1530 bool get canCache => true; |
| 1531 |
| 1532 ServiceObject socketOwner; |
| 1533 |
| 1534 @reflectable bool get isPipe => (kind == SocketKind.Pipe); |
| 1535 |
| 1536 @observable SocketStats latest; |
| 1537 @observable SocketStats previous; |
| 1538 |
| 1539 @observable SocketKind kind; |
| 1540 |
| 1541 @observable String protocol = ''; |
| 1542 |
| 1543 @observable bool readClosed = false; |
| 1544 @observable bool writeClosed = false; |
| 1545 @observable bool closing = false; |
| 1546 |
| 1547 /// Listening for connections. |
| 1548 @observable bool listening = false; |
| 1549 |
| 1550 @observable int fd; |
| 1551 |
| 1552 @observable String localAddress; |
| 1553 @observable int localPort; |
| 1554 @observable String remoteAddress; |
| 1555 @observable int remotePort; |
| 1556 |
| 1557 // Updates internal state from [map]. [map] can be a reference. |
| 1558 void _update(ObservableMap map, bool mapIsRef) { |
| 1559 name = map['name']; |
| 1560 vmName = map['name']; |
| 1561 |
| 1562 kind = SocketKind.fromString(map['kind']); |
| 1563 |
| 1564 if (mapIsRef) { |
| 1565 return; |
| 1566 } |
| 1567 |
| 1568 _loaded = true; |
| 1569 |
| 1570 _upgradeCollection(map, isolate); |
| 1571 |
| 1572 readClosed = map['readClosed']; |
| 1573 writeClosed = map['writeClosed']; |
| 1574 closing = map['closing']; |
| 1575 listening = map['listening']; |
| 1576 |
| 1577 protocol = map['protocol']; |
| 1578 |
| 1579 localAddress = map['localAddress']; |
| 1580 localPort = map['localPort']; |
| 1581 remoteAddress = map['remoteAddress']; |
| 1582 remotePort = map['remotePort']; |
| 1583 |
| 1584 fd = map['fd']; |
| 1585 socketOwner = map['owner']; |
| 1586 } |
| 1587 } |
| 1588 |
| 1480 // Returns true if [map] is a service map. i.e. it has the following keys: | 1589 // Returns true if [map] is a service map. i.e. it has the following keys: |
| 1481 // 'id' and a 'type'. | 1590 // 'id' and a 'type'. |
| 1482 bool _isServiceMap(ObservableMap m) { | 1591 bool _isServiceMap(ObservableMap m) { |
| 1483 return (m != null) && (m['id'] != null) && (m['type'] != null); | 1592 return (m != null) && (m['id'] != null) && (m['type'] != null); |
| 1484 } | 1593 } |
| 1485 | 1594 |
| 1486 bool _hasRef(String type) => type.startsWith('@'); | 1595 bool _hasRef(String type) => type.startsWith('@'); |
| 1487 String _stripRef(String type) => (_hasRef(type) ? type.substring(1) : type); | 1596 String _stripRef(String type) => (_hasRef(type) ? type.substring(1) : type); |
| 1488 | 1597 |
| 1489 /// Recursively upgrades all [ServiceObject]s inside [collection] which must | 1598 /// Recursively upgrades all [ServiceObject]s inside [collection] which must |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1517 var v = list[i]; | 1626 var v = list[i]; |
| 1518 if ((v is ObservableMap) && _isServiceMap(v)) { | 1627 if ((v is ObservableMap) && _isServiceMap(v)) { |
| 1519 list[i] = owner.getFromMap(v); | 1628 list[i] = owner.getFromMap(v); |
| 1520 } else if (v is ObservableList) { | 1629 } else if (v is ObservableList) { |
| 1521 _upgradeObservableList(v, owner); | 1630 _upgradeObservableList(v, owner); |
| 1522 } else if (v is ObservableMap) { | 1631 } else if (v is ObservableMap) { |
| 1523 _upgradeObservableMap(v, owner); | 1632 _upgradeObservableMap(v, owner); |
| 1524 } | 1633 } |
| 1525 } | 1634 } |
| 1526 } | 1635 } |
| OLD | NEW |