restructured and extended performance diagnostics to cover gump and target responses

This commit is contained in:
krrios 2007-04-22 06:08:45 +00:00
parent a8d3bcbec9
commit 5c64b1754c
12 changed files with 569 additions and 401 deletions

View file

@ -26,6 +26,7 @@ using System.Net;
using System.Net.Sockets;
using Server;
using Server.Network;
using Server.Diagnostics;
namespace Server.Network
{
@ -221,8 +222,11 @@ namespace Server.Network
return false;
}
PacketProfile profile = PacketProfile.GetIncomingProfile( packetID );
DateTime start = ( profile == null ? DateTime.MinValue : DateTime.Now );
PacketReceiveProfile prof = PacketReceiveProfile.Acquire( packetID );
if ( prof != null ) {
prof.Start();
}
byte[] packetBuffer;
@ -241,8 +245,9 @@ namespace Server.Network
if ( BufferSize >= packetLength )
m_Buffers.ReleaseBuffer( packetBuffer );
if ( profile != null )
profile.Record( packetLength, DateTime.Now - start );
if ( prof != null ) {
prof.Finish( packetLength );
}
}
}
else

View file

@ -32,6 +32,7 @@ using Server.Items;
using Server.Gumps;
using Server.Menus;
using Server.HuePickers;
using Server.Diagnostics;
namespace Server.Network {
public interface IPacketEncoder {
@ -534,8 +535,7 @@ namespace Server.Network {
return;
}
PacketProfile prof = PacketProfile.GetOutgoingProfile( ( byte ) p.PacketID );
DateTime start = ( prof == null ? DateTime.MinValue : DateTime.Now );
PacketSendProfile prof = PacketSendProfile.Acquire( p.GetType() );
int length;
byte[] buffer = p.Compile( m_CompressionEnabled, out length );
@ -546,6 +546,10 @@ namespace Server.Network {
return;
}
if ( prof != null ) {
prof.Start();
}
if ( m_Encoder != null ) {
m_Encoder.EncodeOutgoingPacket( this, ref buffer, ref length );
}
@ -572,7 +576,7 @@ namespace Server.Network {
p.OnSend();
if ( prof != null ) {
prof.Record( length, DateTime.Now - start );
prof.Finish( length );
}
} else {
Console.WriteLine( "Client: {0}: null buffer send, disconnecting...", this );

View file

@ -34,6 +34,7 @@ using Server.Movement;
using Server.Prompts;
using Server.HuePickers;
using Server.ContextMenus;
using Server.Diagnostics;
using CV = Server.ClientVersion;
namespace Server.Network
@ -1010,69 +1011,81 @@ namespace Server.Network
if ( t != null )
{
if ( x == -1 && y == -1 && !serial.IsValid )
{
// User pressed escape
t.Cancel( from, TargetCancelType.Canceled );
TargetProfile prof = TargetProfile.Acquire( t.GetType() );
if ( prof != null ) {
prof.Start();
}
else
{
object toTarget;
if ( type == 1 )
try {
if ( x == -1 && y == -1 && !serial.IsValid )
{
if ( graphic == 0 )
{
toTarget = new LandTarget( new Point3D( x, y, z ), from.Map );
}
else
{
Map map = from.Map;
// User pressed escape
t.Cancel( from, TargetCancelType.Canceled );
}
else
{
object toTarget;
if ( map == null || map == Map.Internal )
if ( type == 1 )
{
if ( graphic == 0 )
{
t.Cancel( from, TargetCancelType.Canceled );
return;
toTarget = new LandTarget( new Point3D( x, y, z ), from.Map );
}
else
{
Tile[] tiles = map.Tiles.GetStaticTiles( x, y, !t.DisallowMultis );
Map map = from.Map;
bool valid = false;
for ( int i = 0; !valid && i < tiles.Length; ++i )
{
if ( tiles[i].Z == z && (tiles[i].ID & 0x3FFF) == (graphic & 0x3FFF) )
valid = true;
}
if ( !valid )
if ( map == null || map == Map.Internal )
{
t.Cancel( from, TargetCancelType.Canceled );
return;
}
else
{
toTarget = new StaticTarget( new Point3D( x, y, z ), graphic );
Tile[] tiles = map.Tiles.GetStaticTiles( x, y, !t.DisallowMultis );
bool valid = false;
for ( int i = 0; !valid && i < tiles.Length; ++i )
{
if ( tiles[i].Z == z && (tiles[i].ID & 0x3FFF) == (graphic & 0x3FFF) )
valid = true;
}
if ( !valid )
{
t.Cancel( from, TargetCancelType.Canceled );
return;
}
else
{
toTarget = new StaticTarget( new Point3D( x, y, z ), graphic );
}
}
}
}
}
else if ( serial.IsMobile )
{
toTarget = World.FindMobile( serial );
}
else if ( serial.IsItem )
{
toTarget = World.FindItem( serial );
}
else
{
t.Cancel( from, TargetCancelType.Canceled );
return;
}
else if ( serial.IsMobile )
{
toTarget = World.FindMobile( serial );
}
else if ( serial.IsItem )
{
toTarget = World.FindItem( serial );
}
else
{
t.Cancel( from, TargetCancelType.Canceled );
return;
}
t.Invoke( from, toTarget );
t.Invoke( from, toTarget );
}
} finally {
if ( prof != null ) {
prof.Finish();
}
}
}
}
@ -1123,8 +1136,18 @@ namespace Server.Network
state.RemoveGump( gump );
GumpProfile prof = GumpProfile.Acquire( gump.GetType() );
if ( prof != null ) {
prof.Start();
}
gump.OnResponse( state, new RelayInfo( buttonID, switches, textEntries ) );
if ( prof != null ) {
prof.Finish();
}
return;
}
}

View file

@ -1,159 +0,0 @@
/***************************************************************************
* PacketProfile.cs
* -------------------
* begin : May 1, 2002
* copyright : (C) The RunUO Software Team
* email : info@runuo.com
*
* $Id$
*
***************************************************************************/
/***************************************************************************
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
***************************************************************************/
using System;
namespace Server.Network
{
public class PacketProfile
{
private int m_Constructed;
private int m_Count;
private int m_TotalByteLength;
private TimeSpan m_TotalProcTime;
private TimeSpan m_PeakProcTime;
private bool m_Outgoing;
[CommandProperty( AccessLevel.Administrator )]
public bool Outgoing
{
get{ return m_Outgoing; }
}
[CommandProperty( AccessLevel.Administrator )]
public int Constructed
{
get{ return m_Constructed; }
}
[CommandProperty( AccessLevel.Administrator )]
public int TotalByteLength
{
get{ return m_TotalByteLength; }
}
[CommandProperty( AccessLevel.Administrator )]
public TimeSpan TotalProcTime
{
get{ return m_TotalProcTime; }
}
[CommandProperty( AccessLevel.Administrator )]
public TimeSpan PeakProcTime
{
get{ return m_PeakProcTime; }
}
[CommandProperty( AccessLevel.Administrator )]
public int Count
{
get{ return m_Count; }
}
[CommandProperty( AccessLevel.Administrator )]
public double AverageByteLength
{
get
{
if ( m_Count == 0 )
return 0;
return Math.Round( (double) m_TotalByteLength / m_Count, 2 );
}
}
[CommandProperty( AccessLevel.Administrator )]
public TimeSpan AverageProcTime
{
get
{
if ( m_Count == 0 )
return TimeSpan.Zero;
return TimeSpan.FromTicks( m_TotalProcTime.Ticks / m_Count );
}
}
public void Record( int byteLength, TimeSpan processTime )
{
++m_Count;
m_TotalByteLength += byteLength;
m_TotalProcTime += processTime;
if ( processTime > m_PeakProcTime )
m_PeakProcTime = processTime;
}
public void RegConstruct()
{
++m_Constructed;
}
public PacketProfile( bool outgoing )
{
m_Outgoing = outgoing;
}
private static PacketProfile[] m_OutgoingProfiles;
private static PacketProfile[] m_IncomingProfiles;
public static PacketProfile GetOutgoingProfile( int packetID )
{
if ( !Core.Profiling )
return null;
PacketProfile prof = m_OutgoingProfiles[packetID];
if ( prof == null )
m_OutgoingProfiles[packetID] = prof = new PacketProfile( true );
return prof;
}
public static PacketProfile GetIncomingProfile( int packetID )
{
if ( !Core.Profiling )
return null;
PacketProfile prof = m_IncomingProfiles[packetID];
if ( prof == null )
m_IncomingProfiles[packetID] = prof = new PacketProfile( false );
return prof;
}
public static PacketProfile[] OutgoingProfiles
{
get{ return m_OutgoingProfiles; }
}
public static PacketProfile[] IncomingProfiles
{
get{ return m_IncomingProfiles; }
}
static PacketProfile()
{
m_OutgoingProfiles = new PacketProfile[0x100];
m_IncomingProfiles = new PacketProfile[0x100];
}
}
}

View file

@ -34,6 +34,7 @@ using Server.Menus.Questions;
using Server.Prompts;
using Server.HuePickers;
using Server.ContextMenus;
using Server.Diagnostics;
namespace Server.Network
{
@ -3460,10 +3461,11 @@ namespace Server.Network
{
m_PacketID = packetID;
PacketProfile prof = PacketProfile.GetOutgoingProfile( (byte)packetID );
PacketSendProfile prof = PacketSendProfile.Acquire( GetType() );
if ( prof != null )
prof.RegConstruct();
if ( prof != null ) {
prof.Created++;
}
}
public void EnsureCapacity( int length )
@ -3479,12 +3481,13 @@ namespace Server.Network
m_Length = length;
m_Stream = PacketWriter.CreateInstance( length );// new PacketWriter( length );
m_Stream.Write( (byte) packetID );
m_Stream.Write( ( byte ) packetID );
PacketProfile prof = PacketProfile.GetOutgoingProfile( (byte)packetID );
PacketSendProfile prof = PacketSendProfile.Acquire( GetType() );
if ( prof != null )
prof.RegConstruct();
if ( prof != null ) {
prof.Created++;
}
}
public PacketWriter UnderlyingStream