Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CPU profiling trace updates #48

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Source/MDFastBinding/MDFastBinding.Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,7 @@ public MDFastBinding(ReadOnlyTargetRules Target) : base(Target)
"SlateCore"
}
);

PrivateDefinitions.Add("MDFASTBINDING_CONDENSED_PROFILING=0");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@

#include "MDFastBindingInstance.h"
#include "BindingValues/MDFastBindingValueBase.h"
#include "Utils/MDFastBindingTraceHelpers.h"

void UMDFastBindingDestinationBase::InitializeDestination(UObject* SourceObject)
{
#if defined(MDFASTBINDING_CONDENSED_PROFILING) && MDFASTBINDING_CONDENSED_PROFILING
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of checking for MDFASTBINDING_CONDENSED_PROFILING all over, could you change all the instances to always use MD_TRACE_CPUPROFILER_EVENT_SCOPE_FUNCTION_TEXT and then #define it based on MDFASTBINDING_CONDENSED_PROFILING in MDFastBindingTraceHelpers.h?

I think it ends up being cleaner that way.

MD_TRACE_CPUPROFILER_EVENT_SCOPE_FUNCTION_TEXT(*GetName());
#else
TRACE_CPUPROFILER_EVENT_SCOPE_STR(__FUNCTION__);
TRACE_CPUPROFILER_EVENT_SCOPE_TEXT(*GetName());
#endif

InitializeDestination_Internal(SourceObject);

for (const FMDFastBindingItem& BindingItem : BindingItems)
Expand All @@ -20,8 +26,13 @@ void UMDFastBindingDestinationBase::InitializeDestination(UObject* SourceObject)

void UMDFastBindingDestinationBase::UpdateDestination(UObject* SourceObject)
{
#if defined(MDFASTBINDING_CONDENSED_PROFILING) && MDFASTBINDING_CONDENSED_PROFILING
MD_TRACE_CPUPROFILER_EVENT_SCOPE_FUNCTION_TEXT(*GetName());
#else
TRACE_CPUPROFILER_EVENT_SCOPE_STR(__FUNCTION__);
TRACE_CPUPROFILER_EVENT_SCOPE_TEXT(*GetName());
#endif

if (CheckCachedNeedsUpdate())
{
UpdateDestination_Internal(SourceObject);
Expand All @@ -30,8 +41,13 @@ void UMDFastBindingDestinationBase::UpdateDestination(UObject* SourceObject)

void UMDFastBindingDestinationBase::TerminateDestination(UObject* SourceObject)
{
#if defined(MDFASTBINDING_CONDENSED_PROFILING) && MDFASTBINDING_CONDENSED_PROFILING
MD_TRACE_CPUPROFILER_EVENT_SCOPE_FUNCTION_TEXT(*GetName());
#else
TRACE_CPUPROFILER_EVENT_SCOPE_STR(__FUNCTION__);
TRACE_CPUPROFILER_EVENT_SCOPE_TEXT(*GetName());
#endif

TerminateDestination_Internal(SourceObject);

for (const FMDFastBindingItem& BindingItem : BindingItems)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "BindingDestinations/MDFastBindingDestination_Function.h"

#include "MDFastBinding.h"
#include "Utils/MDFastBindingTraceHelpers.h"

#define LOCTEXT_NAMESPACE "MDFastBindingDestination_Function"

Expand All @@ -18,6 +19,13 @@ void UMDFastBindingDestination_Function::InitializeDestination_Internal(UObject*

void UMDFastBindingDestination_Function::UpdateDestination_Internal(UObject* SourceObject)
{
#if defined(MDFASTBINDING_CONDENSED_PROFILING) && MDFASTBINDING_CONDENSED_PROFILING
MD_TRACE_CPUPROFILER_EVENT_SCOPE_FUNCTION_TEXT(*Function.GetFunctionName().ToString());
#else
TRACE_CPUPROFILER_EVENT_SCOPE_STR(__FUNCTION__);
TRACE_CPUPROFILER_EVENT_SCOPE_TEXT(*Function.GetFunctionName().ToString());
#endif

bNeedsUpdate = false;
Function.CallFunction(SourceObject);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,12 @@ void UMDFastBindingValueBase::TerminateValue(UObject* SourceObject)

TTuple<const FProperty*, void*> UMDFastBindingValueBase::GetValue(UObject* SourceObject, bool& OutDidUpdate)
{
#if defined(MDFASTBINDING_CONDENSED_PROFILING) && MDFASTBINDING_CONDENSED_PROFILING
MD_TRACE_CPUPROFILER_EVENT_SCOPE_FUNCTION_TEXT(*GetName());
#else
TRACE_CPUPROFILER_EVENT_SCOPE_STR(__FUNCTION__);
TRACE_CPUPROFILER_EVENT_SCOPE_TEXT(*GetName());
#endif

OutDidUpdate = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "MDFastBinding.h"
#include "BindingDestinations/MDFastBindingDestinationBase.h"
#include "Utils/MDFastBindingTraceHelpers.h"

#define LOCTEXT_NAMESPACE "MDFastBindingDestination_Function"

Expand All @@ -18,6 +19,13 @@ UMDFastBindingValue_Function::UMDFastBindingValue_Function()

TTuple<const FProperty*, void*> UMDFastBindingValue_Function::GetValue_Internal(UObject* SourceObject)
{
#if defined(MDFASTBINDING_CONDENSED_PROFILING) && MDFASTBINDING_CONDENSED_PROFILING
MD_TRACE_CPUPROFILER_EVENT_SCOPE_FUNCTION_TEXT(*Function.GetFunctionName().ToString());
#else
TRACE_CPUPROFILER_EVENT_SCOPE_STR(__FUNCTION__);
TRACE_CPUPROFILER_EVENT_SCOPE_TEXT(*Function.GetFunctionName().ToString());
#endif

bNeedsUpdate = false;
return Function.CallFunction(SourceObject);
}
Expand Down
20 changes: 20 additions & 0 deletions Source/MDFastBinding/Private/MDFastBindingContainer.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
#include "MDFastBindingContainer.h"

#include "MDFastBindingInstance.h"
#include "MDFastBindingLog.h"
#include "MDFastBindingOwnerInterface.h"
#include "BindingDestinations/MDFastBindingDestinationBase.h"
#include "Blueprint/UserWidget.h"
#include "Utils/MDFastBindingTraceHelpers.h"
#include "WidgetExtension/MDFastBindingWidgetExtension.h"

void UMDFastBindingContainer::InitializeBindings(UObject* SourceObject)
{
#if defined(MDFASTBINDING_CONDENSED_PROFILING) && MDFASTBINDING_CONDENSED_PROFILING
MD_TRACE_CPUPROFILER_EVENT_SCOPE_FUNCTION_TEXT(*GetNameSafe(SourceObject));
#else
TRACE_CPUPROFILER_EVENT_SCOPE_STR(__FUNCTION__);
TRACE_CPUPROFILER_EVENT_SCOPE_TEXT(*GetNameSafe(SourceObject));
#endif

if (const UUserWidget* OuterWidget = Cast<UUserWidget>(GetOuter()))
{
UE_CLOG(!OuterWidget->IsDesignTime(), LogMDFastBinding, Warning, TEXT("[%s] uses a deprecated property-based MDFastBindingContainer, resave it to automatically upgrade it to a widget extension"), *GetNameSafe(OuterWidget->GetClass()));
Expand All @@ -27,8 +36,12 @@ void UMDFastBindingContainer::InitializeBindings(UObject* SourceObject)

void UMDFastBindingContainer::UpdateBindings(UObject* SourceObject)
{
#if defined(MDFASTBINDING_CONDENSED_PROFILING) && MDFASTBINDING_CONDENSED_PROFILING
MD_TRACE_CPUPROFILER_EVENT_SCOPE_FUNCTION_TEXT(*GetNameSafe(SourceObject));
#else
TRACE_CPUPROFILER_EVENT_SCOPE_STR(__FUNCTION__);
TRACE_CPUPROFILER_EVENT_SCOPE_TEXT(*GetNameSafe(SourceObject));
#endif

for (TConstSetBitIterator<> It(TickingBindings); It; ++It)
{
Expand All @@ -38,6 +51,13 @@ void UMDFastBindingContainer::UpdateBindings(UObject* SourceObject)

void UMDFastBindingContainer::TerminateBindings(UObject* SourceObject)
{
#if defined(MDFASTBINDING_CONDENSED_PROFILING) && MDFASTBINDING_CONDENSED_PROFILING
MD_TRACE_CPUPROFILER_EVENT_SCOPE_FUNCTION_TEXT(*GetNameSafe(SourceObject));
#else
TRACE_CPUPROFILER_EVENT_SCOPE_STR(__FUNCTION__);
TRACE_CPUPROFILER_EVENT_SCOPE_TEXT(*GetNameSafe(SourceObject));
#endif

for (UMDFastBindingInstance* Binding : Bindings)
{
Binding->TerminateBinding(SourceObject);
Expand Down
22 changes: 22 additions & 0 deletions Source/MDFastBinding/Private/MDFastBindingInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "MDFastBindingContainer.h"
#include "BindingDestinations/MDFastBindingDestinationBase.h"
#include "BindingValues/MDFastBindingValueBase.h"
#include "Utils/MDFastBindingTraceHelpers.h"

#if WITH_EDITOR
#include "UObject/ObjectSaveContext.h"
Expand Down Expand Up @@ -39,6 +40,13 @@ UMDFastBindingContainer* UMDFastBindingInstance::GetBindingContainer() const

void UMDFastBindingInstance::InitializeBinding(UObject* SourceObject)
{
#if defined(MDFASTBINDING_CONDENSED_PROFILING) && MDFASTBINDING_CONDENSED_PROFILING && WITH_EDITORONLY_DATA
MD_TRACE_CPUPROFILER_EVENT_SCOPE_FUNCTION_TEXT(*GetBindingDisplayName().ToString());
#else
TRACE_CPUPROFILER_EVENT_SCOPE_STR(__FUNCTION__);
TRACE_CPUPROFILER_EVENT_SCOPE_TEXT(*GetBindingDisplayName().ToString());
#endif

if (BindingDestination != nullptr)
{
BindingDestination->InitializeDestination(SourceObject);
Expand All @@ -47,6 +55,13 @@ void UMDFastBindingInstance::InitializeBinding(UObject* SourceObject)

bool UMDFastBindingInstance::UpdateBinding(UObject* SourceObject)
{
#if defined(MDFASTBINDING_CONDENSED_PROFILING) && MDFASTBINDING_CONDENSED_PROFILING && WITH_EDITORONLY_DATA
MD_TRACE_CPUPROFILER_EVENT_SCOPE_FUNCTION_TEXT(*GetBindingDisplayName().ToString());
#else
TRACE_CPUPROFILER_EVENT_SCOPE_STR(__FUNCTION__);
TRACE_CPUPROFILER_EVENT_SCOPE_TEXT(*GetBindingDisplayName().ToString());
#endif

if (BindingDestination != nullptr)
{
BindingDestination->UpdateDestination(SourceObject);
Expand All @@ -58,6 +73,13 @@ bool UMDFastBindingInstance::UpdateBinding(UObject* SourceObject)

void UMDFastBindingInstance::TerminateBinding(UObject* SourceObject)
{
#if defined(MDFASTBINDING_CONDENSED_PROFILING) && MDFASTBINDING_CONDENSED_PROFILING && WITH_EDITORONLY_DATA
MD_TRACE_CPUPROFILER_EVENT_SCOPE_FUNCTION_TEXT(*GetBindingDisplayName().ToString());
#else
TRACE_CPUPROFILER_EVENT_SCOPE_STR(__FUNCTION__);
TRACE_CPUPROFILER_EVENT_SCOPE_TEXT(*GetBindingDisplayName().ToString());
#endif

if (BindingDestination != nullptr)
{
BindingDestination->TerminateDestination(SourceObject);
Expand Down
12 changes: 12 additions & 0 deletions Source/MDFastBinding/Public/Utils/MDFastBindingTraceHelpers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// 1047 Custom - Enhance MDFastBinding profiling readability
#pragma once

#include "ProfilingDebugging/CpuProfilerTrace.h"

#if defined(MDFASTBINDING_CONDENSED_PROFILING) && MDFASTBINDING_CONDENSED_PROFILING

// Trace a scoped cpu timing event providing the current function along with specified text appended to it
// Note: This macro has a larger overhead compared to TRACE_CPUPROFILER_EVENT_SCOPE_TEXT()
#define MD_TRACE_CPUPROFILER_EVENT_SCOPE_FUNCTION_TEXT(Text) TRACE_CPUPROFILER_EVENT_SCOPE_TEXT(*FString::Printf(TEXT("%s - %s"), ANSI_TO_TCHAR(__FUNCTION__), Text));

#endif