Fixes code according to modern code style. Fixes a few expression bugs.

This commit is contained in:
Kamron Batman 2018-09-15 09:58:51 -07:00
parent 89eea25e5f
commit 970fd563b2
3324 changed files with 441118 additions and 433755 deletions

View file

@ -19,67 +19,70 @@
***************************************************************************/
using System;
using System.IO;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
namespace Server.Diagnostics {
public abstract class BaseProfile {
public static void WriteAll<T>( TextWriter op, IEnumerable<T> profiles ) where T : BaseProfile {
List<T> list = new List<T>( profiles );
namespace Server.Diagnostics
{
public abstract class BaseProfile
{
private Stopwatch _stopwatch;
list.Sort( delegate( T a, T b ) {
return -a.TotalTime.CompareTo( b.TotalTime );
} );
protected BaseProfile(string name)
{
Name = name;
foreach ( T prof in list ) {
prof.WriteTo( op );
op.WriteLine();
}
}
_stopwatch = new Stopwatch();
}
private Stopwatch _stopwatch;
public string Name{ get; }
public string Name { get; }
public long Count{ get; private set; }
public long Count { get; private set; }
public TimeSpan AverageTime => TimeSpan.FromTicks(TotalTime.Ticks / Math.Max(1, Count));
public TimeSpan AverageTime => TimeSpan.FromTicks( TotalTime.Ticks / Math.Max( 1, Count ) );
public TimeSpan PeakTime{ get; private set; }
public TimeSpan PeakTime { get; private set; }
public TimeSpan TotalTime{ get; private set; }
public TimeSpan TotalTime { get; private set; }
public static void WriteAll<T>(TextWriter op, IEnumerable<T> profiles) where T : BaseProfile
{
List<T> list = new List<T>(profiles);
protected BaseProfile( string name ) {
Name = name;
list.Sort(delegate(T a, T b) { return -a.TotalTime.CompareTo(b.TotalTime); });
_stopwatch = new Stopwatch();
}
foreach (T prof in list)
{
prof.WriteTo(op);
op.WriteLine();
}
}
public virtual void Start() {
if ( _stopwatch.IsRunning ) {
_stopwatch.Reset();
}
public virtual void Start()
{
if (_stopwatch.IsRunning) _stopwatch.Reset();
_stopwatch.Start();
}
_stopwatch.Start();
}
public virtual void Finish() {
TimeSpan elapsed = _stopwatch.Elapsed;
public virtual void Finish()
{
TimeSpan elapsed = _stopwatch.Elapsed;
TotalTime += elapsed;
TotalTime += elapsed;
if ( elapsed > PeakTime ) {
PeakTime = elapsed;
}
if (elapsed > PeakTime) PeakTime = elapsed;
Count++;
Count++;
_stopwatch.Reset();
}
_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 );
}
}
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);
}
}
}

View file

