Skip to content
Permalink
Browse files

Log execution time of tasks in /taskdebug, use actual methods instead…

… of delegates for some tasks for more cleaner list in /taskdebug
  • Loading branch information...
UnknownShadow200 committed Dec 24, 2017
1 parent ee20a6d commit 35f5c620a8f8029eaf3e6aad6e4dcae3599a6695
Showing with 16 additions and 11 deletions.
  1. +2 −1 fCraft/Portals/PortalDB.cs
  2. +2 −6 fCraft/System/Scheduler.cs
  3. +7 −3 fCraft/System/SchedulerTask.cs
  4. +5 −1 fCraft/System/Server.cs
@@ -94,8 +94,9 @@ public class PortalDB {
}
}

static void SaveCallback( SchedulerTask task ) { Save(); }
public static void StartSaveTask() {
SchedulerTask saveTask = Scheduler.NewBackgroundTask(delegate { Save(); }).RunForever(SaveInterval, SaveInterval + TimeSpan.FromSeconds(15));
Scheduler.NewBackgroundTask( SaveCallback ).RunForever(SaveInterval, SaveInterval + TimeSpan.FromSeconds(15));
}
}
}
@@ -69,8 +69,8 @@ public static class Scheduler {
}
} else {
task.IsExecuting = true;
#if DEBUG_SCHEDULER
task.ExecuteStart = DateTime.UtcNow;
#if DEBUG_SCHEDULER
FireEvent( TaskExecuting, task );
#endif

@@ -87,8 +87,8 @@ public static class Scheduler {
}
#endif

#if DEBUG_SCHEDULER
task.ExecuteEnd = DateTime.UtcNow;
#if DEBUG_SCHEDULER
FireEvent( TaskExecuted, task );
#endif
}
@@ -289,10 +289,6 @@ public static class Scheduler {
lock( TaskListLock ) {
foreach( SchedulerTask task in Tasks ) {
player.Message( task.ToString() );
#if DEBUG_SCHEDULER
TimeSpan delta = task.ExecuteEnd - task.ExecuteStart;
player.Message( " Exceution time: {0} milliseconds", delta.TotalMilliseconds);
#endif
}
}
}
@@ -79,9 +79,9 @@ internal SchedulerTask( [NotNull] SchedulerCallback callback, bool isBackground,
/// can be used for anything you want. </summary>
public object UserState { get; set; }

#if DEBUG_SCHEDULER
public DateTime ExecuteStart, ExecuteEnd;
#endif


#region Run Once

/// <summary> Runs the task once, as quickly as possible.
@@ -263,7 +263,11 @@ internal SchedulerTask( [NotNull] SchedulerCallback callback, bool isBackground,
sb.Append( " -> " );
sb.Append( UserState );
}
sb.Append( ')' );

sb.Append( ") - (took " );
TimeSpan delta = ExecuteEnd - ExecuteStart;
sb.Append( delta.TotalMilliseconds );
sb.Append( " ms)" );
return sb.ToString();
}
}
@@ -420,7 +420,7 @@ public static partial class Server {
Scheduler.NewTask( ShowRandomAnnouncement ).RunForever( announcementInterval );
}
if (ConfigKey.IRCBotEnabled.Enabled() || ConfigKey.IRCBotChannels.GetString().Length >= 1 || ConfigKey.IRCBotNetwork.GetString().Length >= 1) {
Scheduler.NewTask(t => IRC.SendRawMessage(IRCCommands.Ping(ConfigKey.IRCBotChannels.GetString()), "", "")).RunForever(TimeSpan.FromMinutes(15));
Scheduler.NewTask( SendIrcPing ).RunForever( TimeSpan.FromMinutes( 15 ) );
}

ChatTimer.LoadAll();
@@ -1003,7 +1003,11 @@ static void CheckIdles(SchedulerTask task)
oldCPUTime = newCPUTime;
IsMonitoringCPUUsage = true;
}


static void SendIrcPing( SchedulerTask task ) {
IRC.SendRawMessage(IRCCommands.Ping(ConfigKey.IRCBotChannels.GetString()), "", "");
}
#endregion


0 comments on commit 35f5c62

Please sign in to comment.
You can’t perform that action at this time.