Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(316)

Side by Side Diff: runtime/observatory/lib/src/elements/cpu_profile.dart

Issue 1241653002: Factor cpu profile tree into separate element and expose allocation tracing UI (Closed) Base URL: git@github.com:dart-lang/sdk.git@expose_allocation_profile_service
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 cpu_profile_element; 5 library cpu_profile_element;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:html'; 8 import 'dart:html';
9 import 'observatory_element.dart'; 9 import 'observatory_element.dart';
10 import 'package:observatory/service.dart'; 10 import 'package:observatory/service.dart';
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 } 514 }
515 515
516 _onLoadFinished() { 516 _onLoadFinished() {
517 _sw.stop(); 517 _sw.stop();
518 loadTime = formatTimeMilliseconds(_sw.elapsedMilliseconds); 518 loadTime = formatTimeMilliseconds(_sw.elapsedMilliseconds);
519 state = 'Loaded'; 519 state = 'Loaded';
520 } 520 }
521 521
522 Future _getCpuProfile() async { 522 Future _getCpuProfile() async {
523 profile.clear(); 523 profile.clear();
524 if (functionTree != null) {
525 functionTree.clear();
526 functionTree = null;
527 }
528 if (codeTree != null) {
529 codeTree.clear();
530 codeTree = null;
531 }
532 if (isolate == null) { 524 if (isolate == null) {
533 return new Future.value(null); 525 return new Future.value(null);
534 } 526 }
535 _onFetchStarted(); 527 _onFetchStarted();
536 try { 528 try {
537 var params = { 'tags': tagSelector }; 529 var params = { 'tags': tagSelector };
538 var response = await isolate.invokeRpc('_getCpuProfile', params); 530 var response = await isolate.invokeRpc('_getCpuProfile', params);
539 _onFetchFinished(); 531 _onFetchFinished();
540 await _onLoadStarted(); 532 await _onLoadStarted();
541 profile.load(isolate, response); 533 profile.load(isolate, response);
(...skipping 16 matching lines...) Expand all
558 } 550 }
559 } 551 }
560 } 552 }
561 553
562 void _updateView() { 554 void _updateView() {
563 sampleCount = profile.sampleCount.toString(); 555 sampleCount = profile.sampleCount.toString();
564 refreshTime = new DateTime.now().toString(); 556 refreshTime = new DateTime.now().toString();
565 stackDepth = profile.stackDepth.toString(); 557 stackDepth = profile.stackDepth.toString();
566 sampleRate = profile.sampleRate.toStringAsFixed(0); 558 sampleRate = profile.sampleRate.toStringAsFixed(0);
567 timeSpan = formatTime(profile.timeSpan); 559 timeSpan = formatTime(profile.timeSpan);
568 bool exclusive = directionSelector == 'Up'; 560 CpuProfileTreeElement cpuProfileTreeElement =
569 if (functionTree != null) { 561 shadowRoot.querySelector('#cpuProfileTree');
570 functionTree.clear(); 562 ProfileTreeDirection direction = ProfileTreeDirection.Exclusive;
571 functionTree = null; 563 if (directionSelector != 'Up') {
564 direction = ProfileTreeDirection.Inclusive;
572 } 565 }
573 if (codeTree != null) { 566 ProfileTreeMode mode = ProfileTreeMode.Function;
574 codeTree.clear(); 567 if (modeSelector == 'Code') {
575 codeTree = null; 568 mode = ProfileTreeMode.Code;
576 } 569 }
577 if (modeSelector == 'Code') { 570 cpuProfileTreeElement.profile = profile;
578 _buildCodeTree(exclusive); 571 cpuProfileTreeElement.direction = direction;
579 } else { 572 cpuProfileTreeElement.mode = mode;
580 _buildFunctionTree(exclusive); 573 cpuProfileTreeElement.render();
581 }
582 }
583
584 TableTree codeTree;
585 TableTree functionTree;
586
587 void _buildFunctionTree(bool exclusive) {
588 if (functionTree == null) {
589 var tableBody = shadowRoot.querySelector('#treeBody');
590 assert(tableBody != null);
591 functionTree = new TableTree(tableBody, 2);
592 }
593 var tree = profile.loadFunctionTree(exclusive ? 'exclusive' : 'inclusive');
594 if (tree == null) {
595 return;
596 }
597 var rootRow =
598 new FunctionProfileTreeRow(functionTree, null, profile, tree.root);
599 functionTree.initialize(rootRow);
600 }
601
602 void _buildCodeTree(bool exclusive) {
603 if (codeTree == null) {
604 var tableBody = shadowRoot.querySelector('#treeBody');
605 assert(tableBody != null);
606 codeTree = new TableTree(tableBody, 2);
607 }
608 var tree = profile.loadCodeTree(exclusive ? 'exclusive' : 'inclusive');
609 if (tree == null) {
610 return;
611 }
612 var rootRow = new CodeProfileTreeRow(codeTree, null, profile, tree.root);
613 codeTree.initialize(rootRow);
614 } 574 }
615 } 575 }
616 576
617 class NameSortedTable extends SortedTable { 577 class NameSortedTable extends SortedTable {
618 NameSortedTable(columns) : super(columns); 578 NameSortedTable(columns) : super(columns);
619 @override 579 @override
620 dynamic getSortKeyFor(int row, int col) { 580 dynamic getSortKeyFor(int row, int col) {
621 if (col == FUNCTION_COLUMN) { 581 if (col == FUNCTION_COLUMN) {
622 // Use name as sort key. 582 // Use name as sort key.
623 return rows[row].values[col].name; 583 return rows[row].values[col].name;
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after
1093 _changeSort(target, profileCalleesTable); 1053 _changeSort(target, profileCalleesTable);
1094 _renderCallTable($['callees-table'], profileCalleesTable, _onCalleesClick); 1054 _renderCallTable($['callees-table'], profileCalleesTable, _onCalleesClick);
1095 } 1055 }
1096 1056
1097 ////// 1057 //////
1098 /// 1058 ///
1099 /// Function tree. 1059 /// Function tree.
1100 /// 1060 ///
1101 TableTree functionTree; 1061 TableTree functionTree;
1102 _updateFunctionTreeView() { 1062 _updateFunctionTreeView() {
1063 CpuProfileTreeElement cpuProfileTreeElement =
1064 shadowRoot.querySelector('#cpuProfileTree');
1065 ProfileTreeDirection direction = ProfileTreeDirection.Exclusive;
1066 if (directionSelector != 'Up') {
1067 direction = ProfileTreeDirection.Inclusive;
1068 }
1069 ProfileTreeMode mode = ProfileTreeMode.Function;
1070 cpuProfileTreeElement.profile = profile;
1071 cpuProfileTreeElement.direction = direction;
1072 cpuProfileTreeElement.mode = mode;
1073 cpuProfileTreeElement.functionFilter = (FunctionCallTreeNode node) {
1074 return node.profileFunction.function == focusedFunction;
1075 };
1076 cpuProfileTreeElement.render();
1077 }
1078 }
1079
1080 enum ProfileTreeDirection {
1081 Exclusive,
1082 Inclusive
1083 }
1084
1085 enum ProfileTreeMode {
1086 Code,
1087 Function,
1088 }
1089
1090 @CustomTag('cpu-profile-tree')
1091 class CpuProfileTreeElement extends ObservatoryElement {
1092 ProfileTreeDirection direction = ProfileTreeDirection.Exclusive;
1093 ProfileTreeMode mode = ProfileTreeMode.Function;
1094 CpuProfile profile;
1095 TableTree codeTree;
1096 TableTree functionTree;
1097 FunctionCallTreeNodeFilter functionFilter;
1098
1099 CpuProfileTreeElement.created() : super.created();
1100
1101 void render() {
1102 _updateView();
1103 }
1104
1105 void _updateView() {
1103 if (functionTree != null) { 1106 if (functionTree != null) {
1104 functionTree.clear(); 1107 functionTree.clear();
1105 functionTree = null; 1108 functionTree = null;
1106 } 1109 }
1107 _buildFunctionTree(); 1110 if (codeTree != null) {
1111 codeTree.clear();
1112 codeTree = null;
1113 }
1114 bool exclusive = direction == ProfileTreeDirection.Exclusive;
1115 if (mode == ProfileTreeMode.Code) {
1116 _buildCodeTree(exclusive);
1117 } else {
1118 assert(mode == ProfileTreeMode.Function);
1119 _buildFunctionTree(exclusive);
1120 }
1108 } 1121 }
1109 1122
1110 void _buildFunctionTree() { 1123 void _buildFunctionTree(bool exclusive) {
1111 if (functionTree == null) { 1124 if (functionTree == null) {
1112 var tableBody = shadowRoot.querySelector('#treeBody'); 1125 var tableBody = shadowRoot.querySelector('#treeBody');
1113 assert(tableBody != null); 1126 assert(tableBody != null);
1114 functionTree = new TableTree(tableBody, 2); 1127 functionTree = new TableTree(tableBody, 2);
1115 } 1128 }
1116 if (focusedFunction == null) { 1129 if (profile == null) {
1117 return; 1130 return;
1118 } 1131 }
1119 bool exclusive = directionSelector == 'Up';
1120 var tree = profile.loadFunctionTree(exclusive ? 'exclusive' : 'inclusive'); 1132 var tree = profile.loadFunctionTree(exclusive ? 'exclusive' : 'inclusive');
1121 if (tree == null) { 1133 if (tree == null) {
1122 return; 1134 return;
1123 } 1135 }
1124 var filter = (FunctionCallTreeNode node) { 1136 if (functionFilter != null) {
1125 return node.profileFunction.function == focusedFunction; 1137 tree = tree.filtered(functionFilter);
1126 }; 1138 }
1127 tree = tree.filtered(filter);
1128 var rootRow = 1139 var rootRow =
1129 new FunctionProfileTreeRow(functionTree, null, profile, tree.root); 1140 new FunctionProfileTreeRow(functionTree, null, profile, tree.root);
1130 functionTree.initialize(rootRow); 1141 functionTree.initialize(rootRow);
1131 } 1142 }
1143
1144 void _buildCodeTree(bool exclusive) {
1145 if (codeTree == null) {
1146 var tableBody = shadowRoot.querySelector('#treeBody');
1147 assert(tableBody != null);
1148 codeTree = new TableTree(tableBody, 2);
1149 }
1150 if (profile == null) {
1151 return;
1152 }
1153 var tree = profile.loadCodeTree(exclusive ? 'exclusive' : 'inclusive');
1154 if (tree == null) {
1155 return;
1156 }
1157 var rootRow = new CodeProfileTreeRow(codeTree, null, profile, tree.root);
1158 codeTree.initialize(rootRow);
1159 }
1132 } 1160 }
OLDNEW
« no previous file with comments | « runtime/observatory/lib/src/elements/class_view.html ('k') | runtime/observatory/lib/src/elements/cpu_profile.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698