Skip to content

Commit

Permalink
Added profiling code tutorial source code
Browse files Browse the repository at this point in the history
  • Loading branch information
orfeasel committed Apr 23, 2020
1 parent d0a78b6 commit 1df892c
Show file tree
Hide file tree
Showing 59 changed files with 698 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Profiling_Code/Config/DefaultEditor.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[UnrealEd.SimpleMap]
SimpleMapName=/Game/ThirdPersonCPP/Maps/ThirdPersonExampleMap

[EditoronlyBP]
bAllowClassAndBlueprintPinMatching=true
bReplaceBlueprintWithClass= true
bDontLoadBlueprintOutsideEditor= true
bBlueprintIsNotBlueprintType= true
2 changes: 2 additions & 0 deletions Profiling_Code/Config/DefaultEditorPerProjectUserSettings.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[ContentBrowser]
ContentBrowserTab1.SelectedPaths=/Game/ThirdPersonCPP
21 changes: 21 additions & 0 deletions Profiling_Code/Config/DefaultEngine.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[/Script/EngineSettings.GameMapsSettings]
GameDefaultMap=/Game/ThirdPersonCPP/Maps/ThirdPersonExampleMap
EditorStartupMap=/Game/ThirdPersonCPP/Maps/ThirdPersonExampleMap
GlobalDefaultGameMode="/Script/ProfilingBlocks.ProfilingBlocksGameMode"

[/Script/IOSRuntimeSettings.IOSRuntimeSettings]
MinimumiOSVersion=IOS_11

[/Script/Engine.Engine]
+ActiveGameNameRedirects=(OldGameName="TP_ThirdPerson",NewGameName="/Script/ProfilingBlocks")
+ActiveGameNameRedirects=(OldGameName="/Script/TP_ThirdPerson",NewGameName="/Script/ProfilingBlocks")
+ActiveClassRedirects=(OldClassName="TP_ThirdPersonGameMode",NewClassName="ProfilingBlocksGameMode")
+ActiveClassRedirects=(OldClassName="TP_ThirdPersonCharacter",NewClassName="ProfilingBlocksCharacter")

[/Script/HardwareTargeting.HardwareTargetingSettings]
TargetedHardwareClass=Desktop
AppliedTargetedHardwareClass=Desktop
DefaultGraphicsPerformance=Maximum
AppliedDefaultGraphicsPerformance=Maximum


