Skip to content
Permalink
Browse files

If DEBUG_SCHEDULER is defined, /taskdebug also outputs how long each …

…task takes to complete
  • Loading branch information...
UnknownShadow200 committed Nov 20, 2017
1 parent 7970334 commit f5004f23782420bb0ff424befb257db27c47efd9
Showing with 20 additions and 7 deletions.
  1. +17 −6 fCraft/System/Scheduler.cs
  2. +3 −1 fCraft/System/SchedulerTask.cs
@@ -18,7 +18,12 @@ public static class Scheduler {
static Thread schedulerThread,
backgroundThread;


#if DEBUG_SCHEDULER
public static event EventHandler<SchedulerTaskEventArgs> TaskAdded;
public static event EventHandler<SchedulerTaskEventArgs> TaskRemoved;
public static event EventHandler<SchedulerTaskEventArgs> TaskExecuted;
public static event EventHandler<SchedulerTaskEventArgs> TaskExecuting;
#endif
public static int CriticalTaskCount {
get {
lock( BackgroundTaskQueueLock ) {
@@ -65,6 +70,7 @@ public static class Scheduler {
} else {
task.IsExecuting = true;
#if DEBUG_SCHEDULER
task.ExecuteStart = DateTime.UtcNow;
FireEvent( TaskExecuting, task );
#endif

@@ -82,6 +88,7 @@ public static class Scheduler {
#endif

#if DEBUG_SCHEDULER
task.ExecuteEnd = DateTime.UtcNow;
FireEvent( TaskExecuted, task );
#endif
}
@@ -130,6 +137,7 @@ public static class Scheduler {
static void ExecuteBackgroundTask( SchedulerTask task ) {
task.IsExecuting = true;
#if DEBUG_SCHEDULER
task.ExecuteStart = DateTime.UtcNow;
FireEvent( TaskExecuting, task );
#endif

@@ -146,6 +154,7 @@ public static class Scheduler {
#endif

#if DEBUG_SCHEDULER
task.ExecuteEnd = DateTime.UtcNow;
FireEvent( TaskExecuted, task );
#endif
}
@@ -162,11 +171,9 @@ public static class Scheduler {
FireEvent( TaskAdded, task );
if( Tasks.Add( task ) ) {
UpdateCache();
Logger.Log( LogType.Debug,
"Scheduler.AddTask: Added {0}", task );
}else{
Logger.Log( LogType.Debug,
"Scheduler.AddTask: Added duplicate {0}", task );
Logger.Log( LogType.Debug, "Scheduler.AddTask: Added {0}", task );
} else {
Logger.Log( LogType.Debug, "Scheduler.AddTask: Added duplicate {0}", task );
}
#else
if( Tasks.Add( task ) ) {
@@ -282,6 +289,10 @@ 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,7 +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.

0 comments on commit f5004f2

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