提交 03f53b4c 编写于 作者: J Jared Parsons 提交者: Jared Parsons

Respond to PR feedback

上级 0e147358
...@@ -55,6 +55,13 @@ function Terminate-BuildProcesses() { ...@@ -55,6 +55,13 @@ function Terminate-BuildProcesses() {
# Ensure that procdump is available on the machine. Returns the path to the directory that contains # Ensure that procdump is available on the machine. Returns the path to the directory that contains
# the procdump binaries (both 32 and 64 bit) # the procdump binaries (both 32 and 64 bit)
function Ensure-ProcDump() { function Ensure-ProcDump() {
# Jenkins images default to having procdump installed in the root. Use that if available to avoid
# an unnecessary download.
if (Test-Path "c:\SysInternals\procdump.exe") {
return "c:\SysInternals";
}
$toolsDir = Join-Path $binariesDir "Tools" $toolsDir = Join-Path $binariesDir "Tools"
$outDir = Join-Path $toolsDir "ProcDump" $outDir = Join-Path $toolsDir "ProcDump"
$filePath = Join-Path $outDir "procdump.exe" $filePath = Join-Path $outDir "procdump.exe"
......
...@@ -124,7 +124,7 @@ private async Task CacheTestResult(ContentFile contentFile, TestResult testResul ...@@ -124,7 +124,7 @@ private async Task CacheTestResult(ContentFile contentFile, TestResult testResul
} }
catch (Exception ex) catch (Exception ex)
{ {
Logger.Log($"Failed to create cached {ex}"); Logger.Log("Failed to create cached", ex);
} }
} }
} }
......
...@@ -80,7 +80,7 @@ public bool TryGetCachedTestResult(string checksum, out CachedTestResult testRes ...@@ -80,7 +80,7 @@ public bool TryGetCachedTestResult(string checksum, out CachedTestResult testRes
catch (Exception e) catch (Exception e)
{ {
// Okay for exception to occur here on I/O // Okay for exception to occur here on I/O
Logger.Log($"Failed to read cache {checksum} {e.Message}"); Logger.Log($"Failed to read cache {checksum}", e);
} }
return false; return false;
...@@ -107,7 +107,7 @@ public Task AddCachedTestResult(AssemblyInfo assemblyInfo, ContentFile contentFi ...@@ -107,7 +107,7 @@ public Task AddCachedTestResult(AssemblyInfo assemblyInfo, ContentFile contentFi
catch (Exception e) catch (Exception e)
{ {
// I/O errors are expected and okay here. // I/O errors are expected and okay here.
Logger.Log($"Failed to log {checksum} {e.Message}"); Logger.Log($"Failed to log {checksum}", e);
FileUtil.DeleteDirectory(storagePath); FileUtil.DeleteDirectory(storagePath);
} }
...@@ -159,7 +159,7 @@ private void CleanupStorage() ...@@ -159,7 +159,7 @@ private void CleanupStorage()
} }
catch (Exception ex) catch (Exception ex)
{ {
Logger.Log($"Unable to cleanup storage {ex.Message}"); Logger.Log("Unable to cleanup storage", ex);
} }
} }
} }
......
...@@ -26,6 +26,25 @@ internal static void LogError(Exception ex, string line) ...@@ -26,6 +26,25 @@ internal static void LogError(Exception ex, string line)
} }
} }
internal static void Log(string message, Exception ex)
{
lock (s_lines)
{
s_lines.Add(message);
s_lines.Add(ex.Message);
s_lines.Add(ex.StackTrace);
}
}
internal static void Log(Exception ex)
{
lock (s_lines)
{
s_lines.Add(ex.Message);
s_lines.Add(ex.StackTrace);
}
}
internal static void Log(string line) internal static void Log(string line)
{ {
lock (s_lines) lock (s_lines)
......
...@@ -36,8 +36,8 @@ public static void OpenFile(string file) ...@@ -36,8 +36,8 @@ public static void OpenFile(string file)
public static Task<ProcessOutput> RunProcessAsync( public static Task<ProcessOutput> RunProcessAsync(
string executable, string executable,
string arguments, string arguments,
bool lowPriority,
CancellationToken cancellationToken, CancellationToken cancellationToken,
bool lowPriority = false,
string workingDirectory = null, string workingDirectory = null,
bool captureOutput = false, bool captureOutput = false,
bool displayWindow = true, bool displayWindow = true,
......
...@@ -78,25 +78,5 @@ internal static List<Process> GetProcessTree(Process process) ...@@ -78,25 +78,5 @@ internal static List<Process> GetProcessTree(Process process)
return list; return list;
} }
internal static bool Is64Bit(Process process)
{
if (Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE") == "x86")
{
return false;
}
bool isWow64;
if (!IsWow64Process(process.Handle, out isWow64))
{
throw new Exception($"{nameof(IsWow64Process)} failed with {Marshal.GetLastWin32Error()}");
}
return !isWow64;
}
[DllImport("kernel32.dll", SetLastError = true, CallingConvention = CallingConvention.Winapi)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool IsWow64Process([In] IntPtr process, [Out] out bool wow64Process);
} }
} }
...@@ -64,7 +64,7 @@ private static async Task<int> Run(Options options, CancellationToken cancellati ...@@ -64,7 +64,7 @@ private static async Task<int> Run(Options options, CancellationToken cancellati
var finishedTask = await Task.WhenAny(timeoutTask, runTask); var finishedTask = await Task.WhenAny(timeoutTask, runTask);
if (finishedTask == timeoutTask) if (finishedTask == timeoutTask)
{ {
HandleTimeout(options); await HandleTimeout(options, cancellationToken);
cts.Cancel(); cts.Cancel();
try try
...@@ -150,26 +150,18 @@ private static void WriteLogFile(Options options) ...@@ -150,26 +150,18 @@ private static void WriteLogFile(Options options)
/// Invoked when a timeout occurs and we need to dump all of the test processes and shut down /// Invoked when a timeout occurs and we need to dump all of the test processes and shut down
/// the runnner. /// the runnner.
/// </summary> /// </summary>
private static void HandleTimeout(Options options) private static async Task HandleTimeout(Options options, CancellationToken cancellationToken)
{ {
string GetProcDumpFilePath(Process proc) => ProcessUtil.Is64Bit(proc) var procDumpFilePath = Path.Combine(options.ProcDumpPath, "procdump.exe");
? Path.Combine(options.ProcDumpPath, "procdump64.exe")
: Path.Combine(options.ProcDumpPath, "procdump.exe");
void DumpProcess(Process targetProcess, string dumpFilePath) async Task DumpProcess(Process targetProcess, string dumpFilePath)
{ {
Console.Write($"Dumping {targetProcess.ProcessName} {targetProcess.Id} to {dumpFilePath} ... "); Console.Write($"Dumping {targetProcess.ProcessName} {targetProcess.Id} to {dumpFilePath} ... ");
try try
{ {
var processStartInfo = new ProcessStartInfo(); var args = $"-accepteula -ma {targetProcess.Id} {dumpFilePath}";
processStartInfo.FileName = GetProcDumpFilePath(targetProcess); var processTask = ProcessRunner.RunProcessAsync(procDumpFilePath, args, cancellationToken);
processStartInfo.Arguments = $"-accepteula -ma {targetProcess.Id} {dumpFilePath}"; var processOutput = await processTask;
processStartInfo.CreateNoWindow = true;
processStartInfo.UseShellExecute = false;
processStartInfo.WindowStyle = ProcessWindowStyle.Hidden;
processStartInfo.RedirectStandardOutput = true;
var process = Process.Start(processStartInfo);
process.WaitForExit();
// The exit code for procdump doesn't obey standard windows rules. It will return non-zero // The exit code for procdump doesn't obey standard windows rules. It will return non-zero
// for succesful cases (possibly returning the count of dumps that were written). Best // for succesful cases (possibly returning the count of dumps that were written). Best
...@@ -180,15 +172,16 @@ void DumpProcess(Process targetProcess, string dumpFilePath) ...@@ -180,15 +172,16 @@ void DumpProcess(Process targetProcess, string dumpFilePath)
} }
else else
{ {
Console.WriteLine($"FAILED with {process.ExitCode}"); Console.WriteLine($"FAILED with {processOutput.ExitCode}");
Console.WriteLine($"{processStartInfo.FileName} {processStartInfo.Arguments}"); Console.WriteLine($"{procDumpFilePath} {args}");
Console.WriteLine(process.StandardOutput.ReadToEnd()); Console.WriteLine(string.Join(Environment.NewLine, processOutput.OutputLines));
} }
} }
catch (Exception ex) catch (Exception ex) when (!cancellationToken.IsCancellationRequested)
{ {
Console.WriteLine("FAILED"); Console.WriteLine("FAILED");
Console.WriteLine(ex.Message); Console.WriteLine(ex.Message);
Logger.Log("Failed to dump process", ex);
} }
} }
...@@ -204,7 +197,7 @@ void DumpProcess(Process targetProcess, string dumpFilePath) ...@@ -204,7 +197,7 @@ void DumpProcess(Process targetProcess, string dumpFilePath)
foreach (var proc in ProcessUtil.GetProcessTree(Process.GetCurrentProcess()).OrderBy(x => x.ProcessName)) foreach (var proc in ProcessUtil.GetProcessTree(Process.GetCurrentProcess()).OrderBy(x => x.ProcessName))
{ {
var dumpFilePath = Path.Combine(dumpDir, $"{proc.ProcessName}-{counter}.dmp"); var dumpFilePath = Path.Combine(dumpDir, $"{proc.ProcessName}-{counter}.dmp");
DumpProcess(proc, dumpFilePath); await DumpProcess(proc, dumpFilePath);
counter++; counter++;
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册