| OLD | NEW |
| 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:logging/logging.dart'; | 10 import 'package:logging/logging.dart'; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 } | 52 } |
| 53 | 53 |
| 54 makeInfoBox() { | 54 makeInfoBox() { |
| 55 if (infoBox != null) { | 55 if (infoBox != null) { |
| 56 return; | 56 return; |
| 57 } | 57 } |
| 58 infoBox = new DivElement(); | 58 infoBox = new DivElement(); |
| 59 infoBox.classes.add('infoBox'); | 59 infoBox.classes.add('infoBox'); |
| 60 infoBox.classes.add('shadow'); | 60 infoBox.classes.add('shadow'); |
| 61 infoBox.style.display = 'none'; | 61 infoBox.style.display = 'none'; |
| 62 infoBox.onClick.listen((e) => e.stopPropagation()); | 62 listeners.add(infoBox.onClick.listen((e) => e.stopPropagation())); |
| 63 } | 63 } |
| 64 | 64 |
| 65 makeInfoButton() { | 65 makeInfoButton() { |
| 66 infoButton = new SpanElement(); | 66 infoButton = new SpanElement(); |
| 67 infoButton.style.marginLeft = 'auto'; | 67 infoButton.style.marginLeft = 'auto'; |
| 68 infoButton.style.marginRight = '1em'; | 68 infoButton.style.marginRight = '1em'; |
| 69 infoButton.children.add(new Element.tag('icon-info-outline')); | 69 infoButton.children.add(new Element.tag('icon-info-outline')); |
| 70 infoButton.onClick.listen((event) { | 70 listeners.add(infoButton.onClick.listen((event) { |
| 71 event.stopPropagation(); | 71 event.stopPropagation(); |
| 72 toggleInfoBox(); | 72 toggleInfoBox(); |
| 73 }); | 73 })); |
| 74 } | 74 } |
| 75 | 75 |
| 76 static const attributes = const { | 76 static const attributes = const { |
| 77 'optimized' : const ['O', null, 'Optimized'], | 77 'optimized' : const ['O', null, 'Optimized'], |
| 78 'unoptimized' : const ['U', null, 'Unoptimized'], | 78 'unoptimized' : const ['U', null, 'Unoptimized'], |
| 79 'inlined' : const ['I', null, 'Inlined'], | 79 'inlined' : const ['I', null, 'Inlined'], |
| 80 'dart' : const ['D', null, 'Dart'], | 80 'dart' : const ['D', null, 'Dart'], |
| 81 'tag' : const ['T', null, 'Tag'], | 81 'tag' : const ['T', null, 'Tag'], |
| 82 'native' : const ['N', null, 'Native'], | 82 'native' : const ['N', null, 'Native'], |
| 83 'stub': const ['S', null, 'Stub'], | 83 'stub': const ['S', null, 'Stub'], |
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 _sw.start(); | 516 _sw.start(); |
| 517 state = 'Loading'; | 517 state = 'Loading'; |
| 518 } | 518 } |
| 519 | 519 |
| 520 _onLoadFinished() { | 520 _onLoadFinished() { |
| 521 _sw.stop(); | 521 _sw.stop(); |
| 522 loadTime = formatTimeMilliseconds(_sw.elapsedMilliseconds); | 522 loadTime = formatTimeMilliseconds(_sw.elapsedMilliseconds); |
| 523 state = 'Loaded'; | 523 state = 'Loaded'; |
| 524 } | 524 } |
| 525 | 525 |
| 526 Future _getCpuProfile() async { | 526 Future _getCpuProfile() { |
| 527 profile.clear(); | 527 profile.clear(); |
| 528 if (functionTree != null) { | 528 if (functionTree != null) { |
| 529 functionTree.clear(); | 529 functionTree.clear(); |
| 530 functionTree = null; |
| 530 } | 531 } |
| 531 if (codeTree != null) { | 532 if (codeTree != null) { |
| 532 codeTree.clear(); | 533 codeTree.clear(); |
| 534 codeTree = null; |
| 533 } | 535 } |
| 534 if (isolate == null) { | 536 if (isolate == null) { |
| 535 return new Future.value(null); | 537 return new Future.value(null); |
| 536 } | 538 } |
| 537 _onFetchStarted(); | 539 _onFetchStarted(); |
| 538 var response = | 540 return isolate.invokeRpc('getCpuProfile', { 'tags': tagSelector }) |
| 539 await isolate.invokeRpc('getCpuProfile', { 'tags': tagSelector }); | 541 .then((response) { |
| 540 _onFetchFinished(); | 542 _onFetchFinished(); |
| 541 _onLoadStarted(); | 543 _onLoadStarted(); |
| 542 await window.animationFrame; | 544 try { |
| 543 try { | 545 profile.load(isolate, response); |
| 544 profile.load(isolate, response); | 546 _onLoadFinished(); |
| 545 _onLoadFinished(); | 547 _updateView(); |
| 546 _updateView(); | 548 } catch (e, st) { |
| 547 } catch (e, st) { | 549 state = 'Exception'; |
| 550 exception = e; |
| 551 stackTrace = st; |
| 552 } |
| 553 }).catchError((e, st) { |
| 548 state = 'Exception'; | 554 state = 'Exception'; |
| 549 exception = e; | 555 exception = e; |
| 550 stackTrace = st; | 556 stackTrace = st; |
| 551 } | 557 }); |
| 552 } | 558 } |
| 553 | 559 |
| 554 void _updateView() { | 560 void _updateView() { |
| 555 sampleCount = profile.sampleCount.toString(); | 561 sampleCount = profile.sampleCount.toString(); |
| 556 refreshTime = new DateTime.now().toString(); | 562 refreshTime = new DateTime.now().toString(); |
| 557 stackDepth = profile.stackDepth.toString(); | 563 stackDepth = profile.stackDepth.toString(); |
| 558 sampleRate = profile.sampleRate.toStringAsFixed(0); | 564 sampleRate = profile.sampleRate.toStringAsFixed(0); |
| 559 timeSpan = formatTime(profile.timeSpan); | 565 timeSpan = formatTime(profile.timeSpan); |
| 566 bool exclusive = directionSelector == 'Up'; |
| 560 if (functionTree != null) { | 567 if (functionTree != null) { |
| 561 functionTree.clear(); | 568 functionTree.clear(); |
| 569 functionTree = null; |
| 562 } | 570 } |
| 563 if (codeTree != null) { | 571 if (codeTree != null) { |
| 564 codeTree.clear(); | 572 codeTree.clear(); |
| 573 codeTree = null; |
| 565 } | 574 } |
| 566 bool exclusive = directionSelector == 'Up'; | |
| 567 if (modeSelector == 'Code') { | 575 if (modeSelector == 'Code') { |
| 568 _buildCodeTree(exclusive); | 576 _buildCodeTree(exclusive); |
| 569 } else { | 577 } else { |
| 570 _buildFunctionTree(exclusive); | 578 _buildFunctionTree(exclusive); |
| 571 } | 579 } |
| 572 } | 580 } |
| 573 | 581 |
| 574 TableTree codeTree; | 582 TableTree codeTree; |
| 575 TableTree functionTree; | 583 TableTree functionTree; |
| 576 | 584 |
| 577 void _buildFunctionTree(bool exclusive) { | 585 void _buildFunctionTree(bool exclusive) { |
| 578 if (functionTree == null) { | 586 if (functionTree == null) { |
| 579 var tableBody = shadowRoot.querySelector('#treeBody'); | 587 var tableBody = shadowRoot.querySelector('#treeBody'); |
| 580 assert(tableBody != null); | 588 assert(tableBody != null); |
| 581 functionTree = new TableTree(tableBody, 2); | 589 functionTree = new TableTree(tableBody, 2); |
| 582 } | 590 } |
| 583 var tree = profile.functionTrees[exclusive ? 'exclusive' : 'inclusive']; | 591 var tree = profile.loadFunctionTree(exclusive ? 'exclusive' : 'inclusive'); |
| 584 if (tree == null) { | 592 if (tree == null) { |
| 585 return; | 593 return; |
| 586 } | 594 } |
| 587 var rootRow = | 595 var rootRow = |
| 588 new FunctionProfileTreeRow(functionTree, null, profile, tree.root); | 596 new FunctionProfileTreeRow(functionTree, null, profile, tree.root); |
| 589 functionTree.initialize(rootRow); | 597 functionTree.initialize(rootRow); |
| 590 } | 598 } |
| 591 | 599 |
| 592 void _buildCodeTree(bool exclusive) { | 600 void _buildCodeTree(bool exclusive) { |
| 593 if (codeTree == null) { | 601 if (codeTree == null) { |
| 594 var tableBody = shadowRoot.querySelector('#treeBody'); | 602 var tableBody = shadowRoot.querySelector('#treeBody'); |
| 595 assert(tableBody != null); | 603 assert(tableBody != null); |
| 596 codeTree = new TableTree(tableBody, 2); | 604 codeTree = new TableTree(tableBody, 2); |
| 597 } | 605 } |
| 598 var tree = profile.codeTrees[exclusive ? 'exclusive' : 'inclusive']; | 606 var tree = profile.loadCodeTree(exclusive ? 'exclusive' : 'inclusive'); |
| 599 if (tree == null) { | 607 if (tree == null) { |
| 600 return; | 608 return; |
| 601 } | 609 } |
| 602 var rootRow = new CodeProfileTreeRow(codeTree, null, profile, tree.root); | 610 var rootRow = new CodeProfileTreeRow(codeTree, null, profile, tree.root); |
| 603 codeTree.initialize(rootRow); | 611 codeTree.initialize(rootRow); |
| 604 } | 612 } |
| 605 } | 613 } |
| OLD | NEW |