OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 cpu_profiler; | 5 part of cpu_profiler; |
6 | 6 |
7 abstract class CallTreeNode<NodeT extends M.CallTreeNode> | 7 abstract class CallTreeNode<NodeT extends M.CallTreeNode> |
8 implements M.CallTreeNode { | 8 implements M.CallTreeNode { |
9 final List<NodeT> children; | 9 final List<NodeT> children; |
10 final int count; | 10 final int count; |
11 final int inclusiveNativeAllocations; | |
12 final int exclusiveNativeAllocations; | |
13 double get percentage => _percentage; | 11 double get percentage => _percentage; |
14 double _percentage = 0.0; | 12 double _percentage = 0.0; |
15 final Set<String> attributes = new Set<String>(); | 13 final Set<String> attributes = new Set<String>(); |
16 | 14 |
17 // Either a ProfileCode or a ProfileFunction. | 15 // Either a ProfileCode or a ProfileFunction. |
18 Object get profileData; | 16 Object get profileData; |
19 String get name; | 17 String get name; |
20 | 18 |
21 CallTreeNode(this.children, this.count, this.inclusiveNativeAllocations, | 19 CallTreeNode(this.children, this.count); |
22 this.exclusiveNativeAllocations); | |
23 } | 20 } |
24 | 21 |
25 class CodeCallTreeNode extends CallTreeNode<CodeCallTreeNode> | 22 class CodeCallTreeNode extends CallTreeNode<CodeCallTreeNode> |
26 implements M.CodeCallTreeNode { | 23 implements M.CodeCallTreeNode { |
27 final ProfileCode profileCode; | 24 final ProfileCode profileCode; |
28 | 25 |
29 Object get profileData => profileCode; | 26 Object get profileData => profileCode; |
30 | 27 |
31 String get name => profileCode.code.name; | 28 String get name => profileCode.code.name; |
32 | 29 |
33 final Set<String> attributes = new Set<String>(); | 30 final Set<String> attributes = new Set<String>(); |
34 CodeCallTreeNode(this.profileCode, int count, int inclusiveNativeAllocations, | 31 CodeCallTreeNode(this.profileCode, int count) |
35 int exclusiveNativeAllocations) | 32 : super(new List<CodeCallTreeNode>(), count) { |
36 : super(new List<CodeCallTreeNode>(), count, inclusiveNativeAllocations, | |
37 exclusiveNativeAllocations) { | |
38 attributes.addAll(profileCode.attributes); | 33 attributes.addAll(profileCode.attributes); |
39 } | 34 } |
40 } | 35 } |
41 | 36 |
42 class CallTree<NodeT extends CallTreeNode> { | 37 class CallTree<NodeT extends CallTreeNode> { |
43 final bool inclusive; | 38 final bool inclusive; |
44 final NodeT root; | 39 final NodeT root; |
45 | 40 |
46 CallTree(this.inclusive, this.root); | 41 CallTree(this.inclusive, this.root); |
47 } | 42 } |
48 | 43 |
49 class CodeCallTree extends CallTree<CodeCallTreeNode> | 44 class CodeCallTree extends CallTree<CodeCallTreeNode> |
50 implements M.CodeCallTree { | 45 implements M.CodeCallTree { |
51 CodeCallTree(bool inclusive, CodeCallTreeNode root) : super(inclusive, root) { | 46 CodeCallTree(bool inclusive, CodeCallTreeNode root) : super(inclusive, root) { |
52 if ((root.inclusiveNativeAllocations != null) && | 47 _setCodePercentage(null, root); |
53 (root.inclusiveNativeAllocations != 0)) { | |
54 _setCodeMemoryPercentage(null, root); | |
55 } else { | |
56 _setCodePercentage(null, root); | |
57 } | |
58 } | 48 } |
59 | 49 |
60 CodeCallTree filtered(CallTreeNodeFilter filter) { | 50 CodeCallTree filtered(CallTreeNodeFilter filter) { |
61 var treeFilter = new _FilteredCodeCallTreeBuilder(filter, this); | 51 var treeFilter = new _FilteredCodeCallTreeBuilder(filter, this); |
62 treeFilter.build(); | 52 treeFilter.build(); |
63 if ((treeFilter.filtered.root.inclusiveNativeAllocations != null) && | 53 _setCodePercentage(null, treeFilter.filtered.root); |
64 (treeFilter.filtered.root.inclusiveNativeAllocations != 0)) { | |
65 _setCodeMemoryPercentage(null, treeFilter.filtered.root); | |
66 } else { | |
67 _setCodePercentage(null, treeFilter.filtered.root); | |
68 } | |
69 return treeFilter.filtered; | 54 return treeFilter.filtered; |
70 } | 55 } |
71 | 56 |
72 _setCodePercentage(CodeCallTreeNode parent, CodeCallTreeNode node) { | 57 _setCodePercentage(CodeCallTreeNode parent, CodeCallTreeNode node) { |
73 assert(node != null); | 58 assert(node != null); |
74 var parentPercentage = 1.0; | 59 var parentPercentage = 1.0; |
75 var parentCount = node.count; | 60 var parentCount = node.count; |
76 if (parent != null) { | 61 if (parent != null) { |
77 parentPercentage = parent._percentage; | 62 parentPercentage = parent._percentage; |
78 parentCount = parent.count; | 63 parentCount = parent.count; |
79 } | 64 } |
80 if (inclusive) { | 65 if (inclusive) { |
81 node._percentage = parentPercentage * (node.count / parentCount); | 66 node._percentage = parentPercentage * (node.count / parentCount); |
82 } else { | 67 } else { |
83 node._percentage = (node.count / parentCount); | 68 node._percentage = (node.count / parentCount); |
84 } | 69 } |
85 for (var child in node.children) { | 70 for (var child in node.children) { |
86 _setCodePercentage(node, child); | 71 _setCodePercentage(node, child); |
87 } | 72 } |
88 } | 73 } |
89 | 74 |
90 _setCodeMemoryPercentage(CodeCallTreeNode parent, CodeCallTreeNode node) { | |
91 assert(node != null); | |
92 var parentPercentage = 1.0; | |
93 var parentMemory = node.inclusiveNativeAllocations; | |
94 if (parent != null) { | |
95 parentPercentage = parent._percentage; | |
96 parentMemory = parent.inclusiveNativeAllocations; | |
97 } | |
98 if (inclusive) { | |
99 node._percentage = | |
100 parentPercentage * (node.inclusiveNativeAllocations / parentMemory); | |
101 } else { | |
102 node._percentage = (node.inclusiveNativeAllocations / parentMemory); | |
103 } | |
104 for (var child in node.children) { | |
105 _setCodeMemoryPercentage(node, child); | |
106 } | |
107 } | |
108 | |
109 _recordCallerAndCalleesInner( | 75 _recordCallerAndCalleesInner( |
110 CodeCallTreeNode caller, CodeCallTreeNode callee) { | 76 CodeCallTreeNode caller, CodeCallTreeNode callee) { |
111 if (caller != null) { | 77 if (caller != null) { |
112 caller.profileCode._recordCallee(callee.profileCode, callee.count); | 78 caller.profileCode._recordCallee(callee.profileCode, callee.count); |
113 callee.profileCode._recordCaller(caller.profileCode, caller.count); | 79 callee.profileCode._recordCaller(caller.profileCode, caller.count); |
114 } | 80 } |
115 | 81 |
116 for (var child in callee.children) { | 82 for (var child in callee.children) { |
117 _recordCallerAndCalleesInner(callee, child); | 83 _recordCallerAndCalleesInner(callee, child); |
118 } | 84 } |
(...skipping 14 matching lines...) Expand all Loading... |
133 | 99 |
134 class FunctionCallTreeNode extends CallTreeNode { | 100 class FunctionCallTreeNode extends CallTreeNode { |
135 final ProfileFunction profileFunction; | 101 final ProfileFunction profileFunction; |
136 final codes = new List<FunctionCallTreeNodeCode>(); | 102 final codes = new List<FunctionCallTreeNodeCode>(); |
137 int _totalCodeTicks = 0; | 103 int _totalCodeTicks = 0; |
138 int get totalCodesTicks => _totalCodeTicks; | 104 int get totalCodesTicks => _totalCodeTicks; |
139 | 105 |
140 String get name => M.getFunctionFullName(profileFunction.function); | 106 String get name => M.getFunctionFullName(profileFunction.function); |
141 Object get profileData => profileFunction; | 107 Object get profileData => profileFunction; |
142 | 108 |
143 FunctionCallTreeNode(this.profileFunction, int count, | 109 FunctionCallTreeNode(this.profileFunction, int count) |
144 inclusiveNativeAllocations, exclusiveNativeAllocations) | 110 : super(new List<FunctionCallTreeNode>(), count) { |
145 : super(new List<FunctionCallTreeNode>(), count, | |
146 inclusiveNativeAllocations, exclusiveNativeAllocations) { | |
147 profileFunction._addKindBasedAttributes(attributes); | 111 profileFunction._addKindBasedAttributes(attributes); |
148 } | 112 } |
149 | 113 |
150 // Does this function have an optimized version of itself? | 114 // Does this function have an optimized version of itself? |
151 bool hasOptimizedCode() { | 115 bool hasOptimizedCode() { |
152 for (var nodeCode in codes) { | 116 for (var nodeCode in codes) { |
153 var profileCode = nodeCode.code; | 117 var profileCode = nodeCode.code; |
154 if (!profileCode.code.isDartCode) { | 118 if (!profileCode.code.isDartCode) { |
155 continue; | 119 continue; |
156 } | 120 } |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 | 283 |
320 class _FilteredFunctionCallTreeBuilder extends _FilteredCallTreeBuilder { | 284 class _FilteredFunctionCallTreeBuilder extends _FilteredCallTreeBuilder { |
321 _FilteredFunctionCallTreeBuilder( | 285 _FilteredFunctionCallTreeBuilder( |
322 CallTreeNodeFilter filter, FunctionCallTree tree) | 286 CallTreeNodeFilter filter, FunctionCallTree tree) |
323 : super( | 287 : super( |
324 filter, | 288 filter, |
325 tree, | 289 tree, |
326 new FunctionCallTree( | 290 new FunctionCallTree( |
327 tree.inclusive, | 291 tree.inclusive, |
328 new FunctionCallTreeNode( | 292 new FunctionCallTreeNode( |
329 tree.root.profileData, | 293 tree.root.profileData, tree.root.count))); |
330 tree.root.count, | |
331 tree.root.inclusiveNativeAllocations, | |
332 tree.root.exclusiveNativeAllocations))); | |
333 | 294 |
334 _copyNode(FunctionCallTreeNode node) { | 295 _copyNode(FunctionCallTreeNode node) { |
335 return new FunctionCallTreeNode(node.profileData, node.count, | 296 return new FunctionCallTreeNode(node.profileData, node.count); |
336 node.inclusiveNativeAllocations, node.exclusiveNativeAllocations); | |
337 } | 297 } |
338 } | 298 } |
339 | 299 |
340 class _FilteredCodeCallTreeBuilder extends _FilteredCallTreeBuilder { | 300 class _FilteredCodeCallTreeBuilder extends _FilteredCallTreeBuilder { |
341 _FilteredCodeCallTreeBuilder(CallTreeNodeFilter filter, CodeCallTree tree) | 301 _FilteredCodeCallTreeBuilder(CallTreeNodeFilter filter, CodeCallTree tree) |
342 : super( | 302 : super( |
343 filter, | 303 filter, |
344 tree, | 304 tree, |
345 new CodeCallTree( | 305 new CodeCallTree(tree.inclusive, |
346 tree.inclusive, | 306 new CodeCallTreeNode(tree.root.profileData, tree.root.count))); |
347 new CodeCallTreeNode( | |
348 tree.root.profileData, | |
349 tree.root.count, | |
350 tree.root.inclusiveNativeAllocations, | |
351 tree.root.exclusiveNativeAllocations))); | |
352 | 307 |
353 _copyNode(CodeCallTreeNode node) { | 308 _copyNode(CodeCallTreeNode node) { |
354 return new CodeCallTreeNode(node.profileData, node.count, | 309 return new CodeCallTreeNode(node.profileData, node.count); |
355 node.inclusiveNativeAllocations, node.exclusiveNativeAllocations); | |
356 } | 310 } |
357 } | 311 } |
358 | 312 |
359 class FunctionCallTree extends CallTree implements M.FunctionCallTree { | 313 class FunctionCallTree extends CallTree implements M.FunctionCallTree { |
360 FunctionCallTree(bool inclusive, FunctionCallTreeNode root) | 314 FunctionCallTree(bool inclusive, FunctionCallTreeNode root) |
361 : super(inclusive, root) { | 315 : super(inclusive, root) { |
362 if ((root.inclusiveNativeAllocations != null) && | 316 _setFunctionPercentage(null, root); |
363 (root.inclusiveNativeAllocations != 0)) { | |
364 _setFunctionMemoryPercentage(null, root); | |
365 } else { | |
366 _setFunctionPercentage(null, root); | |
367 } | |
368 } | 317 } |
369 | 318 |
370 FunctionCallTree filtered(CallTreeNodeFilter filter) { | 319 FunctionCallTree filtered(CallTreeNodeFilter filter) { |
371 var treeFilter = new _FilteredFunctionCallTreeBuilder(filter, this); | 320 var treeFilter = new _FilteredFunctionCallTreeBuilder(filter, this); |
372 treeFilter.build(); | 321 treeFilter.build(); |
373 if ((treeFilter.filtered.root.inclusiveNativeAllocations != null) && | 322 _setFunctionPercentage(null, treeFilter.filtered.root); |
374 (treeFilter.filtered.root.inclusiveNativeAllocations != 0)) { | |
375 _setFunctionMemoryPercentage(null, treeFilter.filtered.root); | |
376 } else { | |
377 _setFunctionPercentage(null, treeFilter.filtered.root); | |
378 } | |
379 return treeFilter.filtered; | 323 return treeFilter.filtered; |
380 } | 324 } |
381 | 325 |
382 void _setFunctionPercentage( | 326 void _setFunctionPercentage( |
383 FunctionCallTreeNode parent, FunctionCallTreeNode node) { | 327 FunctionCallTreeNode parent, FunctionCallTreeNode node) { |
384 assert(node != null); | 328 assert(node != null); |
385 var parentPercentage = 1.0; | 329 var parentPercentage = 1.0; |
386 var parentCount = node.count; | 330 var parentCount = node.count; |
387 if (parent != null) { | 331 if (parent != null) { |
388 parentPercentage = parent._percentage; | 332 parentPercentage = parent._percentage; |
389 parentCount = parent.count; | 333 parentCount = parent.count; |
390 } | 334 } |
391 if (inclusive) { | 335 if (inclusive) { |
392 node._percentage = parentPercentage * (node.count / parentCount); | 336 node._percentage = parentPercentage * (node.count / parentCount); |
393 } else { | 337 } else { |
394 node._percentage = (node.count / parentCount); | 338 node._percentage = (node.count / parentCount); |
395 } | 339 } |
396 for (var child in node.children) { | 340 for (var child in node.children) { |
397 _setFunctionPercentage(node, child); | 341 _setFunctionPercentage(node, child); |
398 } | 342 } |
399 } | 343 } |
400 | 344 |
401 void _setFunctionMemoryPercentage( | |
402 FunctionCallTreeNode parent, FunctionCallTreeNode node) { | |
403 assert(node != null); | |
404 var parentPercentage = 1.0; | |
405 var parentMemory = node.inclusiveNativeAllocations; | |
406 if (parent != null) { | |
407 parentPercentage = parent._percentage; | |
408 parentMemory = parent.inclusiveNativeAllocations; | |
409 } | |
410 if (inclusive) { | |
411 node._percentage = | |
412 parentPercentage * (node.inclusiveNativeAllocations / parentMemory); | |
413 } else { | |
414 node._percentage = (node.inclusiveNativeAllocations / parentMemory); | |
415 } | |
416 for (var child in node.children) { | |
417 _setFunctionMemoryPercentage(node, child); | |
418 } | |
419 } | |
420 | |
421 _markFunctionCallsInner( | 345 _markFunctionCallsInner( |
422 FunctionCallTreeNode caller, FunctionCallTreeNode callee) { | 346 FunctionCallTreeNode caller, FunctionCallTreeNode callee) { |
423 if (caller != null) { | 347 if (caller != null) { |
424 caller.profileFunction | 348 caller.profileFunction |
425 ._recordCallee(callee.profileFunction, callee.count); | 349 ._recordCallee(callee.profileFunction, callee.count); |
426 callee.profileFunction | 350 callee.profileFunction |
427 ._recordCaller(caller.profileFunction, caller.count); | 351 ._recordCaller(caller.profileFunction, caller.count); |
428 } | 352 } |
429 for (var child in callee.children) { | 353 for (var child in callee.children) { |
430 _markFunctionCallsInner(callee, child); | 354 _markFunctionCallsInner(callee, child); |
(...skipping 20 matching lines...) Expand all Loading... |
451 int _exclusiveTicks = 0; | 375 int _exclusiveTicks = 0; |
452 int get exclusiveTicks => _exclusiveTicks; | 376 int get exclusiveTicks => _exclusiveTicks; |
453 InlineIntervalTick(this.startAddress); | 377 InlineIntervalTick(this.startAddress); |
454 } | 378 } |
455 | 379 |
456 class ProfileCode implements M.ProfileCode { | 380 class ProfileCode implements M.ProfileCode { |
457 final CpuProfile profile; | 381 final CpuProfile profile; |
458 final Code code; | 382 final Code code; |
459 int exclusiveTicks; | 383 int exclusiveTicks; |
460 int inclusiveTicks; | 384 int inclusiveTicks; |
461 int exclusiveNativeAllocations; | |
462 int inclusiveNativeAllocations; | |
463 double normalizedExclusiveTicks = 0.0; | 385 double normalizedExclusiveTicks = 0.0; |
464 double normalizedInclusiveTicks = 0.0; | 386 double normalizedInclusiveTicks = 0.0; |
465 final addressTicks = new Map<int, CodeTick>(); | 387 final addressTicks = new Map<int, CodeTick>(); |
466 final intervalTicks = new Map<int, InlineIntervalTick>(); | 388 final intervalTicks = new Map<int, InlineIntervalTick>(); |
467 String formattedInclusiveTicks = ''; | 389 String formattedInclusiveTicks = ''; |
468 String formattedExclusiveTicks = ''; | 390 String formattedExclusiveTicks = ''; |
469 String formattedExclusivePercent = ''; | 391 String formattedExclusivePercent = ''; |
470 String formattedCpuTime = ''; | 392 String formattedCpuTime = ''; |
471 String formattedOnStackTime = ''; | 393 String formattedOnStackTime = ''; |
472 final Set<String> attributes = new Set<String>(); | 394 final Set<String> attributes = new Set<String>(); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
529 | 451 |
530 normalizedExclusiveTicks = exclusiveTicks / profile.sampleCount; | 452 normalizedExclusiveTicks = exclusiveTicks / profile.sampleCount; |
531 | 453 |
532 normalizedInclusiveTicks = inclusiveTicks / profile.sampleCount; | 454 normalizedInclusiveTicks = inclusiveTicks / profile.sampleCount; |
533 | 455 |
534 var ticks = data['ticks']; | 456 var ticks = data['ticks']; |
535 if (ticks != null) { | 457 if (ticks != null) { |
536 _processTicks(ticks); | 458 _processTicks(ticks); |
537 } | 459 } |
538 | 460 |
539 if (data.containsKey('exclusiveNativeAllocations') && | |
540 data.containsKey('inclusiveNativeAllocations')) { | |
541 exclusiveNativeAllocations = | |
542 int.parse(data['exclusiveNativeAllocations']); | |
543 inclusiveNativeAllocations = | |
544 int.parse(data['inclusiveNativeAllocations']); | |
545 } | |
546 | |
547 formattedExclusivePercent = | 461 formattedExclusivePercent = |
548 Utils.formatPercent(exclusiveTicks, profile.sampleCount); | 462 Utils.formatPercent(exclusiveTicks, profile.sampleCount); |
549 | 463 |
550 formattedCpuTime = Utils.formatTimeMilliseconds( | 464 formattedCpuTime = Utils.formatTimeMilliseconds( |
551 profile.approximateMillisecondsForCount(exclusiveTicks)); | 465 profile.approximateMillisecondsForCount(exclusiveTicks)); |
552 | 466 |
553 formattedOnStackTime = Utils.formatTimeMilliseconds( | 467 formattedOnStackTime = Utils.formatTimeMilliseconds( |
554 profile.approximateMillisecondsForCount(inclusiveTicks)); | 468 profile.approximateMillisecondsForCount(inclusiveTicks)); |
555 | 469 |
556 formattedInclusiveTicks = | 470 formattedInclusiveTicks = |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
588 final Map<ProfileFunction, int> callees = new Map<ProfileFunction, int>(); | 502 final Map<ProfileFunction, int> callees = new Map<ProfileFunction, int>(); |
589 | 503 |
590 // Absolute ticks: | 504 // Absolute ticks: |
591 int exclusiveTicks = 0; | 505 int exclusiveTicks = 0; |
592 int inclusiveTicks = 0; | 506 int inclusiveTicks = 0; |
593 | 507 |
594 // Global percentages: | 508 // Global percentages: |
595 double normalizedExclusiveTicks = 0.0; | 509 double normalizedExclusiveTicks = 0.0; |
596 double normalizedInclusiveTicks = 0.0; | 510 double normalizedInclusiveTicks = 0.0; |
597 | 511 |
598 // Native allocations: | |
599 int exclusiveNativeAllocations = 0; | |
600 int inclusiveNativeAllocations = 0; | |
601 | |
602 String formattedInclusiveTicks = ''; | 512 String formattedInclusiveTicks = ''; |
603 String formattedExclusiveTicks = ''; | 513 String formattedExclusiveTicks = ''; |
604 String formattedExclusivePercent = ''; | 514 String formattedExclusivePercent = ''; |
605 String formattedCpuTime = ''; | 515 String formattedCpuTime = ''; |
606 String formattedOnStackTime = ''; | 516 String formattedOnStackTime = ''; |
607 final Set<String> attributes = new Set<String>(); | 517 final Set<String> attributes = new Set<String>(); |
608 | 518 |
609 int _sortCodes(ProfileCode a, ProfileCode b) { | 519 int _sortCodes(ProfileCode a, ProfileCode b) { |
610 if (a.code.isOptimized == b.code.isOptimized) { | 520 if (a.code.isOptimized == b.code.isOptimized) { |
611 return b.code.profile.exclusiveTicks - a.code.profile.exclusiveTicks; | 521 return b.code.profile.exclusiveTicks - a.code.profile.exclusiveTicks; |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
689 } | 599 } |
690 profileCodes.sort(_sortCodes); | 600 profileCodes.sort(_sortCodes); |
691 | 601 |
692 _addKindBasedAttributes(attributes); | 602 _addKindBasedAttributes(attributes); |
693 exclusiveTicks = int.parse(data['exclusiveTicks']); | 603 exclusiveTicks = int.parse(data['exclusiveTicks']); |
694 inclusiveTicks = int.parse(data['inclusiveTicks']); | 604 inclusiveTicks = int.parse(data['inclusiveTicks']); |
695 | 605 |
696 normalizedExclusiveTicks = exclusiveTicks / profile.sampleCount; | 606 normalizedExclusiveTicks = exclusiveTicks / profile.sampleCount; |
697 normalizedInclusiveTicks = inclusiveTicks / profile.sampleCount; | 607 normalizedInclusiveTicks = inclusiveTicks / profile.sampleCount; |
698 | 608 |
699 if (data.containsKey('exclusiveNativeAllocations') && | |
700 data.containsKey('inclusiveNativeAllocations')) { | |
701 exclusiveNativeAllocations = | |
702 int.parse(data['exclusiveNativeAllocations']); | |
703 inclusiveNativeAllocations = | |
704 int.parse(data['inclusiveNativeAllocations']); | |
705 } | |
706 | |
707 formattedExclusivePercent = | 609 formattedExclusivePercent = |
708 Utils.formatPercent(exclusiveTicks, profile.sampleCount); | 610 Utils.formatPercent(exclusiveTicks, profile.sampleCount); |
709 | 611 |
710 formattedCpuTime = Utils.formatTimeMilliseconds( | 612 formattedCpuTime = Utils.formatTimeMilliseconds( |
711 profile.approximateMillisecondsForCount(exclusiveTicks)); | 613 profile.approximateMillisecondsForCount(exclusiveTicks)); |
712 | 614 |
713 formattedOnStackTime = Utils.formatTimeMilliseconds( | 615 formattedOnStackTime = Utils.formatTimeMilliseconds( |
714 profile.approximateMillisecondsForCount(inclusiveTicks)); | 616 profile.approximateMillisecondsForCount(inclusiveTicks)); |
715 | 617 |
716 formattedInclusiveTicks = | 618 formattedInclusiveTicks = |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
801 sampleRate = 0.0; | 703 sampleRate = 0.0; |
802 stackDepth = 0; | 704 stackDepth = 0; |
803 timeSpan = 0.0; | 705 timeSpan = 0.0; |
804 codes.clear(); | 706 codes.clear(); |
805 functions.clear(); | 707 functions.clear(); |
806 tries.clear(); | 708 tries.clear(); |
807 _builtCodeCalls = false; | 709 _builtCodeCalls = false; |
808 _builtFunctionCalls = false; | 710 _builtFunctionCalls = false; |
809 } | 711 } |
810 | 712 |
811 Future load(ServiceObjectOwner owner, ServiceMap profile) async { | 713 Future load(Isolate isolate, ServiceMap profile) async { |
812 await loadProgress(owner, profile).last; | 714 await loadProgress(isolate, profile).last; |
813 } | 715 } |
814 | 716 |
815 static Future sleep([Duration duration = const Duration(microseconds: 0)]) { | 717 static Future sleep([Duration duration = const Duration(microseconds: 0)]) { |
816 final Completer completer = new Completer(); | 718 final Completer completer = new Completer(); |
817 new Timer(duration, () => completer.complete()); | 719 new Timer(duration, () => completer.complete()); |
818 return completer.future; | 720 return completer.future; |
819 } | 721 } |
820 | 722 |
821 Stream<double> loadProgress(ServiceObjectOwner owner, ServiceMap profile) { | 723 Stream<double> loadProgress(Isolate isolate, ServiceMap profile) { |
822 var progress = new StreamController<double>.broadcast(); | 724 var progress = new StreamController<double>.broadcast(); |
823 | 725 |
824 (() async { | 726 (() async { |
825 final Stopwatch watch = new Stopwatch(); | 727 final Stopwatch watch = new Stopwatch(); |
826 watch.start(); | 728 watch.start(); |
827 int count = 0; | 729 int count = 0; |
828 var needToUpdate = () { | 730 var needToUpdate = () { |
829 count++; | 731 count++; |
830 if (((count % 256) == 0) && (watch.elapsedMilliseconds > 16)) { | 732 if (((count % 256) == 0) && (watch.elapsedMilliseconds > 16)) { |
831 watch.reset(); | 733 watch.reset(); |
832 return true; | 734 return true; |
833 } | 735 } |
834 return false; | 736 return false; |
835 }; | 737 }; |
836 var signal = (double p) { | 738 var signal = (double p) { |
837 progress.add(p); | 739 progress.add(p); |
838 return sleep(); | 740 return sleep(); |
839 }; | 741 }; |
840 try { | 742 try { |
841 clear(); | 743 clear(); |
842 progress.add(0.0); | 744 progress.add(0.0); |
843 if (profile == null) { | 745 if ((isolate == null) || (profile == null)) { |
844 return; | 746 return; |
845 } | 747 } |
846 | 748 |
847 if ((owner != null) && (owner is Isolate)) { | 749 this.isolate = isolate; |
848 isolate = owner as Isolate; | 750 isolate.resetCachedProfileData(); |
849 isolate.resetCachedProfileData(); | |
850 } | |
851 | 751 |
852 sampleCount = profile['sampleCount']; | 752 sampleCount = profile['sampleCount']; |
853 samplePeriod = profile['samplePeriod']; | 753 samplePeriod = profile['samplePeriod']; |
854 sampleRate = (Duration.MICROSECONDS_PER_SECOND / samplePeriod); | 754 sampleRate = (Duration.MICROSECONDS_PER_SECOND / samplePeriod); |
855 stackDepth = profile['stackDepth']; | 755 stackDepth = profile['stackDepth']; |
856 timeSpan = profile['timeSpan']; | 756 timeSpan = profile['timeSpan']; |
857 | 757 |
858 num length = profile['codes'].length + profile['functions'].length; | 758 num length = profile['codes'].length + profile['functions'].length; |
859 | 759 |
860 // Process code table. | 760 // Process code table. |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
917 } | 817 } |
918 | 818 |
919 CodeCallTreeNode _readCodeTrieNode(List<int> data) { | 819 CodeCallTreeNode _readCodeTrieNode(List<int> data) { |
920 // Lookup code object. | 820 // Lookup code object. |
921 var codeIndex = data[_dataCursor++]; | 821 var codeIndex = data[_dataCursor++]; |
922 var code = codes[codeIndex]; | 822 var code = codes[codeIndex]; |
923 // Node tick counter. | 823 // Node tick counter. |
924 var count = data[_dataCursor++]; | 824 var count = data[_dataCursor++]; |
925 // Child node count. | 825 // Child node count. |
926 var children = data[_dataCursor++]; | 826 var children = data[_dataCursor++]; |
927 // Inclusive native allocations. | |
928 var inclusiveNativeAllocations = data[_dataCursor++]; | |
929 // Exclusive native allocations. | |
930 var exclusiveNativeAllocations = data[_dataCursor++]; | |
931 // Create node. | 827 // Create node. |
932 var node = new CodeCallTreeNode( | 828 var node = new CodeCallTreeNode(code, count); |
933 code, count, inclusiveNativeAllocations, exclusiveNativeAllocations); | |
934 node.children.length = children; | 829 node.children.length = children; |
935 return node; | 830 return node; |
936 } | 831 } |
937 | 832 |
938 CodeCallTreeNode _readCodeTrie(List<int> data) { | 833 CodeCallTreeNode _readCodeTrie(List<int> data) { |
939 final nodeStack = new List<CodeCallTreeNode>(); | 834 final nodeStack = new List<CodeCallTreeNode>(); |
940 final childIndexStack = new List<int>(); | 835 final childIndexStack = new List<int>(); |
941 | 836 |
942 _dataCursor = 0; | 837 _dataCursor = 0; |
943 // Read root. | 838 // Read root. |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
992 return new FunctionCallTree(inclusive, root); | 887 return new FunctionCallTree(inclusive, root); |
993 } | 888 } |
994 | 889 |
995 FunctionCallTreeNode _readFunctionTrieNode(List<int> data) { | 890 FunctionCallTreeNode _readFunctionTrieNode(List<int> data) { |
996 // Read index into function table. | 891 // Read index into function table. |
997 var index = data[_dataCursor++]; | 892 var index = data[_dataCursor++]; |
998 // Lookup function object. | 893 // Lookup function object. |
999 var function = functions[index]; | 894 var function = functions[index]; |
1000 // Counter. | 895 // Counter. |
1001 var count = data[_dataCursor++]; | 896 var count = data[_dataCursor++]; |
1002 // Inclusive native allocations. | |
1003 var inclusiveNativeAllocations = data[_dataCursor++]; | |
1004 // Exclusive native allocations. | |
1005 var exclusiveNativeAllocations = data[_dataCursor++]; | |
1006 // Create node. | 897 // Create node. |
1007 var node = new FunctionCallTreeNode(function, count, | 898 var node = new FunctionCallTreeNode(function, count); |
1008 inclusiveNativeAllocations, exclusiveNativeAllocations); | |
1009 // Number of code index / count pairs. | 899 // Number of code index / count pairs. |
1010 var codeCount = data[_dataCursor++]; | 900 var codeCount = data[_dataCursor++]; |
1011 node.codes.length = codeCount; | 901 node.codes.length = codeCount; |
1012 var totalCodeTicks = 0; | 902 var totalCodeTicks = 0; |
1013 for (var i = 0; i < codeCount; i++) { | 903 for (var i = 0; i < codeCount; i++) { |
1014 var codeIndex = data[_dataCursor++]; | 904 var codeIndex = data[_dataCursor++]; |
1015 var code = codes[codeIndex]; | 905 var code = codes[codeIndex]; |
1016 assert(code != null); | 906 assert(code != null); |
1017 var codeTicks = data[_dataCursor++]; | 907 var codeTicks = data[_dataCursor++]; |
1018 totalCodeTicks += codeTicks; | 908 totalCodeTicks += codeTicks; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1073 } | 963 } |
1074 | 964 |
1075 int approximateMillisecondsForCount(count) { | 965 int approximateMillisecondsForCount(count) { |
1076 return (count * samplePeriod) ~/ Duration.MICROSECONDS_PER_MILLISECOND; | 966 return (count * samplePeriod) ~/ Duration.MICROSECONDS_PER_MILLISECOND; |
1077 } | 967 } |
1078 | 968 |
1079 double approximateSecondsForCount(count) { | 969 double approximateSecondsForCount(count) { |
1080 return (count * samplePeriod) / Duration.MICROSECONDS_PER_SECOND; | 970 return (count * samplePeriod) / Duration.MICROSECONDS_PER_SECOND; |
1081 } | 971 } |
1082 } | 972 } |
OLD | NEW |