Files
UnrealEngineUWP/Engine/Source/Developer/TraceServices/Private/Common/Utils.cpp
ionut matasaru 0fe05296a9 [Insights]
- Added detection for AllocationsProvider availability to know when to enable the Memory Insights tab (in addition to detecting availability of the LLM tags memory provider).
  - Simplified the API for allocation queries (using A, B, C, D time markers).
  - Added initial AllocationsAnalysis that processes the allocation trace events and delegates them to AllocationsProvider.
  - Added initial AllocationsProvider. Uses a simple map for live allocations.
  - Added FSbTree ("SBIF with offsetted cells" data structure for storing the retired allocations in AllocationsProvider).
  - Added async allocation queries (based on A, B, C, D time markers). Currently it uses a single TaskGraph task.
  - Added "LogTraceServices" log category for general purpose logging in TraceServices module.

#rb Catalin.Dragoiu

[CL 14813195 by ionut matasaru in ue5-main branch]
2020-11-25 12:48:47 -04:00

76 lines
2.1 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "Utils.h"
#include "TraceServices/Containers/Tables.h"
#include "Templates/SharedPointer.h"
#include "HAL/FileManager.h"
DEFINE_LOG_CATEGORY(LogTraceServices);
namespace TraceServices
{
void Table2Csv(const IUntypedTable& Table, const TCHAR* Filename)
{
TSharedPtr<FArchive> OutputFile = MakeShareable(IFileManager::Get().CreateFileWriter(Filename));
check(OutputFile);
FString Header;
const ITableLayout& Layout = Table.GetLayout();
int32 ColumnCount = Layout.GetColumnCount();
for (int32 ColumnIndex = 0; ColumnIndex < ColumnCount; ++ColumnIndex)
{
Header += Layout.GetColumnName(ColumnIndex);
if (ColumnIndex < ColumnCount - 1)
{
Header += TEXT(",");
}
else
{
Header += TEXT("\n");
}
}
auto AnsiHeader = StringCast<ANSICHAR>(*Header);
OutputFile->Serialize((void*)AnsiHeader.Get(), AnsiHeader.Length());
TUniquePtr<IUntypedTableReader> TableReader(Table.CreateReader());
for (; TableReader->IsValid(); TableReader->NextRow())
{
FString Line;
for (int32 ColumnIndex = 0; ColumnIndex < ColumnCount; ++ColumnIndex)
{
switch (Layout.GetColumnType(ColumnIndex))
{
case TableColumnType_Bool:
Line += TableReader->GetValueBool(ColumnIndex) ? "true" : "false";
break;
case TableColumnType_Int:
Line += FString::Printf(TEXT("%lld"), TableReader->GetValueInt(ColumnIndex));
break;
case TableColumnType_Float:
Line += FString::Printf(TEXT("%f"), TableReader->GetValueFloat(ColumnIndex));
break;
case TableColumnType_Double:
Line += FString::Printf(TEXT("%f"), TableReader->GetValueDouble(ColumnIndex));
break;
case TableColumnType_CString:
FString ValueString = TableReader->GetValueCString(ColumnIndex);
ValueString.ReplaceInline(TEXT(","), TEXT(" "));
Line += ValueString;
break;
}
if (ColumnIndex < ColumnCount - 1)
{
Line += TEXT(",");
}
else
{
Line += TEXT("\n");
}
}
auto AnsiLine = StringCast<ANSICHAR>(*Line);
OutputFile->Serialize((void*)AnsiLine.Get(), AnsiLine.Length());
}
OutputFile->Close();
}
} // namespace TraceServices