OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 library heap_profile_element; |
| 6 |
| 7 import 'package:polymer/polymer.dart'; |
| 8 import 'observatory_element.dart'; |
| 9 |
| 10 /// Displays an Error response. |
| 11 @CustomTag('heap-profile') |
| 12 class HeapProfileElement extends ObservatoryElement { |
| 13 @published Map profile; |
| 14 @published List sortedProfileNewSpace; |
| 15 @published List sortedProfileOldSpace; |
| 16 |
| 17 @observable int classCountSelected = 0; |
| 18 final List classCounts = [10, 20, 50]; |
| 19 |
| 20 static const ALLOCATED_BEFORE_GC = 0; |
| 21 static const ALLOCATED_BEFORE_GC_SIZE = 1; |
| 22 static const LIVE_AFTER_GC = 2; |
| 23 static const LIVE_AFTER_GC_SIZE = 3; |
| 24 static const ALLOCATED_SINCE_GC = 4; |
| 25 static const ALLOCATED_SINCE_GC_SIZE = 5; |
| 26 |
| 27 HeapProfileElement.created() : super.created(); |
| 28 |
| 29 _sort() { |
| 30 if ((profile == null) || (profile['members'] is! List) || |
| 31 (profile['members'].length == 0)) { |
| 32 sortedProfileNewSpace = toObservable([]); |
| 33 sortedProfileOldSpace = toObservable([]); |
| 34 } |
| 35 sortedProfileNewSpace = profile['members'].toList(); |
| 36 bool new_space = true; |
| 37 sortedProfileNewSpace.sort((a, b) { |
| 38 List aData = a[new_space ? 'new' : 'old']; |
| 39 List bData = b[new_space ? 'new' : 'old']; |
| 40 int aCurrent = aData[LIVE_AFTER_GC_SIZE] + aData[ALLOCATED_SINCE_GC_SIZE]; |
| 41 int bCurrent = bData[LIVE_AFTER_GC_SIZE] + bData[ALLOCATED_SINCE_GC_SIZE]; |
| 42 return bCurrent - aCurrent; |
| 43 }); |
| 44 sortedProfileNewSpace = toObservable(sortedProfileNewSpace.sublist(0, 10)); |
| 45 |
| 46 sortedProfileOldSpace = profile['members'].toList(); |
| 47 new_space = false; |
| 48 sortedProfileOldSpace.sort((a, b) { |
| 49 List aData = a[new_space ? 'new' : 'old']; |
| 50 List bData = b[new_space ? 'new' : 'old']; |
| 51 int aCurrent = aData[LIVE_AFTER_GC_SIZE] + aData[ALLOCATED_SINCE_GC_SIZE]; |
| 52 int bCurrent = bData[LIVE_AFTER_GC_SIZE] + bData[ALLOCATED_SINCE_GC_SIZE]; |
| 53 return bCurrent - aCurrent; |
| 54 }); |
| 55 sortedProfileOldSpace = toObservable(sortedProfileOldSpace.sublist(0, 10)); |
| 56 } |
| 57 |
| 58 void profileChanged(oldValue) { |
| 59 _sort(); |
| 60 notifyPropertyChange(#sortedProfileNewSpace, [], sortedProfileNewSpace); |
| 61 notifyPropertyChange(#sortedProfileOldSpace, [], sortedProfileOldSpace); |
| 62 notifyPropertyChange(#status, [], status); |
| 63 } |
| 64 |
| 65 String status(bool new_space) { |
| 66 if (profile == null) { |
| 67 return ''; |
| 68 } |
| 69 String space = new_space ? 'new' : 'old'; |
| 70 Map heap = profile['heap'][space]; |
| 71 var usage = '${ObservatoryApplication.scaledSizeUnits(heap['used'])} / ' |
| 72 '${ObservatoryApplication.scaledSizeUnits(heap['capacity'])}'; |
| 73 var timings = '${ObservatoryApplication.timeUnits(heap['time'])} secs'; |
| 74 var collections = '${heap['collections']} collections'; |
| 75 var avgTime = '${(heap['time'] * 1000.0) / heap['collections']} ms'; |
| 76 return '$usage ($timings) [$collections] $avgTime'; |
| 77 } |
| 78 |
| 79 String current(Map cls, bool new_space, [bool instances = false]) { |
| 80 if (cls is !Map) { |
| 81 return ''; |
| 82 } |
| 83 List data = cls[new_space ? 'new' : 'old']; |
| 84 if (data == null) { |
| 85 return ''; |
| 86 } |
| 87 int current = data[instances ? LIVE_AFTER_GC : LIVE_AFTER_GC_SIZE] + |
| 88 data[instances ? ALLOCATED_SINCE_GC : ALLOCATED_SINCE_GC_SIZE]; |
| 89 if (instances) { |
| 90 return '$current'; |
| 91 } |
| 92 return ObservatoryApplication.scaledSizeUnits(current); |
| 93 } |
| 94 |
| 95 String allocated(Map cls, bool new_space, [bool instances = false]) { |
| 96 if (cls is !Map) { |
| 97 return ''; |
| 98 } |
| 99 List data = cls[new_space ? 'new' : 'old']; |
| 100 if (data == null) { |
| 101 return ''; |
| 102 } |
| 103 int current = |
| 104 data[instances ? ALLOCATED_SINCE_GC : ALLOCATED_SINCE_GC_SIZE]; |
| 105 if (instances) { |
| 106 return '$current'; |
| 107 } |
| 108 return ObservatoryApplication.scaledSizeUnits(current); |
| 109 } |
| 110 |
| 111 String beforeGC(Map cls, bool new_space, [bool instances = false]) { |
| 112 if (cls is! Map) { |
| 113 return ''; |
| 114 } |
| 115 List data = cls[new_space ? 'new' : 'old']; |
| 116 if (data == null) { |
| 117 return ''; |
| 118 } |
| 119 int current = |
| 120 data[instances ? ALLOCATED_BEFORE_GC : ALLOCATED_BEFORE_GC_SIZE]; |
| 121 if (instances) { |
| 122 return '$current'; |
| 123 } |
| 124 return ObservatoryApplication.scaledSizeUnits(current); |
| 125 } |
| 126 |
| 127 String afterGC(Map cls, bool new_space, [bool instances = false]) { |
| 128 if (cls is! Map) { |
| 129 return ''; |
| 130 } |
| 131 List data = cls[new_space ? 'new' : 'old']; |
| 132 if (data == null) { |
| 133 return ''; |
| 134 } |
| 135 int current = data[instances ? LIVE_AFTER_GC : LIVE_AFTER_GC_SIZE]; |
| 136 if (instances) { |
| 137 return '$current'; |
| 138 } |
| 139 return ObservatoryApplication.scaledSizeUnits(current); |
| 140 } |
| 141 } |
OLD | NEW |