Index: runtime/observatory/lib/src/elements/cpu_profile/virtual_tree.dart |
diff --git a/runtime/observatory/lib/src/elements/cpu_profile/virtual_tree.dart b/runtime/observatory/lib/src/elements/cpu_profile/virtual_tree.dart |
index 7617a20da4ada1bc6083171d19f10695b4699cf2..5073b76c414d02d9ef6739013f0b1bca7f96b6b0 100644 |
--- a/runtime/observatory/lib/src/elements/cpu_profile/virtual_tree.dart |
+++ b/runtime/observatory/lib/src/elements/cpu_profile/virtual_tree.dart |
@@ -7,7 +7,7 @@ import 'dart:html'; |
import 'dart:math' as Math; |
import 'package:observatory/models.dart' as M; |
import 'package:observatory/src/elements/stack_trace_tree_config.dart' |
- show ProfileTreeMode; |
+ show ProfileTreeMode, ProfileTreeType; |
import 'package:observatory/src/elements/code_ref.dart'; |
import 'package:observatory/src/elements/containers/virtual_tree.dart'; |
import 'package:observatory/src/elements/function_ref.dart'; |
@@ -16,7 +16,7 @@ import 'package:observatory/src/elements/helpers/tag.dart'; |
import 'package:observatory/utils.dart'; |
export 'package:observatory/src/elements/stack_trace_tree_config.dart' |
- show ProfileTreeMode; |
+ show ProfileTreeMode, ProfileTreeType; |
class CpuProfileVirtualTreeElement extends HtmlElement implements Renderable { |
static const tag = |
@@ -29,12 +29,14 @@ class CpuProfileVirtualTreeElement extends HtmlElement implements Renderable { |
M.ProfileTreeDirection _direction; |
ProfileTreeMode _mode; |
+ ProfileTreeType _type; |
M.IsolateRef _isolate; |
M.SampleProfile _profile; |
Iterable<M.CallTreeNodeFilter> _filters; |
M.ProfileTreeDirection get direction => _direction; |
ProfileTreeMode get mode => _mode; |
+ ProfileTreeType get type => _type; |
M.IsolateRef get isolate => _isolate; |
M.SampleProfile get profile => _profile; |
Iterable<M.CallTreeNodeFilter> get filters => _filters; |
@@ -50,9 +52,9 @@ class CpuProfileVirtualTreeElement extends HtmlElement implements Renderable { |
factory CpuProfileVirtualTreeElement( |
M.IsolateRef isolate, M.SampleProfile profile, |
{ProfileTreeMode mode: ProfileTreeMode.function, |
+ ProfileTreeType type: ProfileTreeType.cpu, |
M.ProfileTreeDirection direction: M.ProfileTreeDirection.exclusive, |
RenderingQueue queue}) { |
- assert(isolate != null); |
assert(profile != null); |
assert(mode != null); |
assert(direction != null); |
@@ -61,6 +63,7 @@ class CpuProfileVirtualTreeElement extends HtmlElement implements Renderable { |
e._isolate = isolate; |
e._profile = profile; |
e._mode = mode; |
+ e._type = type; |
e._direction = direction; |
return e; |
} |
@@ -84,18 +87,33 @@ class CpuProfileVirtualTreeElement extends HtmlElement implements Renderable { |
void render() { |
var tree; |
+ var create; |
var update; |
- switch (mode) { |
- case ProfileTreeMode.code: |
- tree = _profile.loadCodeTree(_direction); |
- update = _updateCodeRow; |
+ |
+ switch (type) { |
+ case ProfileTreeType.cpu: |
+ create = _createCpuRow; |
+ if (mode == ProfileTreeMode.code) { |
+ update = _updateCpuCodeRow; |
+ } else if (mode == ProfileTreeMode.function) { |
+ update = _updateCpuFunctionRow; |
+ } else { |
+ throw new Exception('Unknown ProfileTreeMode: $mode'); |
+ } |
break; |
- case ProfileTreeMode.function: |
- tree = _profile.loadFunctionTree(_direction); |
- update = _updateFunctionRow; |
+ case ProfileTreeType.memory: |
+ create = _createMemoryRow; |
+ if (mode == ProfileTreeMode.code) { |
+ update = _updateMemoryCodeRow; |
+ } else if (mode == ProfileTreeMode.function) { |
+ update = _updateMemoryFunctionRow; |
+ } else { |
+ throw new Exception('Unknown ProfileTreeMode: $mode'); |
+ } |
break; |
default: |
- throw new Exception('Unknown ProfileTreeMode: $mode'); |
+ throw new Exception('Unknown ProfileTreeType: $type'); |
+ break; |
} |
if (filters != null) { |
tree = filters.fold(tree, (tree, filter) { |
@@ -106,7 +124,7 @@ class CpuProfileVirtualTreeElement extends HtmlElement implements Renderable { |
children = [new HeadingElement.h1()..text = 'No Results']; |
return; |
} |
- _tree = new VirtualTreeElement(_createRow, update, _getChildren, |
+ _tree = new VirtualTreeElement(create, update, _getChildren, |
items: tree.root.children, queue: _r.queue); |
if (tree.root.children.length == 1) { |
_tree.expand(tree.root.children.first, autoExpandSingleChildNodes: true); |
@@ -114,7 +132,7 @@ class CpuProfileVirtualTreeElement extends HtmlElement implements Renderable { |
children = [_tree]; |
} |
- static Element _createRow(toggle) { |
+ static Element _createCpuRow(toggle) { |
return new DivElement() |
..classes = ['tree-item'] |
..children = [ |
@@ -135,9 +153,30 @@ class CpuProfileVirtualTreeElement extends HtmlElement implements Renderable { |
]; |
} |
+ static Element _createMemoryRow(toggle) { |
+ return new DivElement() |
+ ..classes = ['tree-item'] |
+ ..children = [ |
+ new SpanElement() |
+ ..classes = ['inclusive'] |
+ ..title = 'memory allocated from resulting calls: ', |
+ new SpanElement() |
+ ..classes = ['exclusive'] |
+ ..title = 'memory allocated during execution: ', |
+ new SpanElement()..classes = ['lines'], |
+ new ButtonElement() |
+ ..classes = ['expander'] |
+ ..onClick.listen((_) => toggle(autoToggleSingleChildNodes: true)), |
+ new SpanElement() |
+ ..classes = ['percentage'] |
+ ..title = 'tree node %', |
+ new SpanElement()..classes = ['name'] |
+ ]; |
+ } |
+ |
static _getChildren(M.CallTreeNode node) => node.children; |
- void _updateFunctionRow( |
+ void _updateCpuFunctionRow( |
HtmlElement element, M.FunctionCallTreeNode item, int depth) { |
element.children[0].text = Utils |
.formatPercentNormalized(item.profileFunction.normalizedInclusiveTicks); |
@@ -155,7 +194,30 @@ class CpuProfileVirtualTreeElement extends HtmlElement implements Renderable { |
..classes = ['name']; |
} |
- void _updateCodeRow(HtmlElement element, M.CodeCallTreeNode item, int depth) { |
+ void _updateMemoryFunctionRow( |
+ HtmlElement element, M.FunctionCallTreeNode item, int depth) { |
+ element.children[0].text = |
+ Utils.formatSize(item.inclusiveNativeAllocations); |
+ element.children[0].title = 'memory allocated from resulting calls: ' + |
+ '${item.inclusiveNativeAllocations}B'; |
+ element.children[1].text = |
+ Utils.formatSize(item.exclusiveNativeAllocations); |
+ element.children[1].title = 'memory allocated during execution: ' + |
+ '${item.exclusiveNativeAllocations}B'; |
+ _updateLines(element.children[2].children, depth); |
+ if (item.children.isNotEmpty) { |
+ element.children[3].text = _tree.isExpanded(item) ? '▼' : '►'; |
+ } else { |
+ element.children[3].text = ''; |
+ } |
+ element.children[4].text = Utils.formatPercentNormalized(item.percentage); |
+ element.children[5] = new FunctionRefElement( |
+ null, item.profileFunction.function, queue: _r.queue) |
+ ..classes = ['name']; |
+ } |
+ |
+ void _updateCpuCodeRow( |
+ HtmlElement element, M.CodeCallTreeNode item, int depth) { |
element.children[0].text = Utils |
.formatPercentNormalized(item.profileCode.normalizedInclusiveTicks); |
element.children[1].text = Utils |
@@ -171,6 +233,27 @@ class CpuProfileVirtualTreeElement extends HtmlElement implements Renderable { |
queue: _r.queue)..classes = ['name']; |
} |
+ void _updateMemoryCodeRow( |
+ HtmlElement element, M.CodeCallTreeNode item, int depth) { |
+ element.children[0].text = |
+ Utils.formatSize(item.inclusiveNativeAllocations); |
+ element.children[0].title = 'memory allocated from resulting calls: ' + |
+ '${item.inclusiveNativeAllocations}B'; |
+ element.children[1].text = |
+ Utils.formatSize(item.exclusiveNativeAllocations); |
+ element.children[1].title = 'memory allocated during execution: ' + |
+ '${item.exclusiveNativeAllocations}B'; |
+ _updateLines(element.children[2].children, depth); |
+ if (item.children.isNotEmpty) { |
+ element.children[3].text = _tree.isExpanded(item) ? '▼' : '►'; |
Cutch
2017/03/23 23:39:44
make these arrows into const strings and reference
bkonyi
2017/03/24 00:53:38
Done.
|
+ } else { |
+ element.children[3].text = ''; |
+ } |
+ element.children[4].text = Utils.formatPercentNormalized(item.percentage); |
+ element.children[5] = new CodeRefElement(null, item.profileCode.code, |
+ queue: _r.queue)..classes = ['name']; |
+ } |
+ |
static _updateLines(List<Element> lines, int n) { |
n = Math.max(0, n); |
while (lines.length > n) { |