| 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 // Some value smaller than the object ring, so requesting a large array | 7 // Some value smaller than the object ring, so requesting a large array |
| 8 // doesn't result in an expired ref because the elements lapped it in the | 8 // doesn't result in an expired ref because the elements lapped it in the |
| 9 // object ring. | 9 // object ring. |
| 10 const int kDefaultFieldLimit = 100; | 10 const int kDefaultFieldLimit = 100; |
| (...skipping 4215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4226 localAddress = map['localAddress']; | 4226 localAddress = map['localAddress']; |
| 4227 localPort = map['localPort']; | 4227 localPort = map['localPort']; |
| 4228 remoteAddress = map['remoteAddress']; | 4228 remoteAddress = map['remoteAddress']; |
| 4229 remotePort = map['remotePort']; | 4229 remotePort = map['remotePort']; |
| 4230 | 4230 |
| 4231 fd = map['fd']; | 4231 fd = map['fd']; |
| 4232 socketOwner = map['owner']; | 4232 socketOwner = map['owner']; |
| 4233 } | 4233 } |
| 4234 } | 4234 } |
| 4235 | 4235 |
| 4236 class MetricSample { | 4236 class ServiceMetric extends ServiceObject implements M.Metric { |
| 4237 final double value; | |
| 4238 final DateTime time; | |
| 4239 MetricSample(this.value) : time = new DateTime.now(); | |
| 4240 } | |
| 4241 | |
| 4242 class ServiceMetric extends ServiceObject { | |
| 4243 ServiceMetric._empty(ServiceObjectOwner owner) : super._empty(owner) { | 4237 ServiceMetric._empty(ServiceObjectOwner owner) : super._empty(owner) { |
| 4244 } | 4238 } |
| 4245 | 4239 |
| 4246 bool get immutable => false; | 4240 bool get immutable => false; |
| 4247 | 4241 |
| 4248 @observable bool recording = false; | |
| 4249 MetricPoller poller; | |
| 4250 | |
| 4251 final ObservableList<MetricSample> samples = | |
| 4252 new ObservableList<MetricSample>(); | |
| 4253 int _sampleBufferSize = 100; | |
| 4254 int get sampleBufferSize => _sampleBufferSize; | |
| 4255 set sampleBufferSize(int size) { | |
| 4256 _sampleBufferSize = size; | |
| 4257 _removeOld(); | |
| 4258 } | |
| 4259 | |
| 4260 Future<ObservableMap> _fetchDirect({int count: kDefaultFieldLimit}) { | 4242 Future<ObservableMap> _fetchDirect({int count: kDefaultFieldLimit}) { |
| 4261 assert(owner is Isolate); | 4243 assert(owner is Isolate); |
| 4262 return isolate.invokeRpcNoUpgrade('_getIsolateMetric', { 'metricId': id }); | 4244 return isolate.invokeRpcNoUpgrade('_getIsolateMetric', { 'metricId': id }); |
| 4263 } | 4245 } |
| 4264 | 4246 |
| 4265 | |
| 4266 void addSample(MetricSample sample) { | |
| 4267 samples.add(sample); | |
| 4268 _removeOld(); | |
| 4269 } | |
| 4270 | |
| 4271 void _removeOld() { | |
| 4272 // TODO(johnmccutchan): If this becomes hot, consider using a circular | |
| 4273 // buffer. | |
| 4274 if (samples.length > _sampleBufferSize) { | |
| 4275 int count = samples.length - _sampleBufferSize; | |
| 4276 samples.removeRange(0, count); | |
| 4277 } | |
| 4278 } | |
| 4279 | |
| 4280 @observable String description; | 4247 @observable String description; |
| 4281 @observable double value = 0.0; | 4248 @observable double value = 0.0; |
| 4282 // Only a guage has a non-null min and max. | 4249 // Only a guage has a non-null min and max. |
| 4283 @observable double min; | 4250 @observable double min; |
| 4284 @observable double max; | 4251 @observable double max; |
| 4285 | 4252 |
| 4286 bool get isGauge => (min != null) && (max != null); | 4253 bool get isGauge => (min != null) && (max != null); |
| 4287 | 4254 |
| 4288 void _update(ObservableMap map, bool mapIsRef) { | 4255 void _update(ObservableMap map, bool mapIsRef) { |
| 4289 name = map['name']; | 4256 name = map['name']; |
| 4290 description = map['description']; | 4257 description = map['description']; |
| 4291 vmName = map['name']; | 4258 vmName = map['name']; |
| 4292 value = map['value']; | 4259 value = map['value']; |
| 4293 min = map['min']; | 4260 min = map['min']; |
| 4294 max = map['max']; | 4261 max = map['max']; |
| 4295 } | 4262 } |
| 4296 | 4263 |
| 4297 String toString() => "ServiceMetric($_id)"; | 4264 String toString() => "ServiceMetric($_id)"; |
| 4298 } | 4265 } |
| 4299 | 4266 |
| 4300 class MetricPoller { | |
| 4301 // Metrics to be polled. | |
| 4302 final List<ServiceMetric> metrics = new List<ServiceMetric>(); | |
| 4303 final Duration pollPeriod; | |
| 4304 Timer _pollTimer; | |
| 4305 | |
| 4306 MetricPoller(int milliseconds) : | |
| 4307 pollPeriod = new Duration(milliseconds: milliseconds) { | |
| 4308 start(); | |
| 4309 } | |
| 4310 | |
| 4311 void start() { | |
| 4312 _pollTimer = new Timer.periodic(pollPeriod, _onPoll); | |
| 4313 } | |
| 4314 | |
| 4315 void cancel() { | |
| 4316 if (_pollTimer != null) { | |
| 4317 _pollTimer.cancel(); | |
| 4318 } | |
| 4319 _pollTimer = null; | |
| 4320 } | |
| 4321 | |
| 4322 void _onPoll(_) { | |
| 4323 // Reload metrics and add a sample to each. | |
| 4324 for (var metric in metrics) { | |
| 4325 metric.reload().then((m) { | |
| 4326 m.addSample(new MetricSample(m.value)); | |
| 4327 }); | |
| 4328 } | |
| 4329 } | |
| 4330 } | |
| 4331 | |
| 4332 class Frame extends ServiceObject implements M.Frame { | 4267 class Frame extends ServiceObject implements M.Frame { |
| 4333 @observable int index; | 4268 @observable int index; |
| 4334 @observable ServiceFunction function; | 4269 @observable ServiceFunction function; |
| 4335 @observable SourceLocation location; | 4270 @observable SourceLocation location; |
| 4336 @observable Code code; | 4271 @observable Code code; |
| 4337 @observable List<ServiceMap> variables = new ObservableList<ServiceMap>(); | 4272 @observable List<ServiceMap> variables = new ObservableList<ServiceMap>(); |
| 4338 | 4273 |
| 4339 Frame._empty(ServiceObject owner) : super._empty(owner); | 4274 Frame._empty(ServiceObject owner) : super._empty(owner); |
| 4340 | 4275 |
| 4341 void _update(ObservableMap map, bool mapIsRef) { | 4276 void _update(ObservableMap map, bool mapIsRef) { |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4457 var v = list[i]; | 4392 var v = list[i]; |
| 4458 if ((v is ObservableMap) && _isServiceMap(v)) { | 4393 if ((v is ObservableMap) && _isServiceMap(v)) { |
| 4459 list[i] = owner.getFromMap(v); | 4394 list[i] = owner.getFromMap(v); |
| 4460 } else if (v is ObservableList) { | 4395 } else if (v is ObservableList) { |
| 4461 _upgradeObservableList(v, owner); | 4396 _upgradeObservableList(v, owner); |
| 4462 } else if (v is ObservableMap) { | 4397 } else if (v is ObservableMap) { |
| 4463 _upgradeObservableMap(v, owner); | 4398 _upgradeObservableMap(v, owner); |
| 4464 } | 4399 } |
| 4465 } | 4400 } |
| 4466 } | 4401 } |
| OLD | NEW |