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