Files
UnrealEngineUWP/Engine/Source/Developer/TraceServices/Private/Model/StackSamples.cpp
ionut matasaru 9f5c9e10ed [Insights]
- Timing view: Added "Cpu Core" tracks when context switches are available. By default the tracks are hidden and can be enabled from Tracks /  Context Switches sub-menu.
  - Timing view: Added "Alt + C" shortcut key to toggle visibility of "Cpu Core" tracks.
  - Timing view: Added "filter by event type" for Cpu Core tracks. Double click an event in a Cpu Core track highlights all events of same type (same thread) in all Cpu Core tracks. Also fixed the "filter by event type" to fade out / highlight only tracks of same type.

#rb Catalin.Dragoiu

[CL 16955032 by ionut matasaru in ue5-main branch]
2021-07-26 08:14:49 -04:00

81 lines
2.0 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "TraceServices/Model/StackSamples.h"
#include "Model/StackSamplesPrivate.h"
#include "AnalysisServicePrivate.h"
#include "Algo/Sort.h"
namespace TraceServices
{
const FName FStackSamplesProvider::ProviderName = "StackSamplesProvider";
FStackSamplesProvider::FStackSamplesProvider(IAnalysisSession& InSession)
: Session(InSession)
, AddressValues(Session.GetLinearAllocator(), 4096)
{
}
FStackSamplesProvider::~FStackSamplesProvider()
{
for (const auto& ThreadSamples : Threads)
{
delete ThreadSamples.Value;
}
}
const TPagedArray<FStackSample>* FStackSamplesProvider::GetStackSamples(uint32 ThreadId) const
{
Session.ReadAccessCheck();
auto StackSamples = Threads.Find(ThreadId);
return StackSamples ? *StackSamples : nullptr;
}
void FStackSamplesProvider::Add(uint32 ThreadId, double Time, uint32 Count, const uint64* Addresses)
{
Session.WriteAccessCheck();
TPagedArray<FStackSample>** StackSamples = Threads.Find(ThreadId);
if (!StackSamples)
{
StackSamples = &Threads.Add(ThreadId, new TPagedArray<FStackSample>(Session.GetLinearAllocator(), 4096));
}
FStackSample& StackSample = (*StackSamples)->PushBack();
StackSample.Time = Time;
StackSample.Count = Count;
if (AddressValues.NumPages() == 0)
{
for (uint32 Index = 0; Index < Count; Index++)
{
AddressValues.EmplaceBack(Addresses[Index]);
}
StackSample.Addresses = &AddressValues.First();
return;
}
uint64 Available = AddressValues.GetPageSize() - AddressValues.GetLastPage()->Count;
if (Available < Count)
{
for (uint64 Temp = 0; Temp < Available; Temp++)
{
AddressValues.PushBack();
}
}
for (uint32 Index = 0; Index < Count; Index++)
{
AddressValues.EmplaceBack(Addresses[Index]);
}
StackSample.Addresses = &AddressValues.Last() - Count;
}
const IStackSamplesProvider& ReadStackSamplesProvider(const IAnalysisSession& Session)
{
return *Session.ReadProvider<IStackSamplesProvider>(FStackSamplesProvider::ProviderName);
}
} // namespace TraceServices