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