OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 part of observatory; | 5 part of observatory; |
6 | 6 |
7 class CodeInstruction extends Observable { | 7 class CodeInstruction extends Observable { |
8 @observable final int address; | 8 @observable final int address; |
9 @observable final String machine; | 9 @observable final String machine; |
10 @observable final String human; | 10 @observable final String human; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 @observable String name; | 81 @observable String name; |
82 @observable String userName; | 82 @observable String userName; |
83 | 83 |
84 Code(this.kind, this.name, this.startAddress, this.endAddress); | 84 Code(this.kind, this.name, this.startAddress, this.endAddress); |
85 | 85 |
86 Code.fromMap(Map map) : | 86 Code.fromMap(Map map) : |
87 kind = CodeKind.Dart, | 87 kind = CodeKind.Dart, |
88 startAddress = int.parse(map['start'], radix: 16), | 88 startAddress = int.parse(map['start'], radix: 16), |
89 endAddress = int.parse(map['end'], radix: 16) { | 89 endAddress = int.parse(map['end'], radix: 16) { |
90 functionRef = toObservable(map['function']); | 90 functionRef = toObservable(map['function']); |
91 codeRef = toObservable({ | 91 codeRef = toObservable(map); |
92 'type': '@Code', | |
93 'id': map['id'], | |
94 'name': map['name'], | |
95 'user_name': map['user_name'] | |
96 }); | |
97 name = map['name']; | 92 name = map['name']; |
98 userName = map['user_name']; | 93 userName = map['user_name']; |
99 if (map['disassembly'] != null) { | 94 if (map['disassembly'] != null) { |
100 _loadInstructions(map['disassembly']); | 95 _loadInstructions(map['disassembly']); |
101 } | 96 } |
102 } | 97 } |
103 | 98 |
104 factory Code.fromProfileMap(Map map) { | 99 factory Code.fromProfileMap(Map map) { |
105 var kind = CodeKind.fromString(map['kind']); | 100 var kind = CodeKind.fromString(map['kind']); |
106 var startAddress; | 101 var startAddress; |
107 var endAddress; | 102 var endAddress; |
108 var name; | 103 var name; |
109 var userName; | 104 var userName; |
110 var codeRef; | 105 var codeRef = map['code']; |
111 var functionRef; | 106 assert(codeRef != null); |
112 // Initial extraction of startAddress, endAddress, and name depends on what | 107 startAddress = int.parse(codeRef['start'], radix:16); |
113 // kind of code this is and whether or not the code has been collected. | 108 endAddress = int.parse(codeRef['end'], radix:16); |
114 if (kind == CodeKind.Dart) { | 109 name = codeRef['name']; |
115 var code = map['code']; | 110 userName = codeRef['user_name']; |
116 if (code != null) { | |
117 // Extract from Dart code. | |
118 startAddress = int.parse(code['start'], radix:16); | |
119 endAddress = int.parse(code['end'], radix:16); | |
120 name = code['name']; | |
121 userName = code['user_name']; | |
122 codeRef = toObservable({ | |
123 'type': '@Code', | |
124 'id': code['id'], | |
125 'name': name, | |
126 'user_name': userName | |
127 }); | |
128 functionRef = toObservable(code['function']); | |
129 } | |
130 } | |
131 if (startAddress == null) { | |
132 // Extract from Profile code. | |
133 // This is either a native or collected piece of code. | |
134 startAddress = int.parse(map['start'], radix:16); | |
135 endAddress = int.parse(map['end'], radix: 16); | |
136 name = map['name']; | |
137 userName = name; | |
138 } | |
139 var code = new Code(kind, name, startAddress, endAddress); | 111 var code = new Code(kind, name, startAddress, endAddress); |
140 code.codeRef = codeRef; | 112 code.codeRef = codeRef; |
141 code.functionRef = functionRef; | 113 code.functionRef = toObservable(codeRef['function']);; |
142 code.userName = userName; | 114 code.userName = userName; |
143 if (map['disassembly'] != null) { | 115 if (codeRef['disassembly'] != null) { |
144 code._loadInstructions(map['disassembly']); | 116 code._loadInstructions(codeRef['disassembly']); |
| 117 // Throw the JSON version away after loading the disassembly. |
| 118 codeRef['disassembly'] = null; |
145 } | 119 } |
146 return code; | 120 return code; |
147 } | 121 } |
148 | 122 |
149 // Refresh tick counts, etc for a code object. | 123 // Refresh tick counts, etc for a code object. |
150 void _refresh(Map map) { | 124 void _refresh(Map map) { |
151 inclusiveTicks = int.parse(map['inclusive_ticks']); | 125 inclusiveTicks = int.parse(map['inclusive_ticks']); |
152 exclusiveTicks = int.parse(map['exclusive_ticks']); | 126 exclusiveTicks = int.parse(map['exclusive_ticks']); |
153 // Load address ticks. | 127 // Load address ticks. |
154 var ticksList = map['ticks']; | 128 var ticksList = map['ticks']; |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 // and resolve callers and callees. | 251 // and resolve callers and callees. |
278 assert(_codeObjectsInImportOrder.length == codes.length); | 252 assert(_codeObjectsInImportOrder.length == codes.length); |
279 for (var i = 0; i < codes.length; i++) { | 253 for (var i = 0; i < codes.length; i++) { |
280 Code code = _codeObjectsInImportOrder[i]; | 254 Code code = _codeObjectsInImportOrder[i]; |
281 code.resolveCalls(codes[i], _codeObjectsInImportOrder); | 255 code.resolveCalls(codes[i], _codeObjectsInImportOrder); |
282 } | 256 } |
283 _codeObjectsInImportOrder.clear(); | 257 _codeObjectsInImportOrder.clear(); |
284 } | 258 } |
285 | 259 |
286 int _extractCodeStartAddress(Map code) { | 260 int _extractCodeStartAddress(Map code) { |
287 var kind = CodeKind.fromString(code['kind']); | 261 return int.parse(code['code']['start'], radix:16); |
288 if ((kind == CodeKind.Dart) && (code['code'] != null)) { | |
289 // Start address is inside the dart code map. | |
290 return int.parse(code['code']['start'], radix:16); | |
291 } | |
292 // Start address is inside the profile code map. | |
293 return int.parse(code['start'], radix:16); | |
294 } | 262 } |
295 | 263 |
296 void _processCode(Map profileCode) { | 264 void _processCode(Map profileCode) { |
297 if (profileCode['type'] != 'ProfileCode') { | 265 if (profileCode['type'] != 'ProfileCode') { |
298 return; | 266 return; |
299 } | 267 } |
300 int address = _extractCodeStartAddress(profileCode); | 268 int address = _extractCodeStartAddress(profileCode); |
301 var code = isolate.findCodeByAddress(address); | 269 var code = isolate.findCodeByAddress(address); |
302 if (code == null) { | 270 if (code == null) { |
303 // Never seen a code object at this address before, create a new one. | 271 // Never seen a code object at this address before, create a new one. |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 if (executableLines == 0) { | 381 if (executableLines == 0) { |
414 return 0.0; | 382 return 0.0; |
415 } | 383 } |
416 return (coveredLines / executableLines) * 100.0; | 384 return (coveredLines / executableLines) * 100.0; |
417 } | 385 } |
418 | 386 |
419 @observable String coveredPercentageFormatted() { | 387 @observable String coveredPercentageFormatted() { |
420 return '(' + coveredPercentage().toStringAsFixed(1) + '% covered)'; | 388 return '(' + coveredPercentage().toStringAsFixed(1) + '% covered)'; |
421 } | 389 } |
422 } | 390 } |
OLD | NEW |