3 changes: 3 additions & 0 deletions Profiling_Code/Config/DefaultGame.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[/Script/EngineSettings.GeneralProjectSettings]
ProjectID=A24BC0AB4A8B4802F984D68073B692D0
ProjectName=Third Person Game Template
169 changes: 169 additions & 0 deletions Profiling_Code/Config/DefaultInput.ini

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
69 changes: 69 additions & 0 deletions Profiling_Code/ProfilingBlocks.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.28315.86
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Engine", "Engine", "{DB81151B-B46B-44CB-A071-BC67B3ED7C76}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Games", "Games", "{49DF266D-2E16-4748-83CA-71E4079F6858}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ProfilingBlocks", "Intermediate\ProjectFiles\ProfilingBlocks.vcxproj", "{AD9E796C-EECF-4FF2-90A2-63E90DEC1626}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UE4", "Intermediate\ProjectFiles\UE4.vcxproj", "{E07658A1-F08E-4D58-AA2D-BF3AA15965B4}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Visualizers", "Visualizers", "{BF2CA999-6B91-4240-9E6F-124841EBAB47}"
ProjectSection(SolutionItems) = preProject
..\..\Program Files\Epic Games\UE_4.24\Engine\Extras\VisualStudioDebugging\UE4.natvis = ..\..\Program Files\Epic Games\UE_4.24\Engine\Extras\VisualStudioDebugging\UE4.natvis
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
DebugGame Editor|Win32 = DebugGame Editor|Win32
DebugGame Editor|Win64 = DebugGame Editor|Win64
DebugGame|Win32 = DebugGame|Win32
DebugGame|Win64 = DebugGame|Win64
Development Editor|Win32 = Development Editor|Win32
Development Editor|Win64 = Development Editor|Win64
Development|Win32 = Development|Win32
Development|Win64 = Development|Win64
Shipping|Win32 = Shipping|Win32
Shipping|Win64 = Shipping|Win64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{AD9E796C-EECF-4FF2-90A2-63E90DEC1626}.DebugGame Editor|Win32.ActiveCfg = Invalid|Win32
{AD9E796C-EECF-4FF2-90A2-63E90DEC1626}.DebugGame Editor|Win64.ActiveCfg = DebugGame_Editor|x64
{AD9E796C-EECF-4FF2-90A2-63E90DEC1626}.DebugGame Editor|Win64.Build.0 = DebugGame_Editor|x64
{AD9E796C-EECF-4FF2-90A2-63E90DEC1626}.DebugGame|Win32.ActiveCfg = DebugGame|Win32
{AD9E796C-EECF-4FF2-90A2-63E90DEC1626}.DebugGame|Win32.Build.0 = DebugGame|Win32
{AD9E796C-EECF-4FF2-90A2-63E90DEC1626}.DebugGame|Win64.ActiveCfg = DebugGame|x64
{AD9E796C-EECF-4FF2-90A2-63E90DEC1626}.DebugGame|Win64.Build.0 = DebugGame|x64
{AD9E796C-EECF-4FF2-90A2-63E90DEC1626}.Development Editor|Win32.ActiveCfg = Invalid|Win32
{AD9E796C-EECF-4FF2-90A2-63E90DEC1626}.Development Editor|Win64.ActiveCfg = Development_Editor|x64
{AD9E796C-EECF-4FF2-90A2-63E90DEC1626}.Development Editor|Win64.Build.0 = Development_Editor|x64
{AD9E796C-EECF-4FF2-90A2-63E90DEC1626}.Development|Win32.ActiveCfg = Development|Win32
{AD9E796C-EECF-4FF2-90A2-63E90DEC1626}.Development|Win32.Build.0 = Development|Win32
{AD9E796C-EECF-4FF2-90A2-63E90DEC1626}.Development|Win64.ActiveCfg = Development|x64
{AD9E796C-EECF-4FF2-90A2-63E90DEC1626}.Development|Win64.Build.0 = Development|x64
{AD9E796C-EECF-4FF2-90A2-63E90DEC1626}.Shipping|Win32.ActiveCfg = Shipping|Win32
{AD9E796C-EECF-4FF2-90A2-63E90DEC1626}.Shipping|Win32.Build.0 = Shipping|Win32
{AD9E796C-EECF-4FF2-90A2-63E90DEC1626}.Shipping|Win64.ActiveCfg = Shipping|x64
{AD9E796C-EECF-4FF2-90A2-63E90DEC1626}.Shipping|Win64.Build.0 = Shipping|x64
{E07658A1-F08E-4D58-AA2D-BF3AA15965B4}.DebugGame Editor|Win32.ActiveCfg = BuiltWithUnrealBuildTool|Win32
{E07658A1-F08E-4D58-AA2D-BF3AA15965B4}.DebugGame Editor|Win64.ActiveCfg = BuiltWithUnrealBuildTool|Win32
{E07658A1-F08E-4D58-AA2D-BF3AA15965B4}.DebugGame|Win32.ActiveCfg = BuiltWithUnrealBuildTool|Win32
{E07658A1-F08E-4D58-AA2D-BF3AA15965B4}.DebugGame|Win64.ActiveCfg = BuiltWithUnrealBuildTool|Win32
{E07658A1-F08E-4D58-AA2D-BF3AA15965B4}.Development Editor|Win32.ActiveCfg = BuiltWithUnrealBuildTool|Win32
{E07658A1-F08E-4D58-AA2D-BF3AA15965B4}.Development Editor|Win64.ActiveCfg = BuiltWithUnrealBuildTool|Win32
{E07658A1-F08E-4D58-AA2D-BF3AA15965B4}.Development|Win32.ActiveCfg = BuiltWithUnrealBuildTool|Win32
{E07658A1-F08E-4D58-AA2D-BF3AA15965B4}.Development|Win64.ActiveCfg = BuiltWithUnrealBuildTool|Win32
{E07658A1-F08E-4D58-AA2D-BF3AA15965B4}.Shipping|Win32.ActiveCfg = BuiltWithUnrealBuildTool|Win32
{E07658A1-F08E-4D58-AA2D-BF3AA15965B4}.Shipping|Win64.ActiveCfg = BuiltWithUnrealBuildTool|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{E07658A1-F08E-4D58-AA2D-BF3AA15965B4} = {DB81151B-B46B-44CB-A071-BC67B3ED7C76}
{AD9E796C-EECF-4FF2-90A2-63E90DEC1626} = {49DF266D-2E16-4748-83CA-71E4079F6858}
EndGlobalSection
EndGlobal
16 changes: 16 additions & 0 deletions Profiling_Code/ProfilingBlocks.uproject
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"FileVersion": 3,
"EngineAssociation": "4.24",
"Category": "",
"Description": "",
"Modules": [
{
"Name": "ProfilingBlocks",
"Type": "Runtime",
"LoadingPhase": "Default",
"AdditionalDependencies": [
"Engine"
]
}
]
}
3 changes: 3 additions & 0 deletions Profiling_Code/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Profiling Code using the Unreal Engine Profiler Tool

