Chromium Code Reviews| 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 isolate_profile_element; | 5 library isolate_profile_element; |
| 6 | 6 |
| 7 import 'dart:convert'; | |
| 8 import 'dart:html'; | 7 import 'dart:html'; |
| 9 import 'package:dprof/model.dart' as dprof; | 8 import 'package:logging/logging.dart'; |
| 10 import 'package:polymer/polymer.dart'; | 9 import 'package:polymer/polymer.dart'; |
| 11 import 'observatory_element.dart'; | 10 import 'observatory_element.dart'; |
| 12 | 11 |
| 13 /// Displays an IsolateProfile | 12 /// Displays an IsolateProfile |
| 14 @CustomTag('isolate-profile') | 13 @CustomTag('isolate-profile') |
| 15 class IsolateProfileElement extends ObservatoryElement { | 14 class IsolateProfileElement extends ObservatoryElement { |
| 16 IsolateProfileElement.created() : super.created(); | 15 IsolateProfileElement.created() : super.created(); |
| 17 @observable int methodCountSelected = 0; | 16 @observable int methodCountSelected = 0; |
| 18 final List methodCounts = [10, 20, 50]; | 17 final List methodCounts = [10, 20, 50]; |
| 19 @observable List topInclusiveCodes = toObservable([]); | 18 @observable List topInclusiveCodes = toObservable([]); |
| 20 @observable List topExclusiveCodes = toObservable([]); | 19 @observable List topExclusiveCodes = toObservable([]); |
| 21 @observable bool disassemble = false; | 20 |
| 21 void enteredView() { | |
| 22 var isolateId = app.locationManager.currentIsolateId(); | |
| 23 var isolate = app.isolateManager.getIsolate(isolateId); | |
| 24 if (isolate == null) { | |
| 25 return; | |
| 26 } | |
| 27 _refreshTopMethods(isolate); | |
| 28 } | |
| 29 | |
| 22 void _startRequest() { | 30 void _startRequest() { |
| 23 // TODO(johnmccutchan): Indicate visually. | 31 // TODO(johnmccutchan): Indicate visually. |
| 24 print('Request sent.'); | |
| 25 } | 32 } |
| 26 | 33 |
| 27 void _endRequest() { | 34 void _endRequest() { |
| 28 // TODO(johnmccutchan): Indicate visually. | 35 // TODO(johnmccutchan): Indicate visually. |
| 29 print('Request finished.'); | |
| 30 } | 36 } |
| 31 | 37 |
| 32 methodCountSelectedChanged(oldValue) { | 38 methodCountSelectedChanged(oldValue) {; |
| 33 print('Refresh top'); | |
| 34 var isolateId = app.locationManager.currentIsolateId(); | 39 var isolateId = app.locationManager.currentIsolateId(); |
| 35 var isolate = app.isolateManager.getIsolate(isolateId); | 40 var isolate = app.isolateManager.getIsolate(isolateId); |
| 36 if (isolate == null) { | 41 if (isolate == null) { |
| 37 print('No isolate found.'); | 42 return; |
| 38 } | 43 } |
| 39 _refreshTopMethods(isolate); | 44 _refreshTopMethods(isolate); |
| 40 } | 45 } |
| 41 | 46 |
| 42 void toggleDisassemble(Event e, var detail, CheckboxInputElement target) { | |
| 43 disassemble = target.checked; | |
| 44 print(disassemble); | |
| 45 } | |
| 46 | |
| 47 void refreshData(Event e, var detail, Node target) { | 47 void refreshData(Event e, var detail, Node target) { |
| 48 var isolateId = app.locationManager.currentIsolateId(); | 48 var isolateId = app.locationManager.currentIsolateId(); |
| 49 var isolate = app.isolateManager.getIsolate(isolateId); | 49 var isolate = app.isolateManager.getIsolate(isolateId); |
| 50 if (isolate == null) { | 50 if (isolate == null) { |
| 51 print('No isolate found.'); | 51 Logger.root.info('No isolate found.'); |
| 52 return; | |
| 52 } | 53 } |
| 53 var request = '/$isolateId/profile'; | 54 var request = '/$isolateId/profile'; |
| 54 _startRequest(); | 55 _startRequest(); |
| 55 app.requestManager.request(request).then((response) { | 56 app.requestManager.requestMap(request).then((Map profile) { |
| 56 var profile; | 57 assert(profile['type'] == 'Profile'); |
| 57 try { | 58 var samples = profile['samples']; |
| 58 profile = JSON.decode(response); | 59 Logger.root.info('Profile contains ${samples} samples.'); |
| 59 } catch (e) { print(e); } | 60 _loadProfileData(isolate, samples, profile); |
| 60 if ((profile is Map) && (profile['type'] == 'Profile')) { | |
| 61 var codes = profile['codes']; | |
| 62 var samples = profile['samples']; | |
| 63 _loadProfileData(isolate, samples, codes); | |
| 64 } | |
| 65 _endRequest(); | 61 _endRequest(); |
| 66 }).catchError((e) { | 62 }).catchError((e) { |
| 67 _endRequest(); | 63 _endRequest(); |
| 68 }); | 64 }); |
| 69 } | 65 } |
| 70 | 66 |
| 71 void _loadProfileData(Isolate isolate, int totalSamples, List codes) { | 67 void _loadProfileData(Isolate isolate, int totalSamples, Map response) { |
| 72 isolate.profiler = new dprof.Isolate(0, 0); | 68 isolate.profile = new Profile.fromMap(isolate, response); |
| 73 var loader = new dprof.Loader(isolate.profiler); | |
| 74 loader.load(totalSamples, codes); | |
| 75 _refreshTopMethods(isolate); | 69 _refreshTopMethods(isolate); |
| 76 } | 70 } |
| 77 | 71 |
| 78 void _refreshTopMethods(Isolate isolate) { | 72 void _refreshTopMethods(Isolate isolate) { |
| 79 topExclusiveCodes.clear(); | 73 topExclusiveCodes.clear(); |
| 80 topInclusiveCodes.clear(); | 74 topInclusiveCodes.clear(); |
| 81 if ((isolate == null) || (isolate.profiler == null)) { | 75 if ((isolate == null) || (isolate.profile == null)) { |
| 82 return; | 76 return; |
| 83 } | 77 } |
| 84 var count = methodCounts[methodCountSelected]; | 78 var count = methodCounts[methodCountSelected]; |
| 85 var topExclusive = isolate.profiler.topExclusive(count); | 79 var topExclusive = isolate.profile.topExclusive(count); |
| 86 topExclusiveCodes.addAll(topExclusive); | 80 topExclusiveCodes.addAll(topExclusive); |
| 87 var topInclusive = isolate.profiler.topInclusive(count); | 81 var topInclusive = isolate.profile.topInclusive(count); |
| 88 topInclusiveCodes.addAll(topInclusive); | 82 topInclusiveCodes.addAll(topInclusive); |
| 89 | 83 |
| 90 } | 84 } |
| 91 | 85 |
| 92 String codeTicks(dprof.Code code, bool inclusive) { | 86 String codeTicks(Code code, bool inclusive) { |
| 93 if (code == null) { | 87 if (code == null) { |
| 94 return ''; | 88 return ''; |
| 95 } | 89 } |
| 96 return inclusive ? '${code.inclusiveTicks}' : '${code.exclusiveTicks}'; | 90 return inclusive ? '${code.inclusiveTicks}' : '${code.exclusiveTicks}'; |
| 97 } | 91 } |
| 98 | 92 |
| 99 String codePercent(dprof.Code code, bool inclusive) { | 93 String codePercent(Code code, bool inclusive) { |
| 100 if (code == null) { | 94 if (code == null) { |
| 101 return ''; | 95 return ''; |
| 102 } | 96 } |
| 103 var isolateId = app.locationManager.currentIsolateId(); | 97 var isolateId = app.locationManager.currentIsolateId(); |
| 104 var isolate = app.isolateManager.getIsolate(isolateId); | 98 var isolate = app.isolateManager.getIsolate(isolateId); |
| 105 if (isolate == null) { | 99 if (isolate == null) { |
| 106 return ''; | 100 return ''; |
| 107 } | 101 } |
| 108 var ticks = inclusive ? code.inclusiveTicks : code.exclusiveTicks; | 102 var ticks = inclusive ? code.inclusiveTicks : code.exclusiveTicks; |
| 109 var total = ticks / isolate.profiler.totalSamples; | 103 var total = ticks / isolate.profile.totalSamples; |
| 110 return (total * 100.0).toStringAsFixed(2); | 104 return (total * 100.0).toStringAsFixed(2); |
| 111 } | 105 } |
| 112 | 106 |
| 113 String codeName(dprof.Code code) { | 107 String codeName(Code code) { |
| 114 if ((code == null) || (code.method == null)) { | 108 if ((code == null) || (code.name == null)) { |
| 115 return ''; | 109 return ''; |
| 116 } | 110 } |
| 117 return code.method.name; | 111 return code.name; |
| 118 } | 112 } |
| 119 | 113 |
| 120 String instructionTicks(dprof.Instruction instruction) { | 114 String codeUrl(Code code) { |
| 121 if (instruction == null) { | 115 if ((code == null) || (code.name == null)) { |
| 122 return ''; | 116 return ''; |
| 123 } | 117 } |
| 124 if (instruction.ticks == 0) { | 118 if (code.kind != CodeKind.Dart) { |
| 125 return ''; | 119 return ''; |
| 126 } | 120 } |
|
turnidge
2014/01/17 19:30:21
This function looks wrong. Where is the main retu
Cutch
2014/01/17 21:15:42
Both were dead code. Removed.
| |
| 127 return '${instruction.ticks}'; | |
| 128 } | 121 } |
| 129 | 122 |
| 130 String instructionPercent(dprof.Instruction instruction, | 123 String codeUrlName(Code code) { |
| 131 dprof.Code code) { | 124 if ((code == null) || (code.name == null)) { |
| 132 if ((instruction == null) || (code == null)) { | |
| 133 return ''; | 125 return ''; |
| 134 } | 126 } |
| 135 if (instruction.ticks == 0) { | 127 if (code.kind != CodeKind.Dart) { |
| 136 return ''; | 128 return ''; |
| 137 } | 129 } |
| 138 var ticks = instruction.ticks; | |
| 139 var total = ticks / code.inclusiveTicks; | |
| 140 return (total * 100.0).toStringAsFixed(2); | |
| 141 } | |
| 142 | |
| 143 String instructionDisplay(dprof.Instruction instruction) { | |
| 144 if (instruction == null) { | |
| 145 return ''; | |
| 146 } | |
| 147 return instruction.human; | |
| 148 } | 130 } |
| 149 } | 131 } |
| OLD | NEW |