Changes properties to use automatic property initializers

This commit is contained in:
Kamron Batman 2018-09-14 15:23:29 -07:00
parent f0a48ad431
commit 06fa31a7bf
623 changed files with 13072 additions and 19304 deletions

View file

@ -38,27 +38,20 @@ namespace Server.Diagnostics {
}
}
private string _name;
private long _count;
private TimeSpan _totalTime;
private TimeSpan _peakTime;
private Stopwatch _stopwatch;
public string Name => _name;
public string Name { get; }
public long Count => _count;
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 => _peakTime;
public TimeSpan PeakTime { get; private set; }
public TimeSpan TotalTime => _totalTime;
public TimeSpan TotalTime { get; private set; }
protected BaseProfile( string name ) {
_name = name;
Name = name;
_stopwatch = new Stopwatch();
}
@ -74,13 +67,13 @@ namespace Server.Diagnostics {
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();
}

View file

@ -26,11 +26,9 @@ using System.IO;
namespace Server.Diagnostics {
public abstract class BasePacketProfile : BaseProfile {
private long _totalLength;
public long TotalLength { get; private set; }
public long TotalLength => _totalLength;
public double AverageLength => ( double ) _totalLength / Math.Max( 1, Count );
public double AverageLength => ( double ) TotalLength / Math.Max( 1, Count );
protected BasePacketProfile(string name)
: base( name ) {
@ -39,7 +37,7 @@ namespace Server.Diagnostics {
public void Finish( int length ) {
Finish();
_totalLength += length;
TotalLength += length;
}
public override void WriteTo( TextWriter op ) {

View file

@ -41,22 +41,11 @@ namespace Server.Diagnostics {
return prof;
}
private long _created, _started, _stopped;
public long Created { get; set; }
public long Created {
get => _created;
set => _created = value;
}
public long Started { get; set; }
public long Started {
get => _started;
set => _started = value;
}
public long Stopped {
get => _stopped;
set => _stopped = value;
}
public long Stopped { get; set; }
public TimerProfile( string name )
: base( name ) {
@ -65,7 +54,7 @@ namespace Server.Diagnostics {
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 );
}
}
}