Skip to content

Commit

Permalink
Make scheduler dumps best-effort (#10642)
Browse files Browse the repository at this point in the history
Swallow any noncritical exception on the MSBUILDDEBUGSCHEDULER codepath.

Avoids problems like #10628.
  • Loading branch information
rainersigwald authored Sep 11, 2024
1 parent db5b3ef commit 227d6c1
Showing 1 changed file with 34 additions and 10 deletions.
44 changes: 34 additions & 10 deletions src/Build/BackEnd/Components/Scheduler/Scheduler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2565,13 +2565,19 @@ private void TraceScheduler(string format, params object[] stuff)
{
if (_debugDumpState)
{
FileUtilities.EnsureDirectoryExists(_debugDumpPath);
try
{
FileUtilities.EnsureDirectoryExists(_debugDumpPath);

StreamWriter file = FileUtilities.OpenWrite(String.Format(CultureInfo.CurrentCulture, Path.Combine(_debugDumpPath, "SchedulerTrace_{0}.txt"), Process.GetCurrentProcess().Id), append: true);
file.Write("{0}({1})-{2}: ", Thread.CurrentThread.Name, Thread.CurrentThread.ManagedThreadId, _schedulingData.EventTime.Ticks);
file.WriteLine(format, stuff);
file.Flush();
file.Dispose();
using StreamWriter file = FileUtilities.OpenWrite(String.Format(CultureInfo.CurrentCulture, Path.Combine(_debugDumpPath, "SchedulerTrace_{0}.txt"), Process.GetCurrentProcess().Id), append: true);
file.Write("{0}({1})-{2}: ", Thread.CurrentThread.Name, Thread.CurrentThread.ManagedThreadId, _schedulingData.EventTime.Ticks);
file.WriteLine(format, stuff);
file.Flush();
}
catch (Exception e) when (!ExceptionHandling.IsCriticalException(e))
{
// Ignore exceptions
}
}
}

Expand All @@ -2584,9 +2590,11 @@ private void DumpSchedulerState()
{
if (_schedulingData != null)
{
FileUtilities.EnsureDirectoryExists(_debugDumpPath);
using (StreamWriter file = FileUtilities.OpenWrite(String.Format(CultureInfo.CurrentCulture, Path.Combine(_debugDumpPath, "SchedulerState_{0}.txt"), Process.GetCurrentProcess().Id), append: true))
try
{
FileUtilities.EnsureDirectoryExists(_debugDumpPath);
using StreamWriter file = FileUtilities.OpenWrite(String.Format(CultureInfo.CurrentCulture, Path.Combine(_debugDumpPath, "SchedulerState_{0}.txt"), Process.GetCurrentProcess().Id), append: true);

file.WriteLine("Scheduler state at timestamp {0}:", _schedulingData.EventTime.Ticks);
file.WriteLine("------------------------------------------------");

Expand Down Expand Up @@ -2680,6 +2688,10 @@ private void DumpSchedulerState()

file.WriteLine();
}
catch (Exception e) when (!ExceptionHandling.IsCriticalException(e))
{
// Ignore exceptions
}
}
}
}
Expand All @@ -2693,8 +2705,10 @@ private void DumpConfigurations()
{
if (_schedulingData != null)
{
using (StreamWriter file = FileUtilities.OpenWrite(String.Format(CultureInfo.CurrentCulture, Path.Combine(_debugDumpPath, "SchedulerState_{0}.txt"), Process.GetCurrentProcess().Id), append: true))
try
{
using StreamWriter file = FileUtilities.OpenWrite(String.Format(CultureInfo.CurrentCulture, Path.Combine(_debugDumpPath, "SchedulerState_{0}.txt"), Process.GetCurrentProcess().Id), append: true);

file.WriteLine("Configurations used during this build");
file.WriteLine("-------------------------------------");

Expand All @@ -2714,6 +2728,10 @@ private void DumpConfigurations()

file.Flush();
}
catch (Exception e) when (!ExceptionHandling.IsCriticalException(e))
{
// Ignore exceptions
}
}
}
}
Expand All @@ -2727,14 +2745,20 @@ private void DumpRequests()
{
if (_schedulingData != null)
{
using (StreamWriter file = FileUtilities.OpenWrite(String.Format(CultureInfo.CurrentCulture, Path.Combine(_debugDumpPath, "SchedulerState_{0}.txt"), Process.GetCurrentProcess().Id), append: true))
try
{
using StreamWriter file = FileUtilities.OpenWrite(String.Format(CultureInfo.CurrentCulture, Path.Combine(_debugDumpPath, "SchedulerState_{0}.txt"), Process.GetCurrentProcess().Id), append: true);

file.WriteLine("Requests used during the build:");
file.WriteLine("-------------------------------");
file.WriteLine("Format: GlobalRequestId: [NodeId] FinalState (ConfigId) Path (Targets)");
DumpRequestHierarchy(file, null, 0);
file.Flush();
}
catch (Exception e) when (!ExceptionHandling.IsCriticalException(e))
{
// Ignore exceptions
}
}
}
}
Expand Down

0 comments on commit 227d6c1

Please sign in to comment.