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:observatory/service.dart'; | 10 import 'package:observatory/service.dart'; |
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 final CpuProfile profile = new CpuProfile(); | 458 final CpuProfile profile = new CpuProfile(); |
459 | 459 |
460 CpuProfileElement.created() : super.created(); | 460 CpuProfileElement.created() : super.created(); |
461 | 461 |
462 @override | 462 @override |
463 void attached() { | 463 void attached() { |
464 super.attached(); | 464 super.attached(); |
465 } | 465 } |
466 | 466 |
467 void isolateChanged(oldValue) { | 467 void isolateChanged(oldValue) { |
468 _getCpuProfile(); | 468 _getCpuProfile().catchError(app.handleException); |
469 } | 469 } |
470 | 470 |
471 void tagSelectorChanged(oldValue) { | 471 void tagSelectorChanged(oldValue) { |
472 _getCpuProfile(); | 472 _getCpuProfile().catchError(app.handleException); |
473 } | 473 } |
474 | 474 |
475 void modeSelectorChanged(oldValue) { | 475 void modeSelectorChanged(oldValue) { |
476 _updateView(); | 476 _updateView(); |
477 } | 477 } |
478 | 478 |
479 void directionSelectorChanged(oldValue) { | 479 void directionSelectorChanged(oldValue) { |
480 _updateView(); | 480 _updateView(); |
481 } | 481 } |
482 | 482 |
483 void clear(var done) { | 483 Future clearCpuProfile() { |
484 _clearCpuProfile().whenComplete(done); | |
485 } | |
486 | |
487 Future _clearCpuProfile() { | |
488 profile.clear(); | 484 profile.clear(); |
489 if (isolate == null) { | 485 if (isolate == null) { |
490 return new Future.value(null); | 486 return new Future.value(null); |
491 } | 487 } |
492 return isolate.invokeRpc('clearCpuProfile', { }) | 488 return isolate.invokeRpc('clearCpuProfile', { }) |
493 .then((ServiceMap response) { | 489 .then((ServiceMap response) { |
494 _updateView(); | 490 _updateView(); |
495 }); | 491 }); |
496 } | 492 } |
497 | 493 |
498 void refresh(var done) { | 494 Future refresh() { |
499 _getCpuProfile().whenComplete(done); | 495 return _getCpuProfile(); |
500 } | 496 } |
501 | 497 |
502 _onFetchStarted() { | 498 _onFetchStarted() { |
503 _sw.reset(); | 499 _sw.reset(); |
504 _sw.start(); | 500 _sw.start(); |
505 state = 'Requested'; | 501 state = 'Requested'; |
506 } | 502 } |
507 | 503 |
508 _onFetchFinished() { | 504 _onFetchFinished() { |
509 _sw.stop(); | 505 _sw.stop(); |
510 fetchTime = formatTimeMilliseconds(_sw.elapsedMilliseconds); | 506 fetchTime = formatTimeMilliseconds(_sw.elapsedMilliseconds); |
511 } | 507 } |
512 | 508 |
513 Future _onLoadStarted() { | 509 Future _onLoadStarted() { |
514 _sw.reset(); | 510 _sw.reset(); |
515 _sw.start(); | 511 _sw.start(); |
516 state = 'Loading'; | 512 state = 'Loading'; |
517 return window.animationFrame; | 513 return window.animationFrame; |
518 } | 514 } |
519 | 515 |
520 _onLoadFinished() { | 516 _onLoadFinished() { |
521 _sw.stop(); | 517 _sw.stop(); |
522 loadTime = formatTimeMilliseconds(_sw.elapsedMilliseconds); | 518 loadTime = formatTimeMilliseconds(_sw.elapsedMilliseconds); |
523 state = 'Loaded'; | 519 state = 'Loaded'; |
524 } | 520 } |
525 | 521 |
526 Future _getCpuProfile() { | 522 Future _getCpuProfile() async { |
527 profile.clear(); | 523 profile.clear(); |
528 if (functionTree != null) { | 524 if (functionTree != null) { |
529 functionTree.clear(); | 525 functionTree.clear(); |
530 functionTree = null; | 526 functionTree = null; |
531 } | 527 } |
532 if (codeTree != null) { | 528 if (codeTree != null) { |
533 codeTree.clear(); | 529 codeTree.clear(); |
534 codeTree = null; | 530 codeTree = null; |
535 } | 531 } |
536 if (isolate == null) { | 532 if (isolate == null) { |
537 return new Future.value(null); | 533 return new Future.value(null); |
538 } | 534 } |
539 _onFetchStarted(); | 535 _onFetchStarted(); |
540 return isolate.invokeRpc('getCpuProfile', { 'tags': tagSelector }) | 536 try { |
541 .then((response) async { | 537 var params = { 'tags': tagSelector }; |
| 538 var response = await isolate.invokeRpc('getCpuProfile', params); |
542 _onFetchFinished(); | 539 _onFetchFinished(); |
543 await _onLoadStarted(); | 540 await _onLoadStarted(); |
544 try { | 541 profile.load(isolate, response); |
545 profile.load(isolate, response); | 542 _onLoadFinished(); |
546 _onLoadFinished(); | 543 _updateView(); |
547 _updateView(); | 544 } catch (e, st) { |
548 } catch (e, st) { | 545 bool handled = false; |
| 546 if (e is ServerRpcException) { |
| 547 ServerRpcException se = e; |
| 548 if (se.code == ServerRpcException.kProfilingDisabled) { |
| 549 state = 'Disabled'; |
| 550 handled = true; |
| 551 } |
| 552 } |
| 553 if (!handled) { |
549 state = 'Exception'; | 554 state = 'Exception'; |
550 exception = e; | 555 exception = e; |
551 stackTrace = st; | 556 stackTrace = st; |
| 557 rethrow; |
552 } | 558 } |
553 }).catchError((e, st) { | 559 } |
554 state = 'Exception'; | |
555 exception = e; | |
556 stackTrace = st; | |
557 }); | |
558 } | 560 } |
559 | 561 |
560 void _updateView() { | 562 void _updateView() { |
561 sampleCount = profile.sampleCount.toString(); | 563 sampleCount = profile.sampleCount.toString(); |
562 refreshTime = new DateTime.now().toString(); | 564 refreshTime = new DateTime.now().toString(); |
563 stackDepth = profile.stackDepth.toString(); | 565 stackDepth = profile.stackDepth.toString(); |
564 sampleRate = profile.sampleRate.toStringAsFixed(0); | 566 sampleRate = profile.sampleRate.toStringAsFixed(0); |
565 timeSpan = formatTime(profile.timeSpan); | 567 timeSpan = formatTime(profile.timeSpan); |
566 bool exclusive = directionSelector == 'Up'; | 568 bool exclusive = directionSelector == 'Up'; |
567 if (functionTree != null) { | 569 if (functionTree != null) { |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
787 _updateSize() { | 789 _updateSize() { |
788 HtmlElement e = $['main']; | 790 HtmlElement e = $['main']; |
789 final totalHeight = window.innerHeight; | 791 final totalHeight = window.innerHeight; |
790 final top = e.offset.top; | 792 final top = e.offset.top; |
791 final bottomMargin = 32; | 793 final bottomMargin = 32; |
792 final mainHeight = totalHeight - top - bottomMargin; | 794 final mainHeight = totalHeight - top - bottomMargin; |
793 e.style.setProperty('height', '${mainHeight}px'); | 795 e.style.setProperty('height', '${mainHeight}px'); |
794 } | 796 } |
795 | 797 |
796 isolateChanged() { | 798 isolateChanged() { |
797 _getCpuProfile().whenComplete(checkParameters); | 799 _getCpuProfile() |
| 800 .catchError(app.handleException) |
| 801 .whenComplete(checkParameters); |
798 } | 802 } |
799 | 803 |
800 checkParameters() { | 804 checkParameters() { |
801 var functionId = app.locationManager.uri.queryParameters['functionId']; | 805 var functionId = app.locationManager.uri.queryParameters['functionId']; |
802 if (functionId == null) { | 806 if (functionId == null) { |
803 _focusOnFunction(null); | 807 _focusOnFunction(null); |
804 return; | 808 return; |
805 } | 809 } |
806 if (isolate == null) { | 810 if (isolate == null) { |
807 return; | 811 return; |
808 } | 812 } |
809 isolate.getObject(functionId).then((func) => _focusOnFunction(func)); | 813 isolate.getObject(functionId).then((func) => _focusOnFunction(func)); |
810 } | 814 } |
811 | 815 |
812 void directionSelectorChanged(oldValue) { | 816 void directionSelectorChanged(oldValue) { |
813 _updateFunctionTreeView(); | 817 _updateFunctionTreeView(); |
814 } | 818 } |
815 | 819 |
816 void refresh(var done) { | 820 Future refresh() { |
817 _getCpuProfile().whenComplete(done); | 821 return _getCpuProfile(); |
818 } | |
819 | |
820 void clear(var done) { | |
821 _clearCpuProfile().whenComplete(done); | |
822 } | 822 } |
823 | 823 |
824 _onFetchStarted() { | 824 _onFetchStarted() { |
825 _sw.reset(); | 825 _sw.reset(); |
826 _sw.start(); | 826 _sw.start(); |
827 state = 'Requested'; | 827 state = 'Requested'; |
828 } | 828 } |
829 | 829 |
830 _onFetchFinished() { | 830 _onFetchFinished() { |
831 _sw.stop(); | 831 _sw.stop(); |
832 fetchTime = formatTimeMilliseconds(_sw.elapsedMilliseconds); | 832 fetchTime = formatTimeMilliseconds(_sw.elapsedMilliseconds); |
833 } | 833 } |
834 | 834 |
835 _onLoadStarted() { | 835 _onLoadStarted() { |
836 _sw.reset(); | 836 _sw.reset(); |
837 _sw.start(); | 837 _sw.start(); |
838 state = 'Loading'; | 838 state = 'Loading'; |
839 } | 839 } |
840 | 840 |
841 _onLoadFinished() { | 841 _onLoadFinished() { |
842 _sw.stop(); | 842 _sw.stop(); |
843 loadTime = formatTimeMilliseconds(_sw.elapsedMilliseconds); | 843 loadTime = formatTimeMilliseconds(_sw.elapsedMilliseconds); |
844 state = 'Loaded'; | 844 state = 'Loaded'; |
845 } | 845 } |
846 | 846 |
847 Future _clearCpuProfile() { | 847 Future clearCpuProfile() { |
848 profile.clear(); | 848 profile.clear(); |
849 _clearView(); | 849 _clearView(); |
850 if (isolate == null) { | 850 if (isolate == null) { |
851 return new Future.value(null); | 851 return new Future.value(null); |
852 } | 852 } |
853 return isolate.invokeRpc('clearCpuProfile', { }) | 853 return isolate.invokeRpc('clearCpuProfile', { }) |
854 .then((ServiceMap response) { | 854 .then((ServiceMap response) { |
855 _updateView(); | 855 _updateView(); |
856 }); | 856 }); |
857 } | 857 } |
858 | 858 |
859 Future _getCpuProfile() { | 859 Future _getCpuProfile() async { |
860 profile.clear(); | 860 profile.clear(); |
861 _clearView(); | 861 _clearView(); |
862 if (isolate == null) { | 862 if (isolate == null) { |
863 return new Future.value(null); | 863 return new Future.value(null); |
864 } | 864 } |
865 _onFetchStarted(); | 865 _onFetchStarted(); |
866 return isolate.invokeRpc('getCpuProfile', { 'tags': 'None' }) | 866 try { |
867 .then((response) { | 867 var params = { 'tags': 'None' }; |
| 868 var response = await isolate.invokeRpc('getCpuProfile', params); |
868 _onFetchFinished(); | 869 _onFetchFinished(); |
869 _onLoadStarted(); | 870 _onLoadStarted(); |
870 try { | 871 profile.load(isolate, response); |
871 profile.load(isolate, response); | 872 profile.buildFunctionCallerAndCallees(); |
872 profile.buildFunctionCallerAndCallees(); | 873 _onLoadFinished(); |
873 _onLoadFinished(); | 874 _updateView(); |
874 _updateView(); | 875 } catch (e, st) { |
875 } catch (e, st) { | 876 bool handled = false; |
| 877 if (e is ServerRpcException) { |
| 878 ServerRpcException se = e; |
| 879 if (se.code == ServerRpcException.kProfilingDisabled) { |
| 880 state = 'Disabled'; |
| 881 handled = true; |
| 882 } |
| 883 } |
| 884 if (!handled) { |
876 state = 'Exception'; | 885 state = 'Exception'; |
877 exception = e; | 886 exception = e; |
878 stackTrace = st; | 887 stackTrace = st; |
| 888 rethrow; |
879 } | 889 } |
880 }).catchError((e, st) { | 890 } |
881 state = 'Exception'; | |
882 exception = e; | |
883 stackTrace = st; | |
884 }); | |
885 } | 891 } |
886 | 892 |
887 _clearView() { | 893 _clearView() { |
888 profileTable.clearRows(); | 894 profileTable.clearRows(); |
889 _renderTable(); | 895 _renderTable(); |
890 } | 896 } |
891 | 897 |
892 _updateView() { | 898 _updateView() { |
893 sampleCount = profile.sampleCount.toString(); | 899 sampleCount = profile.sampleCount.toString(); |
894 refreshTime = new DateTime.now().toString(); | 900 refreshTime = new DateTime.now().toString(); |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1117 } | 1123 } |
1118 var filter = (FunctionCallTreeNode node) { | 1124 var filter = (FunctionCallTreeNode node) { |
1119 return node.profileFunction.function == focusedFunction; | 1125 return node.profileFunction.function == focusedFunction; |
1120 }; | 1126 }; |
1121 tree = tree.filtered(filter); | 1127 tree = tree.filtered(filter); |
1122 var rootRow = | 1128 var rootRow = |
1123 new FunctionProfileTreeRow(functionTree, null, profile, tree.root); | 1129 new FunctionProfileTreeRow(functionTree, null, profile, tree.root); |
1124 functionTree.initialize(rootRow); | 1130 functionTree.initialize(rootRow); |
1125 } | 1131 } |
1126 } | 1132 } |
OLD | NEW |