Chromium Code Reviews| Index: runtime/bin/vmservice/client/lib/src/elements/isolate_profile.dart |
| diff --git a/runtime/bin/vmservice/client/lib/src/elements/isolate_profile.dart b/runtime/bin/vmservice/client/lib/src/elements/isolate_profile.dart |
| index 39092b38d45c9b63653b64d32d0a708f787956c8..261c0fd702fe95387b21d16a4fab007b170e8dfa 100644 |
| --- a/runtime/bin/vmservice/client/lib/src/elements/isolate_profile.dart |
| +++ b/runtime/bin/vmservice/client/lib/src/elements/isolate_profile.dart |
| @@ -6,10 +6,61 @@ library isolate_profile_element; |
| import 'dart:html'; |
| import 'observatory_element.dart'; |
| +import 'package:logging/logging.dart'; |
| import 'package:observatory/service.dart'; |
| import 'package:observatory/app.dart'; |
| import 'package:polymer/polymer.dart'; |
| +class ProfileCodeTrieNodeTreeRow extends TableTreeRow { |
| + final ServiceMap profile; |
| + @reflectable final CodeTrieNode root; |
| + @reflectable final CodeTrieNode node; |
| + @reflectable Code get code => node.code; |
| + |
| + static String formatPercent(num a, num total) { |
| + var percent = 100.0 * (a / total); |
| + return '${percent.toStringAsFixed(2)}%'; |
| + } |
| + |
| + ProfileCodeTrieNodeTreeRow(this.profile, this.root, this.node, |
| + ProfileCodeTrieNodeTreeRow parent) |
| + : super(parent) { |
| + assert(root != null); |
| + assert(node != null); |
| + var totalSamples = root.count; |
| + // When the row is created, fill out the columns. |
| + if (parent == null) { |
| + columns.add(formatPercent(node.count, root.count)); |
| + } else { |
| + columns.add(formatPercent(node.count, parent.node.count)); |
| + } |
| + columns.add(formatPercent(node.code.exclusiveTicks, totalSamples)); |
| + } |
| + |
| + bool shouldDisplayChild(CodeTrieNode childNode, double threshold) { |
| + return ((childNode.count / node.count) > threshold) || |
| + ((childNode.code.exclusiveTicks / root.count) > threshold); |
| + } |
| + |
| + void onShow() { |
| + var threshold = profile['threshold']; |
| + if (children.length > 0) { |
| + // Child rows already created. |
| + return; |
| + } |
| + for (var childNode in node.children) { |
| + if (!shouldDisplayChild(childNode, threshold)) { |
| + continue; |
| + } |
| + var row = new ProfileCodeTrieNodeTreeRow(profile, root, childNode, this); |
| + children.add(row); |
| + } |
| + } |
| + |
| + void onHide() { |
| + } |
| +} |
| + |
| class ProfileCallerTreeRow extends TableTreeRow { |
| final ServiceMap profile; |
| @reflectable final Code code; |
| @@ -25,29 +76,41 @@ class ProfileCallerTreeRow extends TableTreeRow { |
| assert(code != null); |
| var totalSamples = profile['samples']; |
| // When the row is created, fill out the columns. |
| - columns.add( |
| - formatPercent(code.exclusiveTicks, totalSamples)); |
| if (parent == null) { |
| - // Fill with dummy data. |
| - columns.add(''); |
| + var root = profile.isolate.codes.tagRoot(); |
| + var totalAttributedCalls = root.callersCount(code); |
| + var totalParentCalls = root.sumCallersCount(); |
| + columns.add(formatPercent(totalAttributedCalls, totalParentCalls)); |
| } else { |
| var totalAttributedCalls = parent.code.callersCount(code); |
| var totalParentCalls = parent.code.sumCallersCount(); |
| columns.add(formatPercent(totalAttributedCalls, totalParentCalls)); |
| } |
| + columns.add(formatPercent(code.exclusiveTicks, totalSamples)); |
| + } |
| + |
| + bool shouldDisplayChild(CodeCallCount childNode, totalSamples, |
| + double threshold) { |
| + var callerPercent = code.callersCount(childNode.code) / |
| + code.sumCallersCount(); |
| + return (callerPercent > threshold) || |
| + ((childNode.code.exclusiveTicks / totalSamples) > threshold); |
| } |
| void onShow() { |
| + var threshold = profile['threshold']; |
| + var totalSamples = profile['samples']; |
| if (children.length > 0) { |
| // Child rows already created. |
| return; |
| } |
| - // Create child rows on demand. |
| - code.callers.forEach((CodeCallCount codeCaller) { |
| - var row = |
| - new ProfileCallerTreeRow(profile, codeCaller.code, this); |
| + for (var codeCaller in code.callers) { |
| + if (!shouldDisplayChild(codeCaller, totalSamples, threshold)) { |
| + continue; |
| + } |
| + var row = new ProfileCallerTreeRow(profile, codeCaller.code, this); |
| children.add(row); |
| - }); |
| + } |
| } |
| void onHide() { |
| @@ -59,12 +122,15 @@ class ProfileCallerTreeRow extends TableTreeRow { |
| class IsolateProfileElement extends ObservatoryElement { |
| IsolateProfileElement.created() : super.created(); |
| @published ServiceMap profile; |
| - @reflectable final topExclusiveCodes = new ObservableList<Code>(); |
| - @observable int methodCountSelected = 0; |
| + @observable bool callGraphChecked = false; |
| + @observable bool hideTagsChecked = false; |
| @observable String sampleCount = ''; |
| @observable String refreshTime = ''; |
| + @observable String sampleRate = ''; |
| + @observable String sampleDepth = ''; |
| + @observable String displayCutoff = ''; |
| + @reflectable double displayThreshold = 0.005; // 0.5%. |
| - final List methodCounts = [10, 20, 50]; |
| final _id = '#tableTree'; |
| TableTree tree; |
| @@ -76,21 +142,31 @@ class IsolateProfileElement extends ObservatoryElement { |
| var now = new DateTime.now(); |
| sampleCount = totalSamples.toString(); |
| refreshTime = now.toString(); |
| + sampleDepth = profile['depth'].toString(); |
| + sampleRate = (1000000.0 / profile['period'].toDouble()).toStringAsFixed(0); |
|
turnidge
2014/03/17 21:19:31
Why 1000000.0? Named constant?
Cutch
2014/03/18 14:39:19
Done.
|
| + displayCutoff = '${(displayThreshold * 100.0).toString()}%'; |
| profile.isolate.processProfile(profile); |
| + profile['threshold'] = displayThreshold; |
| _update(); |
| } |
| - void enteredView() { |
| - tree = new TableTree(['Method', 'Exclusive', 'Caller']); |
| + void callGraphCheckedChanged(oldValue) { |
| _update(); |
| } |
| - methodCountSelectedChanged(oldValue) { |
| + |
| + void enteredView() { |
| + tree = new TableTree(); |
| _update(); |
| } |
| + void hideTagsCheckedChanged(oldValue) { |
| + refresh(null); |
| + } |
| + |
| void refresh(var done) { |
| - profile.isolate.get('profile').then((ServiceMap m) { |
| + var request = 'profile' + (hideTagsChecked ? '?tags=hide' : ''); |
| + profile.isolate.get(request).then((ServiceMap m) { |
| // Assert we got back the a profile. |
| assert(m.serviceType == 'Profile'); |
| profile = m; |
| @@ -101,28 +177,46 @@ class IsolateProfileElement extends ObservatoryElement { |
| if (profile == null) { |
| return; |
| } |
| - _refreshTopMethods(); |
| - _rebuildTree(); |
| + _buildTree(); |
| } |
| - void _refreshTopMethods() { |
| + void _buildCallersTree() { |
| assert(profile != null); |
| - var count = methodCounts[methodCountSelected]; |
| - topExclusiveCodes.clear(); |
| - topExclusiveCodes.addAll(profile.isolate.codes.topExclusive(count)); |
| + var root = profile.isolate.codes.tagRoot(); |
| + if (root == null) { |
| + Logger.root.warning('No profile root tag.'); |
| + } |
| + try { |
| + tree.initialize(new ProfileCallerTreeRow(profile, root, null)); |
| + } catch (e, stackTrace) { |
| + Logger.root.warning('_buildCallersTree', e, stackTrace); |
| + } |
| + |
| + notifyPropertyChange(#tree, null, tree); |
| } |
| - void _rebuildTree() { |
| - assert(profile != null); |
| - var rootChildren = []; |
| - for (var code in topExclusiveCodes) { |
| - var row = new ProfileCallerTreeRow(profile, code, null); |
| - rootChildren.add(row); |
| + void _buildStackTree() { |
| + var root = profile.isolate.profileTrieRoot; |
| + if (root == null) { |
| + Logger.root.warning('No profile trie root.'); |
| + } |
| + try { |
| + tree.initialize( |
| + new ProfileCodeTrieNodeTreeRow(profile, root, root, null)); |
| + } catch (e, stackTrace) { |
| + Logger.root.warning('_buildStackTree', e, stackTrace); |
| } |
| - tree.initialize(rootChildren); |
| notifyPropertyChange(#tree, null, tree); |
| } |
| + void _buildTree() { |
| + if (callGraphChecked) { |
| + _buildCallersTree(); |
| + } else { |
| + _buildStackTree(); |
| + } |
| + } |
| + |
| @observable String padding(TableTreeRow row) { |
| return 'padding-left: ${row.depth * 16}px;'; |
| } |