public ProfileViewer(Mobile from) : base(200, 150) { from.CloseGump(typeof(ProfileViewer)); AddBackground(0, 0, 360, 255, 5054); AddBlackAlpha(10, 10, 340, 235); int y = 10; /* header */ AddLabel(110, y, LabelHue, "Current"); AddLabel(240, y, LabelHue, "Total"); y += 25; /* timer values */ MainProfile current = Core.CurrentProfile; MainProfile total = Core.TotalProfile; TimeSpan currentElapsed = Core.Now - current.Start; TimeSpan totalElapsed = Core.Now - total.Start; for (int i = 0; i < TimerNames.Length; i++, y += 20) { TimeSpan currentValue = current.Timer((MainProfile.TimerId)i); TimeSpan totalValue = total.Timer((MainProfile.TimerId)i); AddLabel(20, y, LabelHue, TimerNames[i] + ":"); AddLabel(110, y, LabelHue, FormatTimeSpan(currentValue)); if (currentElapsed.Ticks > 0) { AddLabel(180, y, LabelHue, String.Format("{0:0.0%}", (double)currentValue.Ticks / (double)currentElapsed.Ticks)); } AddLabel(240, y, LabelHue, FormatTimeSpan(totalValue)); if (totalElapsed.Ticks > 0) { AddLabel(310, y, LabelHue, String.Format("{0:0.0%}", (double)totalValue.Ticks / (double)totalElapsed.Ticks)); } } y += 5; /* iterations and iteration rate */ AddLabel(20, y, LabelHue, "Iterations:"); AddLabel(110, y, LabelHue, current.Iterations.ToString()); AddLabel(240, y, LabelHue, total.Iterations.ToString()); y += 20; AddLabel(20, y, LabelHue, "Rate:"); AddLabel(110, y, LabelHue, FormatRate(current.Iterations, currentElapsed)); AddLabel(240, y, LabelHue, FormatRate(total.Iterations, totalElapsed)); y += 20; /* average sleep */ AddLabel(20, y, LabelHue, "Avg. sleep:"); if (current.Iterations > 0) { AddLabel(110, y, LabelHue, FormatTimeSpan(new TimeSpan(current.Timer(MainProfile.TimerId.Idle).Ticks / (long)current.Iterations))); } if (total.Iterations > 0) { AddLabel(240, y, LabelHue, FormatTimeSpan(new TimeSpan(total.Timer(MainProfile.TimerId.Idle).Ticks / (long)total.Iterations))); } y += 25; /* buttons */ AddButton(50, y, 2152, 2154, 1, GumpButtonType.Reply, 0); AddLabel(85, y + 3, LabelHue, "Refresh"); AddButton(150, y, 2152, 2154, 2, GumpButtonType.Reply, 0); AddLabel(185, y + 3, LabelHue, "Reset"); AddButton(250, y, 2152, 2154, 0, GumpButtonType.Reply, 0); AddLabel(285, y + 3, LabelHue, "Close"); }
private static void Run() { m_Now = DateTime.Now; m_TotalProfile = new MainProfile(m_Now); m_CurrentProfile = new MainProfile(m_Now); while ( !m_Closing ) { m_Now = DateTime.Now; /* wait until event happens */ m_Signal.WaitOne(); ClockProfile(MainProfile.TimerId.Idle); /* process mobiles */ Mobile.ProcessDeltaQueue(); ClockProfile(MainProfile.TimerId.MobileDelta); /* process items */ Item.ProcessDeltaQueue(); ClockProfile(MainProfile.TimerId.ItemDelta); /* process timers */ Timer.Slice(); ClockProfile(MainProfile.TimerId.Timers); /* network */ m_MessagePump.Slice(); NetState.FlushAll(); NetState.ProcessDisposedQueue(); ClockProfile(MainProfile.TimerId.Network); if ( Slice != null ) Slice(); /* done with this iteration */ m_TotalProfile.Next(); m_CurrentProfile.Next(); } }
public static void ResetCurrentProfile() { m_CurrentProfile = new MainProfile(m_Now); }
private static void ClockProfile(MainProfile.TimerId id) { DateTime prev = m_Now; m_Now = DateTime.Now; TimeSpan diff = m_Now - prev; m_TotalProfile.Add(id, diff); m_CurrentProfile.Add(id, diff); }
public static void Run() { EventSink.Instance = new EventSink(); if ( !ScriptCompiler.Compile( Environment.Debug ) ) { Console.WriteLine( "Fatal: Compilation failed. Press any key to exit." ); Console.ReadLine(); return; } ScriptCompiler.VerifyLibraries(); // This instance is shared among timer scheduler and timer executor, // and accessed from both core & timer threads. Queue<Timer> timerQueue = new Queue<Timer>(); // Timer scheduler must be set up before world load, since world load // could schedule timers on entity deserialization. var timerScheduler = TimerScheduler.Instance = new TimerScheduler( timerQueue ); m_TimerThread = new TimerThread( timerScheduler ); TimerExecutor timerExecutor = new TimerExecutor( timerQueue ); PacketHandlers.Instance = new PacketHandlers(); try { ScriptCompiler.Configure(); TileData.Configure(); } catch ( TargetInvocationException e ) { Console.WriteLine( "Fatal: Configure exception: {0}", e.InnerException ); return; } Environment.SaveConfig(); Region.Load(); World.Instance.Load(); try { ScriptCompiler.Initialize(); } catch ( TargetInvocationException e ) { Logger.Error( "Initialize exception: {0}", e.InnerException ); return; } m_TimerThread.Start(); NetServer netServer = new NetServer( new Listener( Listener.Port ) ); netServer.Initialize(); GameServer.Instance = new GameServer( netServer, PacketHandlers.Instance ); GameServer.Instance.Initialize(); EventSink.Instance.InvokeServerStarted(); PacketDispatcher.Initialize(); m_Now = DateTime.UtcNow; m_TotalProfile = new MainProfile( m_Now ); m_CurrentProfile = new MainProfile( m_Now ); try { while ( !m_Closing ) { m_Now = DateTime.UtcNow; Thread.Sleep( 1 ); ClockProfile( MainProfile.TimerId.Idle ); Mobile.ProcessDeltaQueue(); ClockProfile( MainProfile.TimerId.MobileDelta ); Item.ProcessDeltaQueue(); ClockProfile( MainProfile.TimerId.ItemDelta ); timerExecutor.Slice(); ClockProfile( MainProfile.TimerId.Timers ); netServer.Slice(); ClockProfile( MainProfile.TimerId.Network ); // Done with this iteration. m_TotalProfile.Next(); m_CurrentProfile.Next(); } } catch ( Exception e ) { HandleCrashed( e ); } m_TimerThread.Stop(); }