| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 library class_view_element; | 5 library class_view_element; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'observatory_element.dart'; | 8 import 'observatory_element.dart'; |
| 9 import 'package:observatory/cpu_profile.dart'; | 9 import 'package:observatory/cpu_profile.dart'; |
| 10 import 'package:observatory/elements.dart'; | 10 import 'package:observatory/elements.dart'; |
| 11 import 'package:observatory/service.dart'; | 11 import 'package:observatory/service.dart'; |
| 12 import 'package:polymer/polymer.dart'; | 12 import 'package:polymer/polymer.dart'; |
| 13 | 13 |
| 14 @CustomTag('class-view') | 14 @CustomTag('class-view') |
| 15 class ClassViewElement extends ObservatoryElement { | 15 class ClassViewElement extends ObservatoryElement { |
| 16 @published Class cls; | 16 @published Class cls; |
| 17 @observable ServiceMap instances; | 17 @observable ServiceMap instances; |
| 18 @observable int retainedBytes; | 18 @observable int retainedBytes; |
| 19 @observable ObservableList mostRetained; | 19 @observable ObservableList mostRetained; |
| 20 SampleBufferControlElement sampleBufferControlElement; |
| 21 StackTraceTreeConfigElement stackTraceTreeConfigElement; |
| 22 CpuProfileTreeElement cpuProfileTreeElement; |
| 23 |
| 20 ClassViewElement.created() : super.created(); | 24 ClassViewElement.created() : super.created(); |
| 21 | 25 |
| 22 Future<ServiceObject> evaluate(String expression) { | 26 Future<ServiceObject> evaluate(String expression) { |
| 23 return cls.evaluate(expression); | 27 return cls.evaluate(expression); |
| 24 } | 28 } |
| 25 | 29 |
| 26 Future<ServiceObject> reachable(var limit) { | 30 Future<ServiceObject> reachable(var limit) { |
| 27 return cls.isolate.getInstances(cls, limit).then((ServiceMap obj) { | 31 return cls.isolate.getInstances(cls, limit).then((ServiceMap obj) { |
| 28 instances = obj; | 32 instances = obj; |
| 29 }); | 33 }); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 40 } | 44 } |
| 41 | 45 |
| 42 // TODO(koda): Add no-arg "calculate-link" instead of reusing "eval-link". | 46 // TODO(koda): Add no-arg "calculate-link" instead of reusing "eval-link". |
| 43 Future<ServiceObject> retainedSize(var dummy) { | 47 Future<ServiceObject> retainedSize(var dummy) { |
| 44 return cls.isolate.getRetainedSize(cls).then((Instance obj) { | 48 return cls.isolate.getRetainedSize(cls).then((Instance obj) { |
| 45 retainedBytes = int.parse(obj.valueAsString); | 49 retainedBytes = int.parse(obj.valueAsString); |
| 46 }); | 50 }); |
| 47 } | 51 } |
| 48 | 52 |
| 49 void attached() { | 53 void attached() { |
| 54 super.attached(); |
| 55 sampleBufferControlElement = |
| 56 shadowRoot.querySelector('#sampleBufferControl'); |
| 57 assert(sampleBufferControlElement != null); |
| 58 sampleBufferControlElement.onSampleBufferUpdate = onSampleBufferChange; |
| 59 sampleBufferControlElement.state = |
| 60 SampleBufferControlElement.kNotLoadedState; |
| 61 stackTraceTreeConfigElement = |
| 62 shadowRoot.querySelector('#stackTraceTreeConfig'); |
| 63 assert(stackTraceTreeConfigElement != null); |
| 64 stackTraceTreeConfigElement.onTreeConfigChange = onTreeConfigChange; |
| 65 cpuProfileTreeElement = shadowRoot.querySelector('#cpuProfileTree'); |
| 66 assert(cpuProfileTreeElement != null); |
| 67 cpuProfileTreeElement.profile = sampleBufferControlElement.profile; |
| 50 cls.fields.forEach((field) => field.reload()); | 68 cls.fields.forEach((field) => field.reload()); |
| 69 sampleBufferControlElement.allocationProfileClass = cls; |
| 51 } | 70 } |
| 52 | 71 |
| 53 Future refresh() { | 72 Future refresh() { |
| 54 instances = null; | 73 instances = null; |
| 55 retainedBytes = null; | 74 retainedBytes = null; |
| 56 mostRetained = null; | 75 mostRetained = null; |
| 57 var loads = []; | 76 var loads = []; |
| 58 loads.add(cls.reload()); | 77 loads.add(cls.reload()); |
| 59 cls.fields.forEach((field) => loads.add(field.reload())); | 78 cls.fields.forEach((field) => loads.add(field.reload())); |
| 60 return Future.wait(loads); | 79 return Future.wait(loads); |
| 61 } | 80 } |
| 62 | 81 |
| 63 Future refreshCoverage() { | 82 Future refreshCoverage() { |
| 64 return cls.refreshCoverage(); | 83 return cls.refreshCoverage(); |
| 65 } | 84 } |
| 66 | 85 |
| 67 final CpuProfile profile = new CpuProfile(); | 86 onSampleBufferChange(CpuProfile sampleBuffer) { |
| 87 cpuProfileTreeElement.render(); |
| 88 } |
| 89 |
| 90 onTreeConfigChange(String modeSelector, String directionSelector) { |
| 91 ProfileTreeDirection direction = ProfileTreeDirection.Exclusive; |
| 92 if (directionSelector != 'Up') { |
| 93 direction = ProfileTreeDirection.Inclusive; |
| 94 } |
| 95 ProfileTreeMode mode = ProfileTreeMode.Function; |
| 96 if (modeSelector == 'Code') { |
| 97 mode = ProfileTreeMode.Code; |
| 98 } |
| 99 cpuProfileTreeElement.direction = direction; |
| 100 cpuProfileTreeElement.mode = mode; |
| 101 cpuProfileTreeElement.render(); |
| 102 } |
| 68 | 103 |
| 69 Future refreshAllocationProfile() async { | 104 Future refreshAllocationProfile() async { |
| 70 var profileResponse = await cls.getAllocationSamples('UserVM'); | 105 return sampleBufferControlElement.reload(cls.isolate); |
| 71 profile.load(profileResponse.isolate, profileResponse); | |
| 72 CpuProfileTreeElement cpuProfileTreeElement = | |
| 73 shadowRoot.querySelector('#cpuProfileTree'); | |
| 74 cpuProfileTreeElement.profile = profile; | |
| 75 cpuProfileTreeElement.direction = ProfileTreeDirection.Exclusive; | |
| 76 cpuProfileTreeElement.mode = ProfileTreeMode.Function; | |
| 77 cpuProfileTreeElement.render(); | |
| 78 } | 106 } |
| 79 | 107 |
| 80 Future toggleAllocationTrace() { | 108 Future toggleAllocationTrace() { |
| 81 if (cls == null) { | 109 if (cls == null) { |
| 82 return new Future(refresh); | 110 return new Future(refresh); |
| 83 } | 111 } |
| 84 return cls.setTraceAllocations(!cls.traceAllocations).whenComplete(refresh); | 112 return cls.setTraceAllocations(!cls.traceAllocations).whenComplete(refresh); |
| 85 } | 113 } |
| 86 } | 114 } |
| OLD | NEW |