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

Skytools benchmark #907

Merged
merged 7 commits into from
May 27, 2020
Merged
Show file tree
Hide file tree
Changes from 6 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
50 changes: 0 additions & 50 deletions TLM/CSUtil.Commons/Benchmark/Benchmark.cs

This file was deleted.

32 changes: 0 additions & 32 deletions TLM/CSUtil.Commons/Benchmark/BenchmarkProfile.cs

This file was deleted.

91 changes: 0 additions & 91 deletions TLM/CSUtil.Commons/Benchmark/BenchmarkProfileProvider.cs

This file was deleted.

12 changes: 0 additions & 12 deletions TLM/CSUtil.Commons/CSUtil.Commons.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,6 @@
<WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>..\TMPE.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Benchmark|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\Benchmark\</OutputPath>
<DefineConstants>DEBUG;TRACE;BENCHMARK</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>..\TMPE.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'PF2_Debug|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\PF2_Debug\</OutputPath>
Expand Down Expand Up @@ -75,11 +66,8 @@
<ItemGroup>
<Compile Include="ArrowDirection.cs" />
<Compile Include="ArrowDirectionUtil.cs" />
<Compile Include="Benchmark\BenchmarkProfileProvider.cs" />
<Compile Include="EnumUtil.cs" />
<Compile Include="Log.cs" />
<Compile Include="Benchmark\Benchmark.cs" />
<Compile Include="Benchmark\BenchmarkProfile.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TernaryBool.cs" />
<Compile Include="TernaryBoolUtil.cs" />
Expand Down
87 changes: 87 additions & 0 deletions TLM/TLM/Benchmark/BenchmarkManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// <copyright file="RealTimeBenchmark.cs" company="dymanoid">
// Copyright (c) dymanoid. All rights reserved.
// </copyright>

namespace TrafficManager.Benchmark {
#if BENCHMARK
using ColossalFramework.IO;
using SkyTools.Benchmarks;
using SkyTools.Tools;

/// <summary>
/// A special class that handles the performance benchmarking.
/// </summary>
internal static class BenchmarkManager {
/// <summary>
/// Initializes the benchmarking.
/// </summary>
public static void Setup() {
var benchmarkSimulationManager = new BenchmarkSimulationManager();
SimulationManager.RegisterSimulationManager(benchmarkSimulationManager);
LoadingManager.instance.m_levelUnloaded += benchmarkSimulationManager.Stop;
}

private sealed class BenchmarkSimulationManager : ISimulationManager {
private readonly Benchmark simulationManagerSimulationStepBenchmark;
private bool isRunning;

public BenchmarkSimulationManager() {
simulationManagerSimulationStepBenchmark = Benchmark.Create(0x1000 * 0x100);
SetupMethods();
}

public void Stop() {
simulationManagerSimulationStepBenchmark.Stop();
simulationManagerSimulationStepBenchmark.Dump();
isRunning = false;
Log.Info("Benchmarking stopped.");
}

public void EarlyUpdateData() {
}

public void GetData(FastList<IDataContainer> data) {
}

public string GetName() => nameof(BenchmarkSimulationManager);

public ThreadProfiler GetSimulationProfiler() => null;

public void LateUpdateData(SimulationManager.UpdateMode mode) {
}

public void SimulationStep(int subStep) {
if (subStep == 1000 || subStep == 0) {
// This is the 'late update data' phase or the simulation is paused
return;
} else if (!isRunning) {
isRunning = true;

try {
// On failure, don't try to activate benchmark on each step
simulationManagerSimulationStepBenchmark.Start();
Log.Info("Benchmarking started.");
}
catch {
}
}

if ((SimulationManager.instance.m_currentFrameIndex & 0xFFF) == 0xFFF) {
simulationManagerSimulationStepBenchmark.MakeSnapshot();
}
}

public void UpdateData(SimulationManager.UpdateMode mode) {
}

private void SetupMethods() {
try {
simulationManagerSimulationStepBenchmark.BenchmarkMethod(typeof(SimulationManager), "SimulationStep");
}
catch {
}
}
}
}
#endif
}
16 changes: 6 additions & 10 deletions TLM/TLM/Custom/AI/CustomCarAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace TrafficManager.Custom.AI {
using ColossalFramework.Math;
using ColossalFramework;
using CSUtil.Commons.Benchmark;
using CSUtil.Commons;
using JetBrains.Annotations;
using System.Diagnostics.CodeAnalysis;
Expand Down Expand Up @@ -469,15 +468,12 @@ public bool CustomStartPathFind(ushort vehicleId,

ExtVehicleType vehicleType;

using (var bm = Benchmark.MaybeCreateBenchmark(null, "OnStartPathFind")) {
vehicleType =
ExtVehicleManager.Instance.OnStartPathFind(vehicleId, ref vehicleData, null);
if (vehicleType == ExtVehicleType.None) {
Log._DebugOnlyWarning(
$"CustomCarAI.CustomStartPathFind({vehicleId}): Vehicle {vehicleId} " +
"does not have a valid vehicle type!");
vehicleType = ExtVehicleType.RoadVehicle;
}
vehicleType = ExtVehicleManager.Instance.OnStartPathFind(vehicleId, ref vehicleData, null);
if (vehicleType == ExtVehicleType.None) {
Log._DebugOnlyWarning(
$"CustomCarAI.CustomStartPathFind({vehicleId}): Vehicle {vehicleId} " +
"does not have a valid vehicle type!");
vehicleType = ExtVehicleType.RoadVehicle;
}

VehicleInfo info = m_info;
Expand Down
9 changes: 2 additions & 7 deletions TLM/TLM/Custom/AI/CustomFireTruckAI.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
namespace TrafficManager.Custom.AI {
namespace TrafficManager.Custom.AI {
using ColossalFramework;
using CSUtil.Commons.Benchmark;
using JetBrains.Annotations;
using TrafficManager.API.Traffic.Data;
using TrafficManager.API.Traffic.Enums;
Expand All @@ -21,16 +20,12 @@ public bool CustomStartPathFind(ushort vehicleId,
bool endBothWays,
bool undergroundTarget) {

ExtVehicleType vehicleType;

using (var bm = Benchmark.MaybeCreateBenchmark(null, "OnStartPathFind")) {
vehicleType = ExtVehicleManager.Instance.OnStartPathFind(
ExtVehicleType vehicleType = ExtVehicleManager.Instance.OnStartPathFind(
vehicleId,
ref vehicleData,
(vehicleData.m_flags & Vehicle.Flags.Emergency2) != 0
? ExtVehicleType.Emergency
: ExtVehicleType.Service);
}

VehicleInfo info = m_info;
bool allowUnderground = (vehicleData.m_flags & (Vehicle.Flags.Underground
Expand Down
Loading