fix: Cleans up core code (#1187)
**Only one functional change** * Fixes a bug in LogFactory where `Warning` is being logged as `Information` Non-functional changes: * Updates/Fixes copyright headers * Removes namespace scopes for core files. View with [whitespace off](https://github.com/modernuo/ModernUO/pull/1187/files?w=1).
This commit is contained in:
parent
0138d40bda
commit
f268d5d4e2
262 changed files with 28527 additions and 28646 deletions
|
|
@ -3,78 +3,77 @@ using System.Collections.Generic;
|
|||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
|
||||
namespace Server.Diagnostics
|
||||
namespace Server.Diagnostics;
|
||||
|
||||
public abstract class BaseProfile
|
||||
{
|
||||
public abstract class BaseProfile
|
||||
private readonly Stopwatch _stopwatch;
|
||||
|
||||
protected BaseProfile(string name)
|
||||
{
|
||||
private readonly Stopwatch _stopwatch;
|
||||
Name = name;
|
||||
|
||||
protected BaseProfile(string name)
|
||||
_stopwatch = new Stopwatch();
|
||||
}
|
||||
|
||||
public string Name { get; }
|
||||
|
||||
public long Count { get; private set; }
|
||||
|
||||
public TimeSpan AverageTime => TimeSpan.FromTicks(TotalTime.Ticks / Math.Max(Count, 1));
|
||||
|
||||
public TimeSpan PeakTime { get; private set; }
|
||||
|
||||
public TimeSpan TotalTime { get; private set; }
|
||||
|
||||
public static void WriteAll<T>(TextWriter op, IEnumerable<T> profiles) where T : BaseProfile
|
||||
{
|
||||
var list = new List<T>(profiles);
|
||||
|
||||
list.Sort((a, b) => -a.TotalTime.CompareTo(b.TotalTime));
|
||||
|
||||
foreach (var prof in list)
|
||||
{
|
||||
Name = name;
|
||||
|
||||
_stopwatch = new Stopwatch();
|
||||
prof.WriteTo(op);
|
||||
op.WriteLine();
|
||||
}
|
||||
}
|
||||
|
||||
public string Name { get; }
|
||||
|
||||
public long Count { get; private set; }
|
||||
|
||||
public TimeSpan AverageTime => TimeSpan.FromTicks(TotalTime.Ticks / Math.Max(Count, 1));
|
||||
|
||||
public TimeSpan PeakTime { get; private set; }
|
||||
|
||||
public TimeSpan TotalTime { get; private set; }
|
||||
|
||||
public static void WriteAll<T>(TextWriter op, IEnumerable<T> profiles) where T : BaseProfile
|
||||
public virtual void Start()
|
||||
{
|
||||
if (_stopwatch.IsRunning)
|
||||
{
|
||||
var list = new List<T>(profiles);
|
||||
|
||||
list.Sort((a, b) => -a.TotalTime.CompareTo(b.TotalTime));
|
||||
|
||||
foreach (var prof in list)
|
||||
{
|
||||
prof.WriteTo(op);
|
||||
op.WriteLine();
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void Start()
|
||||
{
|
||||
if (_stopwatch.IsRunning)
|
||||
{
|
||||
_stopwatch.Reset();
|
||||
}
|
||||
|
||||
_stopwatch.Start();
|
||||
}
|
||||
|
||||
public virtual void Finish()
|
||||
{
|
||||
var elapsed = _stopwatch.Elapsed;
|
||||
|
||||
TotalTime += elapsed;
|
||||
|
||||
if (elapsed > PeakTime)
|
||||
{
|
||||
PeakTime = elapsed;
|
||||
}
|
||||
|
||||
Count++;
|
||||
|
||||
_stopwatch.Reset();
|
||||
}
|
||||
|
||||
public virtual void WriteTo(TextWriter op)
|
||||
_stopwatch.Start();
|
||||
}
|
||||
|
||||
public virtual void Finish()
|
||||
{
|
||||
var elapsed = _stopwatch.Elapsed;
|
||||
|
||||
TotalTime += elapsed;
|
||||
|
||||
if (elapsed > PeakTime)
|
||||
{
|
||||
op.Write(
|
||||
"{0,-100} {1,12:N0} {2,12:F5} {3,-12:F5} {4,12:F5}",
|
||||
Name,
|
||||
Count,
|
||||
AverageTime.TotalSeconds,
|
||||
PeakTime.TotalSeconds,
|
||||
TotalTime.TotalSeconds
|
||||
);
|
||||
PeakTime = elapsed;
|
||||
}
|
||||
|
||||
Count++;
|
||||
|
||||
_stopwatch.Reset();
|
||||
}
|
||||
|
||||
public virtual void WriteTo(TextWriter op)
|
||||
{
|
||||
op.Write(
|
||||
"{0,-100} {1,12:N0} {2,12:F5} {3,-12:F5} {4,12:F5}",
|
||||
Name,
|
||||
Count,
|
||||
AverageTime.TotalSeconds,
|
||||
PeakTime.TotalSeconds,
|
||||
TotalTime.TotalSeconds
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,31 +1,30 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Server.Diagnostics
|
||||
namespace Server.Diagnostics;
|
||||
|
||||
public class GumpProfile : BaseProfile
|
||||
{
|
||||
public class GumpProfile : BaseProfile
|
||||
private static readonly Dictionary<Type, GumpProfile> _profiles = new();
|
||||
|
||||
public GumpProfile(Type type) : base(type.FullName)
|
||||
{
|
||||
private static readonly Dictionary<Type, GumpProfile> _profiles = new();
|
||||
}
|
||||
|
||||
public GumpProfile(Type type) : base(type.FullName)
|
||||
public static IEnumerable<GumpProfile> Profiles => _profiles.Values;
|
||||
|
||||
public static GumpProfile Acquire(Type type)
|
||||
{
|
||||
if (!Core.Profiling)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public static IEnumerable<GumpProfile> Profiles => _profiles.Values;
|
||||
|
||||
public static GumpProfile Acquire(Type type)
|
||||
if (!_profiles.TryGetValue(type, out var prof))
|
||||
{
|
||||
if (!Core.Profiling)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!_profiles.TryGetValue(type, out var prof))
|
||||
{
|
||||
_profiles.Add(type, prof = new GumpProfile(type));
|
||||
}
|
||||
|
||||
return prof;
|
||||
_profiles.Add(type, prof = new GumpProfile(type));
|
||||
}
|
||||
|
||||
return prof;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,89 +4,88 @@ using System.IO;
|
|||
using System.Runtime.CompilerServices;
|
||||
using System.Threading;
|
||||
|
||||
namespace Server.Diagnostics
|
||||
namespace Server.Diagnostics;
|
||||
|
||||
public abstract class BasePacketProfile : BaseProfile
|
||||
{
|
||||
public abstract class BasePacketProfile : BaseProfile
|
||||
protected BasePacketProfile(string name) : base(name)
|
||||
{
|
||||
protected BasePacketProfile(string name) : base(name)
|
||||
{
|
||||
}
|
||||
|
||||
public long TotalLength { get; private set; }
|
||||
|
||||
public double AverageLength => (double)TotalLength / Math.Max(Count, 1);
|
||||
|
||||
public void Finish(long length)
|
||||
{
|
||||
Finish();
|
||||
|
||||
TotalLength += length;
|
||||
}
|
||||
|
||||
public override void WriteTo(TextWriter op)
|
||||
{
|
||||
base.WriteTo(op);
|
||||
|
||||
op.Write("\t{0,12:F2} {1,-12:N0}", AverageLength, TotalLength);
|
||||
}
|
||||
}
|
||||
|
||||
public class PacketSendProfile : BasePacketProfile
|
||||
public long TotalLength { get; private set; }
|
||||
|
||||
public double AverageLength => (double)TotalLength / Math.Max(Count, 1);
|
||||
|
||||
public void Finish(long length)
|
||||
{
|
||||
private static readonly Dictionary<int, PacketSendProfile> _profiles = new();
|
||||
Finish();
|
||||
|
||||
private long _created;
|
||||
|
||||
public PacketSendProfile(int packetId) : base($"0x{packetId:X2}")
|
||||
{
|
||||
}
|
||||
|
||||
public static IEnumerable<PacketSendProfile> Profiles => _profiles.Values;
|
||||
|
||||
[MethodImpl(MethodImplOptions.Synchronized)]
|
||||
public static PacketSendProfile Acquire(int packetId)
|
||||
{
|
||||
if (!_profiles.TryGetValue(packetId, out var prof))
|
||||
{
|
||||
_profiles.Add(packetId, prof = new PacketSendProfile(packetId));
|
||||
}
|
||||
|
||||
return prof;
|
||||
}
|
||||
|
||||
public void Increment()
|
||||
{
|
||||
Interlocked.Increment(ref _created);
|
||||
}
|
||||
|
||||
public override void WriteTo(TextWriter op)
|
||||
{
|
||||
base.WriteTo(op);
|
||||
|
||||
op.Write("\t{0,12:N0}", _created);
|
||||
}
|
||||
TotalLength += length;
|
||||
}
|
||||
|
||||
public class PacketReceiveProfile : BasePacketProfile
|
||||
public override void WriteTo(TextWriter op)
|
||||
{
|
||||
private static readonly Dictionary<int, PacketReceiveProfile>
|
||||
_profiles = new();
|
||||
base.WriteTo(op);
|
||||
|
||||
public PacketReceiveProfile(int packetId) : base($"0x{packetId:X2}")
|
||||
{
|
||||
}
|
||||
|
||||
public static IEnumerable<PacketReceiveProfile> Profiles => _profiles.Values;
|
||||
|
||||
[MethodImpl(MethodImplOptions.Synchronized)]
|
||||
public static PacketReceiveProfile Acquire(int packetId)
|
||||
{
|
||||
if (!_profiles.TryGetValue(packetId, out var prof))
|
||||
{
|
||||
_profiles.Add(packetId, prof = new PacketReceiveProfile(packetId));
|
||||
}
|
||||
|
||||
return prof;
|
||||
}
|
||||
op.Write("\t{0,12:F2} {1,-12:N0}", AverageLength, TotalLength);
|
||||
}
|
||||
}
|
||||
|
||||
public class PacketSendProfile : BasePacketProfile
|
||||
{
|
||||
private static readonly Dictionary<int, PacketSendProfile> _profiles = new();
|
||||
|
||||
private long _created;
|
||||
|
||||
public PacketSendProfile(int packetId) : base($"0x{packetId:X2}")
|
||||
{
|
||||
}
|
||||
|
||||
public static IEnumerable<PacketSendProfile> Profiles => _profiles.Values;
|
||||
|
||||
[MethodImpl(MethodImplOptions.Synchronized)]
|
||||
public static PacketSendProfile Acquire(int packetId)
|
||||
{
|
||||
if (!_profiles.TryGetValue(packetId, out var prof))
|
||||
{
|
||||
_profiles.Add(packetId, prof = new PacketSendProfile(packetId));
|
||||
}
|
||||
|
||||
return prof;
|
||||
}
|
||||
|
||||
public void Increment()
|
||||
{
|
||||
Interlocked.Increment(ref _created);
|
||||
}
|
||||
|
||||
public override void WriteTo(TextWriter op)
|
||||
{
|
||||
base.WriteTo(op);
|
||||
|
||||
op.Write("\t{0,12:N0}", _created);
|
||||
}
|
||||
}
|
||||
|
||||
public class PacketReceiveProfile : BasePacketProfile
|
||||
{
|
||||
private static readonly Dictionary<int, PacketReceiveProfile>
|
||||
_profiles = new();
|
||||
|
||||
public PacketReceiveProfile(int packetId) : base($"0x{packetId:X2}")
|
||||
{
|
||||
}
|
||||
|
||||
public static IEnumerable<PacketReceiveProfile> Profiles => _profiles.Values;
|
||||
|
||||
[MethodImpl(MethodImplOptions.Synchronized)]
|
||||
public static PacketReceiveProfile Acquire(int packetId)
|
||||
{
|
||||
if (!_profiles.TryGetValue(packetId, out var prof))
|
||||
{
|
||||
_profiles.Add(packetId, prof = new PacketReceiveProfile(packetId));
|
||||
}
|
||||
|
||||
return prof;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,32 +1,31 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Server.Diagnostics
|
||||
namespace Server.Diagnostics;
|
||||
|
||||
public class TargetProfile : BaseProfile
|
||||
{
|
||||
public class TargetProfile : BaseProfile
|
||||
private static readonly Dictionary<Type, TargetProfile> _profiles = new();
|
||||
|
||||
public TargetProfile(Type type)
|
||||
: base(type.FullName)
|
||||
{
|
||||
private static readonly Dictionary<Type, TargetProfile> _profiles = new();
|
||||
}
|
||||
|
||||
public TargetProfile(Type type)
|
||||
: base(type.FullName)
|
||||
public static IEnumerable<TargetProfile> Profiles => _profiles.Values;
|
||||
|
||||
public static TargetProfile Acquire(Type type)
|
||||
{
|
||||
if (!Core.Profiling)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public static IEnumerable<TargetProfile> Profiles => _profiles.Values;
|
||||
|
||||
public static TargetProfile Acquire(Type type)
|
||||
if (!_profiles.TryGetValue(type, out var prof))
|
||||
{
|
||||
if (!Core.Profiling)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!_profiles.TryGetValue(type, out var prof))
|
||||
{
|
||||
_profiles.Add(type, prof = new TargetProfile(type));
|
||||
}
|
||||
|
||||
return prof;
|
||||
_profiles.Add(type, prof = new TargetProfile(type));
|
||||
}
|
||||
|
||||
return prof;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,45 +1,44 @@
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace Server.Diagnostics
|
||||
namespace Server.Diagnostics;
|
||||
|
||||
public class TimerProfile : BaseProfile
|
||||
{
|
||||
public class TimerProfile : BaseProfile
|
||||
private static readonly Dictionary<string, TimerProfile> _profiles = new();
|
||||
|
||||
public TimerProfile(string name)
|
||||
: base(name)
|
||||
{
|
||||
private static readonly Dictionary<string, TimerProfile> _profiles = new();
|
||||
}
|
||||
|
||||
public TimerProfile(string name)
|
||||
: base(name)
|
||||
public static IEnumerable<TimerProfile> Profiles => _profiles.Values;
|
||||
|
||||
public long Created { get; set; }
|
||||
|
||||
public long Started { get; set; }
|
||||
|
||||
public long Stopped { get; set; }
|
||||
|
||||
public static TimerProfile Acquire(string name)
|
||||
{
|
||||
if (!Core.Profiling)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public static IEnumerable<TimerProfile> Profiles => _profiles.Values;
|
||||
|
||||
public long Created { get; set; }
|
||||
|
||||
public long Started { get; set; }
|
||||
|
||||
public long Stopped { get; set; }
|
||||
|
||||
public static TimerProfile Acquire(string name)
|
||||
if (!_profiles.TryGetValue(name, out var prof))
|
||||
{
|
||||
if (!Core.Profiling)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!_profiles.TryGetValue(name, out var prof))
|
||||
{
|
||||
_profiles.Add(name, prof = new TimerProfile(name));
|
||||
}
|
||||
|
||||
return prof;
|
||||
_profiles.Add(name, prof = new TimerProfile(name));
|
||||
}
|
||||
|
||||
public override void WriteTo(TextWriter op)
|
||||
{
|
||||
base.WriteTo(op);
|
||||
return prof;
|
||||
}
|
||||
|
||||
op.Write("\t{0,12:N0} {1,12:N0} {2,-12:N0}", Created, Started, Stopped);
|
||||
}
|
||||
public override void WriteTo(TextWriter op)
|
||||
{
|
||||
base.WriteTo(op);
|
||||
|
||||
op.Write("\t{0,12:N0} {1,12:N0} {2,-12:N0}", Created, Started, Stopped);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue