void Profiler::MergeTree(TypeNode * toNode, TypeNode * fromNode) { UnitData * toData = toNode->GetValue(); const UnitData * fromData = fromNode->GetValue(); toData->count += fromData->count; toData->incl += fromData->incl; toData->excl += fromData->excl; if (fromData->max > toData->max) { toData->max = fromData->max; } for (int i = 0; i < PhaseCount; i++) { if (fromNode->ChildExistsAt(i)) { TypeNode * fromChild = fromNode->GetChildAt(i); TypeNode * toChild; if (!toNode->ChildExistsAt(i)) { toChild = Anew(this->alloc, TypeNode, toNode); toNode->SetChildAt(i, toChild); } else { toChild = toNode->GetChildAt(i); } MergeTree(toChild, fromChild); } } }
void Profiler::Merge(Profiler * profiler) { MergeTree(&rootNode, &profiler->rootNode); if (profiler->timeStack.Count() > 1) { FixedStack<TimeEntry, MaxStackDepth> reverseStack; do { reverseStack.Push(*profiler->timeStack.Pop()); } while (profiler->timeStack.Count() > 1); do { TimeEntry * entry = reverseStack.Pop(); this->Push(*entry); profiler->timeStack.Push(*entry); } while (reverseStack.Count() != 0); } }