Added Profiler for simple rough time measurement

This commit is contained in:
miku-666
2023-07-31 20:47:41 +02:00
parent 22eff0df73
commit c9c69a7ed8
9 changed files with 53 additions and 16 deletions

View File

@@ -3,9 +3,9 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.Windows.Forms;
using MetroFramework.Forms;
using Newtonsoft.Json.Linq;
using PckStudio.Extensions;
using PckStudio.Forms.Utilities;
using PckStudio.Internal;
namespace PckStudio.Forms.Additional_Popups.Animation
{
@@ -30,11 +30,10 @@ namespace PckStudio.Forms.Additional_Popups.Animation
private void InitializeTreeviews()
{
Stopwatch stopwatch = Stopwatch.StartNew();
Profiler.Start();
GetTileDataToView("blocks", treeViewBlocks.Nodes, treeViewBlockCache.Add);
GetTileDataToView("items", treeViewItems.Nodes, treeViewItemCache.Add);
stopwatch.Stop();
Debug.WriteLine($"{nameof(InitializeTreeviews)} took {stopwatch.ElapsedMilliseconds}ms");
Profiler.Stop();
}
private void treeViews_AfterSelect(object sender, TreeViewEventArgs e)
@@ -57,7 +56,7 @@ namespace PckStudio.Forms.Additional_Popups.Animation
"items" => AnimationResources.ItemTileInfos,
_ => throw new InvalidOperationException(key)
};
Stopwatch stopwatch = Stopwatch.StartNew();
Profiler.Start();
try
{
if (textureInfos is not null)
@@ -83,8 +82,7 @@ namespace PckStudio.Forms.Additional_Popups.Animation
MessageBox.Show(j_ex.Message, "Error");
return;
}
stopwatch.Stop();
Debug.WriteLine($"{nameof(GetTileDataToView)} took {stopwatch.ElapsedMilliseconds}ms", category: nameof(ChangeTile));
Profiler.Stop();
}
void filter_TextChanged(object sender, EventArgs e)

View File

@@ -24,7 +24,8 @@ namespace PckStudio
internal static void Initialize()
{
Stopwatch stopwatch = Stopwatch.StartNew();
Profiler.Configure(Debug.Listeners[0]);
Profiler.Start();
{
_entityImages ??= Resources.entities_sheet.CreateImageList(32).ToArray();
DataCacher ??= new FileCacher(Program.AppDataCache);
@@ -34,8 +35,7 @@ namespace PckStudio
SettingsManager.Initialize();
CultureInfo.CurrentCulture = CultureInfo.InvariantCulture;
}
stopwatch.Stop();
Debug.WriteLine($"{nameof(ApplicationScope.Initialize)} took {stopwatch.ElapsedMilliseconds}ms");
Profiler.Stop();
}
}
}

View File

@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace PckStudio.Internal
{
internal static class Profiler
{
private static Stopwatch _stopwatch = new Stopwatch();
private static TraceListener _listener;
[Conditional("DEBUG")]
internal static void Configure(TraceListener listener)
{
_listener = listener;
}
[Conditional("DEBUG")]
internal static void Start([CallerMemberName] string caller = default!, [CallerFilePath] string source = default!, [CallerLineNumber] int line = default!)
{
_listener?.WriteLine($"Stopwatch starts", category: nameof(Profiler));
_listener?.WriteLine($"{source}@{caller}:{line}", category: nameof(Profiler));
_stopwatch.Restart();
}
[Conditional("DEBUG")]
internal static void Stop([CallerMemberName] string caller = default!, [CallerFilePath] string source = default!, [CallerLineNumber] int line = default!)
{
_stopwatch.Stop();
_listener?.WriteLine($"{caller} took {_stopwatch.ElapsedMilliseconds}ms", category: nameof(Profiler));
}
}
}

View File

@@ -195,7 +195,7 @@
<Compile Include="Forms\Utilities\AppSettingsForm.Designer.cs">
<DependentUpon>AppSettingsForm.cs</DependentUpon>
</Compile>
<Compile Include="Internals\ApplicationBuildInfo.cs" />
<Compile Include="Internal\ApplicationBuildInfo.cs" />
<Compile Include="Classes\API\PCKCenter\model\PCKCenterJSON.cs" />
<Compile Include="Classes\API\PCKCenter\PCKCollections.cs" />
<Compile Include="Classes\API\PCKCenter\PCKCollectionsLocal.cs" />
@@ -219,11 +219,12 @@
<Compile Include="Classes\Misc\FileCacher.cs" />
<Compile Include="Classes\Misc\OpenFolderDialog.cs" />
<Compile Include="Classes\Models\DefaultModels\Steve64x64Model.cs" />
<Compile Include="Internals\ApplicationScope.cs" />
<Compile Include="Internals\SettingsManager.cs" />
<Compile Include="Internals\SkinBOX.cs" />
<Compile Include="Internal\ApplicationScope.cs" />
<Compile Include="Internal\Profiler.cs" />
<Compile Include="Internal\SettingsManager.cs" />
<Compile Include="Internal\SkinBOX.cs" />
<Compile Include="Extensions\ImageExtensions.cs" />
<Compile Include="Internals\SkinANIM.cs" />
<Compile Include="Internal\SkinANIM.cs" />
<Compile Include="Classes\Models\DefaultModels\Steve64x32Model.cs" />
<Compile Include="Classes\Models\DefaultModels\ModelBase.cs" />
<Compile Include="Classes\Models\Backgrounds.cs" />
@@ -261,7 +262,7 @@
<Compile Include="Features\WiiUPanel.Designer.cs">
<DependentUpon>WiiUPanel.cs</DependentUpon>
</Compile>
<Compile Include="Internals\CommitInfo.cs" />
<Compile Include="Internal\CommitInfo.cs" />
<Compile Include="Forms\Additional-Popups\EntityForms\AddEntry.cs">
<SubType>Form</SubType>
</Compile>