Read the full tutorial here: https://www.orfeasel.com/profiling-code-blocks/
14 changes: 14 additions & 0 deletions Profiling_Code/Source/ProfilingBlocks.Target.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright 1998-2019 Epic Games, Inc. All Rights Reserved.

using UnrealBuildTool;
using System.Collections.Generic;

public class ProfilingBlocksTarget : TargetRules
{
public ProfilingBlocksTarget(TargetInfo Target) : base(Target)
{
Type = TargetType.Game;
DefaultBuildSettings = BuildSettingsVersion.V2;
ExtraModuleNames.Add("ProfilingBlocks");
}
}
81 changes: 81 additions & 0 deletions Profiling_Code/Source/ProfilingBlocks/HeavyComp.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Fill out your copyright notice in the Description page of Project Settings.


#include "HeavyComp.h"

/* Declaring a stat group that will be visible to the profiler, named Orfeas*/
DECLARE_STATS_GROUP(TEXT("Orfeas_Game"), STATGROUP_Orfeas, STATCAT_Advanced);
/* Declaring a cycle stat that belongs to "Orfeas", named Orfeas-FindPrimeNumbers*/
DECLARE_CYCLE_STAT(TEXT("Orfeas - FindPrimeNumbers"), STAT_FindPrimeNumbers, STATGROUP_Orfeas);

// Sets default values for this component's properties
UHeavyComp::UHeavyComp()
{
// Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features
// off to improve performance if you don't need them.
PrimaryComponentTick.bCanEverTick = true;

// ...
}


// Called when the game starts
void UHeavyComp::BeginPlay()
{
Super::BeginPlay();

// ...

}


// Called every frame
void UHeavyComp::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

// ...
}

TArray<int32> UHeavyComp::FindPrimeNumbers()
{
{//Used to declare the "start" of the block we're profiling

//Tell the engine that we're profiling the currect block using the STAT_FindPrimeNumbers stat
SCOPE_CYCLE_COUNTER(STAT_FindPrimeNumbers);

//A really bad way to find prime numbers
//Don't use this in an actual application
TArray<int32> Primes;
Primes.Add(1);
Primes.Add(2);
Primes.Add(3);

int32 CurrentNumber = 4;

while (Primes.Num() <= PrimeNumbersToFind)
{
bool IsPrime = true;
for (int32 index = 2; (index < CurrentNumber / 2) && IsPrime; index++)
{
if (CurrentNumber % index == 0)
{
IsPrime = false;

}
}
if (IsPrime)
{
Primes.Add(CurrentNumber);
}
CurrentNumber++;
}
}//Closing the block of code we're profiling

//This means that the following two lines won't be profiled and as a result they won't have an impact in the STAT_FindPrimeNumbers used above
int32 DummyAction=0;
DummyAction++;

return Primes;
}

32 changes: 32 additions & 0 deletions Profiling_Code/Source/ProfilingBlocks/HeavyComp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "HeavyComp.generated.h"


UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class PROFILINGBLOCKS_API UHeavyComp : public UActorComponent
{
GENERATED_BODY()

public:
// Sets default values for this component's properties
UHeavyComp();

protected:
// Called when the game starts
virtual void BeginPlay() override;

UPROPERTY(EditAnywhere)
int32 PrimeNumbersToFind=5000;

public:
// Called every frame
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;

UFUNCTION(BlueprintCallable)
TArray<int32> FindPrimeNumbers();
};
13 changes: 13 additions & 0 deletions Profiling_Code/Source/ProfilingBlocks/ProfilingBlocks.Build.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright 1998-2019 Epic Games, Inc. All Rights Reserved.

using UnrealBuildTool;

public class ProfilingBlocks : ModuleRules
{
public ProfilingBlocks(ReadOnlyTargetRules Target) : base(Target)
{
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;

PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "HeadMountedDisplay" });
}
}
7 changes: 7 additions & 0 deletions Profiling_Code/Source/ProfilingBlocks/ProfilingBlocks.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright 1998-2019 Epic Games, Inc. All Rights Reserved.

#include "ProfilingBlocks.h"
#include "Modules/ModuleManager.h"

IMPLEMENT_PRIMARY_GAME_MODULE( FDefaultGameModuleImpl, ProfilingBlocks, "ProfilingBlocks" );

5 changes: 5 additions & 0 deletions Profiling_Code/Source/ProfilingBlocks/ProfilingBlocks.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Copyright 1998-2019 Epic Games, Inc. All Rights Reserved.

#pragma once

#include "CoreMinimal.h"
Loading

0 comments on commit 1df892c

Please sign in to comment.