@ -21,28 +21,28 @@
using System;
using System.Collections.Generic;
namespace Server.Diagnostics {
public class GumpProfile : BaseProfile {
private static Dictionary<Type, GumpProfile> _profiles = new Dictionary<Type, GumpProfile>();
namespace Server.Diagnostics
{
public class GumpProfile : BaseProfile
{
private static Dictionary<Type, GumpProfile> _profiles = new Dictionary<Type, GumpProfile>();
public static IEnumerable<GumpProfile> Profiles => _profiles.Values;
public GumpProfile(Type type)
: base(type.FullName)
{
}
public static GumpProfile Acquire( Type type ) {
if ( !Core.Profiling ) {
return null;
}
public static IEnumerable<GumpProfile> Profiles => _profiles.Values;
GumpProfile prof;
public static GumpProfile Acquire(Type type)
{
if (!Core.Profiling) return null;
if ( !_profiles.TryGetValue( type, out prof ) ) {
_profiles.Add( type, prof = new GumpProfile( type ) );
}
GumpProfile prof;
return prof;
}
if (!_profiles.TryGetValue(type, out prof)) _profiles.Add(type, prof = new GumpProfile(type));
public GumpProfile( Type type )
: base( type.FullName ) {
}
}
return prof;
}
}
}

View file

@ -20,84 +20,94 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.CompilerServices;
using System.Threading;
using System.IO;
namespace Server.Diagnostics {
public abstract class BasePacketProfile : BaseProfile {
public long TotalLength { get; private set; }
namespace Server.Diagnostics
{
public abstract class BasePacketProfile : BaseProfile
{
protected BasePacketProfile(string name)
: base(name)
{
}
public double AverageLength => ( double ) TotalLength / Math.Max( 1, Count );
public long TotalLength{ get; private set; }
protected BasePacketProfile(string name)
: base( name ) {
}
public double AverageLength => (double)TotalLength / Math.Max(1, Count);
public void Finish( int length ) {
Finish();
public void Finish(int length)
{
Finish();
TotalLength += length;
}
TotalLength += length;
}
public override void WriteTo( TextWriter op ) {
base.WriteTo( op );
public override void WriteTo(TextWriter op)
{
base.WriteTo(op);
op.Write( "\t{0,12:F2} {1,-12:N0}", AverageLength, TotalLength );
}
}
op.Write("\t{0,12:F2} {1,-12:N0}", AverageLength, TotalLength);
}
}
public class PacketSendProfile : BasePacketProfile {
private static Dictionary<Type, PacketSendProfile> _profiles = new Dictionary<Type, PacketSendProfile>();
public class PacketSendProfile : BasePacketProfile
{
private static Dictionary<Type, PacketSendProfile> _profiles = new Dictionary<Type, PacketSendProfile>();
public static IEnumerable<PacketSendProfile> Profiles => _profiles.Values;
private long _created;
[MethodImpl(MethodImplOptions.Synchronized)]
public static PacketSendProfile Acquire( Type type ) {
PacketSendProfile prof;
public PacketSendProfile(Type type)
: base(type.FullName)
{
}
if ( !_profiles.TryGetValue( type, out prof ) ) {
_profiles.Add( type, prof = new PacketSendProfile( type ) );
}
public static IEnumerable<PacketSendProfile> Profiles => _profiles.Values;
return prof;
}
[MethodImpl(MethodImplOptions.Synchronized)]
public static PacketSendProfile Acquire(Type type)
{
PacketSendProfile prof;
private long _created;
if (!_profiles.TryGetValue(type, out prof)) _profiles.Add(type, prof = new PacketSendProfile(type));
public void Increment() {
Interlocked.Increment(ref _created);
}
return prof;
}
public PacketSendProfile( Type type )
: base( type.FullName ) {
}
public void Increment()
{
Interlocked.Increment(ref _created);
}
public override void WriteTo( TextWriter op ) {
base.WriteTo( op );
public override void WriteTo(TextWriter op)
{
base.WriteTo(op);
op.Write( "\t{0,12:N0}", _created );
}
}
op.Write("\t{0,12:N0}", _created);
}
}
public class PacketReceiveProfile : BasePacketProfile {
private static Dictionary<int, PacketReceiveProfile> _profiles = new Dictionary<int, PacketReceiveProfile>();
public class PacketReceiveProfile : BasePacketProfile
{
private static Dictionary<int, PacketReceiveProfile> _profiles = new Dictionary<int, PacketReceiveProfile>();
public static IEnumerable<PacketReceiveProfile> Profiles => _profiles.Values;
public PacketReceiveProfile(int packetId)
: base($"0x{packetId:X2}")
{
}
[MethodImpl(MethodImplOptions.Synchronized)]
public static PacketReceiveProfile Acquire( int packetId ) {
PacketReceiveProfile prof;
public static IEnumerable<PacketReceiveProfile> Profiles => _profiles.Values;
if ( !_profiles.TryGetValue( packetId, out prof ) ) {
_profiles.Add( packetId, prof = new PacketReceiveProfile( packetId ) );
}
[MethodImpl(MethodImplOptions.Synchronized)]
public static PacketReceiveProfile Acquire(int packetId)
{
PacketReceiveProfile prof;
return prof;
}
if (!_profiles.TryGetValue(packetId, out prof))
_profiles.Add(packetId, prof = new PacketReceiveProfile(packetId));
public PacketReceiveProfile( int packetId )
: base($"0x{packetId:X2}") {
}
}
return prof;
}
}
}

View file

@ -21,28 +21,28 @@
using System;
using System.Collections.Generic;
namespace Server.Diagnostics {
public class TargetProfile : BaseProfile {
private static Dictionary<Type, TargetProfile> _profiles = new Dictionary<Type, TargetProfile>();
namespace Server.Diagnostics
{
public class TargetProfile : BaseProfile
{
private static Dictionary<Type, TargetProfile> _profiles = new Dictionary<Type, TargetProfile>();
public static IEnumerable<TargetProfile> Profiles => _profiles.Values;
public TargetProfile(Type type)
: base(type.FullName)
{
}
public static TargetProfile Acquire( Type type ) {
if ( !Core.Profiling ) {
return null;
}
public static IEnumerable<TargetProfile> Profiles => _profiles.Values;
TargetProfile prof;
public static TargetProfile Acquire(Type type)
{
if (!Core.Profiling) return null;
if ( !_profiles.TryGetValue( type, out prof ) ) {
_profiles.Add( type, prof = new TargetProfile( type ) );
}
TargetProfile prof;
return prof;
}
if (!_profiles.TryGetValue(type, out prof)) _profiles.Add(type, prof = new TargetProfile(type));
public TargetProfile( Type type )
: base( type.FullName ) {
}
}
return prof;
}
}
}

View file

@ -21,40 +21,41 @@
using System.Collections.Generic;
using System.IO;
namespace Server.Diagnostics {
public class TimerProfile : BaseProfile {
private static Dictionary<string, TimerProfile> _profiles = new Dictionary<string, TimerProfile>();
namespace Server.Diagnostics
{
public class TimerProfile : BaseProfile
{
private static Dictionary<string, TimerProfile> _profiles = new Dictionary<string, TimerProfile>();
public static IEnumerable<TimerProfile> Profiles => _profiles.Values;
public TimerProfile(string name)
: base(name)
{
}
public static TimerProfile Acquire( string name ) {
if ( !Core.Profiling ) {
return null;
}
public static IEnumerable<TimerProfile> Profiles => _profiles.Values;
TimerProfile prof;
public long Created{ get; set; }
if ( !_profiles.TryGetValue( name, out prof ) ) {
_profiles.Add( name, prof = new TimerProfile( name ) );
}
public long Started{ get; set; }
return prof;
}
public long Stopped{ get; set; }
public long Created { get; set; }
public static TimerProfile Acquire(string name)
{
if (!Core.Profiling) return null;
public long Started { get; set; }
TimerProfile prof;
public long Stopped { get; set; }
if (!_profiles.TryGetValue(name, out prof)) _profiles.Add(name, prof = new TimerProfile(name));
public TimerProfile( string name )
: base( name ) {
}
return prof;
}
public override void WriteTo( TextWriter op ) {
base.WriteTo( op );
public override void WriteTo(TextWriter op)
{
base.WriteTo(op);
op.Write( "\t{0,12:N0} {1,12:N0} {2,-12:N0}", Created, Started, Stopped );
}
}
op.Write("\t{0,12:N0} {1,12:N0} {2,-12:N0}", Created, Started, Stopped);
}
}
}