| Index: runtime/bin/vmservice/client/lib/src/observatory_elements/heap_profile.dart
|
| diff --git a/runtime/bin/vmservice/client/lib/src/observatory_elements/heap_profile.dart b/runtime/bin/vmservice/client/lib/src/observatory_elements/heap_profile.dart
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..ecd738072d17550c10b4f6d1db353ccfda45b68a
|
| --- /dev/null
|
| +++ b/runtime/bin/vmservice/client/lib/src/observatory_elements/heap_profile.dart
|
| @@ -0,0 +1,141 @@
|
| +// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
|
| +// for details. All rights reserved. Use of this source code is governed by a
|
| +// BSD-style license that can be found in the LICENSE file.
|
| +
|
| +library heap_profile_element;
|
| +
|
| +import 'package:polymer/polymer.dart';
|
| +import 'observatory_element.dart';
|
| +
|
| +/// Displays an Error response.
|
| +@CustomTag('heap-profile')
|
| +class HeapProfileElement extends ObservatoryElement {
|
| + @published Map profile;
|
| + @published List sortedProfileNewSpace;
|
| + @published List sortedProfileOldSpace;
|
| +
|
| + @observable int classCountSelected = 0;
|
| + final List classCounts = [10, 20, 50];
|
| +
|
| + static const ALLOCATED_BEFORE_GC = 0;
|
| + static const ALLOCATED_BEFORE_GC_SIZE = 1;
|
| + static const LIVE_AFTER_GC = 2;
|
| + static const LIVE_AFTER_GC_SIZE = 3;
|
| + static const ALLOCATED_SINCE_GC = 4;
|
| + static const ALLOCATED_SINCE_GC_SIZE = 5;
|
| +
|
| + HeapProfileElement.created() : super.created();
|
| +
|
| + _sort() {
|
| + if ((profile == null) || (profile['members'] is! List) ||
|
| + (profile['members'].length == 0)) {
|
| + sortedProfileNewSpace = toObservable([]);
|
| + sortedProfileOldSpace = toObservable([]);
|
| + }
|
| + sortedProfileNewSpace = profile['members'].toList();
|
| + bool new_space = true;
|
| + sortedProfileNewSpace.sort((a, b) {
|
| + List aData = a[new_space ? 'new' : 'old'];
|
| + List bData = b[new_space ? 'new' : 'old'];
|
| + int aCurrent = aData[LIVE_AFTER_GC_SIZE] + aData[ALLOCATED_SINCE_GC_SIZE];
|
| + int bCurrent = bData[LIVE_AFTER_GC_SIZE] + bData[ALLOCATED_SINCE_GC_SIZE];
|
| + return bCurrent - aCurrent;
|
| + });
|
| + sortedProfileNewSpace = toObservable(sortedProfileNewSpace.sublist(0, 10));
|
| +
|
| + sortedProfileOldSpace = profile['members'].toList();
|
| + new_space = false;
|
| + sortedProfileOldSpace.sort((a, b) {
|
| + List aData = a[new_space ? 'new' : 'old'];
|
| + List bData = b[new_space ? 'new' : 'old'];
|
| + int aCurrent = aData[LIVE_AFTER_GC_SIZE] + aData[ALLOCATED_SINCE_GC_SIZE];
|
| + int bCurrent = bData[LIVE_AFTER_GC_SIZE] + bData[ALLOCATED_SINCE_GC_SIZE];
|
| + return bCurrent - aCurrent;
|
| + });
|
| + sortedProfileOldSpace = toObservable(sortedProfileOldSpace.sublist(0, 10));
|
| + }
|
| +
|
| + void profileChanged(oldValue) {
|
| + _sort();
|
| + notifyPropertyChange(#sortedProfileNewSpace, [], sortedProfileNewSpace);
|
| + notifyPropertyChange(#sortedProfileOldSpace, [], sortedProfileOldSpace);
|
| + notifyPropertyChange(#status, [], status);
|
| + }
|
| +
|
| + String status(bool new_space) {
|
| + if (profile == null) {
|
| + return '';
|
| + }
|
| + String space = new_space ? 'new' : 'old';
|
| + Map heap = profile['heap'][space];
|
| + var usage = '${ObservatoryApplication.scaledSizeUnits(heap['used'])} / '
|
| + '${ObservatoryApplication.scaledSizeUnits(heap['capacity'])}';
|
| + var timings = '${ObservatoryApplication.timeUnits(heap['time'])} secs';
|
| + var collections = '${heap['collections']} collections';
|
| + var avgTime = '${(heap['time'] * 1000.0) / heap['collections']} ms';
|
| + return '$usage ($timings) [$collections] $avgTime';
|
| + }
|
| +
|
| + String current(Map cls, bool new_space, [bool instances = false]) {
|
| + if (cls is !Map) {
|
| + return '';
|
| + }
|
| + List data = cls[new_space ? 'new' : 'old'];
|
| + if (data == null) {
|
| + return '';
|
| + }
|
| + int current = data[instances ? LIVE_AFTER_GC : LIVE_AFTER_GC_SIZE] +
|
| + data[instances ? ALLOCATED_SINCE_GC : ALLOCATED_SINCE_GC_SIZE];
|
| + if (instances) {
|
| + return '$current';
|
| + }
|
| + return ObservatoryApplication.scaledSizeUnits(current);
|
| + }
|
| +
|
| + String allocated(Map cls, bool new_space, [bool instances = false]) {
|
| + if (cls is !Map) {
|
| + return '';
|
| + }
|
| + List data = cls[new_space ? 'new' : 'old'];
|
| + if (data == null) {
|
| + return '';
|
| + }
|
| + int current =
|
| + data[instances ? ALLOCATED_SINCE_GC : ALLOCATED_SINCE_GC_SIZE];
|
| + if (instances) {
|
| + return '$current';
|
| + }
|
| + return ObservatoryApplication.scaledSizeUnits(current);
|
| + }
|
| +
|
| + String beforeGC(Map cls, bool new_space, [bool instances = false]) {
|
| + if (cls is! Map) {
|
| + return '';
|
| + }
|
| + List data = cls[new_space ? 'new' : 'old'];
|
| + if (data == null) {
|
| + return '';
|
| + }
|
| + int current =
|
| + data[instances ? ALLOCATED_BEFORE_GC : ALLOCATED_BEFORE_GC_SIZE];
|
| + if (instances) {
|
| + return '$current';
|
| + }
|
| + return ObservatoryApplication.scaledSizeUnits(current);
|
| + }
|
| +
|
| + String afterGC(Map cls, bool new_space, [bool instances = false]) {
|
| + if (cls is! Map) {
|
| + return '';
|
| + }
|
| + List data = cls[new_space ? 'new' : 'old'];
|
| + if (data == null) {
|
| + return '';
|
| + }
|
| + int current = data[instances ? LIVE_AFTER_GC : LIVE_AFTER_GC_SIZE];
|
| + if (instances) {
|
| + return '$current';
|
| + }
|
| + return ObservatoryApplication.scaledSizeUnits(current);
|
| + }
|
| +}
|
|
|