Skip to content

Commit

Permalink
Actually obey the symbol settings from the symbol settings dialog
Browse files Browse the repository at this point in the history
Default to %windir%/symbols and the microsoft symbol server when no symbol settings are provided
  • Loading branch information
kg committed May 16, 2011
1 parent 7e881d5 commit ad70884
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 7 deletions.
2 changes: 1 addition & 1 deletion DatabaseFile.cs
Expand Up @@ -180,7 +180,7 @@ public DatabaseFile (TaskScheduler scheduler, string filename)
Tangles.Add(theTangle);
}

yield return SymbolCache.CreateIndex(
yield return SymbolCache.CreateIndex<string>(
"ByFunction",
IndexSymbolByFunction
).Bind(() => SymbolsByFunction);
Expand Down
49 changes: 46 additions & 3 deletions HeapRecording.cs
Expand Up @@ -31,6 +31,9 @@

namespace HeapProfiler {
public class HeapRecording : IDisposable {
public const string DefaultSymbolPath = @"%windir%\symbols";
public const string DefaultSymbolServers = @"http://msdl.microsoft.com/download/symbols";

public const int SymbolResolveBatchSize = 1024;

public static class SnapshotLoadState {
Expand Down Expand Up @@ -262,14 +265,19 @@ string filename
}
});

IDictionary<string, string> environment = null;
yield return GetEnvironment().Bind(() => environment);

var psi = new ProcessStartInfo(
Settings.UmdhPath, String.Format(
"\"{0}\" -f:\"{1}\"", infile, outfile
)
);

using (var rp = Scheduler.Start(
Program.RunProcess(psi, ProcessPriorityClass.Idle),
Program.RunProcess(
psi, ProcessPriorityClass.Idle, environment
),
TaskExecutionPolicy.RunAsBackgroundTask
))
yield return rp;
Expand Down Expand Up @@ -947,6 +955,33 @@ where sgn.Key.Equals(item.key)
return f;
}

protected IEnumerator<object> GetEnvironment () {
object[] prefs = null;
yield return Program.Preferences.Select(
new[] { "SymbolPath", "SymbolServers" }
).Bind(() => prefs);

var symbolPath = (prefs[0] as string) ?? "";
var symbolServers = (prefs[1] as string) ?? "";

if (String.IsNullOrWhiteSpace(symbolPath))
symbolPath = DefaultSymbolPath;
if (String.IsNullOrWhiteSpace(symbolServers))
symbolServers = DefaultSymbolServers;

var symbolSrv = String.Format(
"SRV*{0}*{1}",
Environment.ExpandEnvironmentVariables(symbolPath),
Environment.ExpandEnvironmentVariables(symbolServers)
);

var environment = new Dictionary<string, string> {
{ "_NT_SYMBOL_PATH", symbolSrv }
};

yield return new Result(environment);
}

protected IEnumerator<object> CaptureSnapshotTask (string targetFilename) {
var now = DateTime.Now;

Expand All @@ -958,10 +993,13 @@ where sgn.Key.Equals(item.key)
)
);

IDictionary<string, string> environment = null;
yield return GetEnvironment().Bind(() => environment);

TemporaryFiles.Add(targetFilename);

using (Activities.AddItem("Capturing heap snapshot"))
yield return Program.RunProcess(psi);
yield return Program.RunProcess(psi, customEnvironment: environment);

yield return Future.RunInThread(
() => File.AppendAllText(targetFilename, mem.GetFileText())
Expand All @@ -987,13 +1025,18 @@ where sgn.Key.Equals(item.key)
} else {
filename = Path.GetTempFileName();

IDictionary<string, string> environment = null;
yield return GetEnvironment().Bind(() => environment);

var psi = new ProcessStartInfo(
Settings.UmdhPath, String.Format(
"\"{0}\" \"{1}\" -f:\"{2}\"", file1, file2, filename
)
);

var rp = Scheduler.Start(Program.RunProcess(psi), TaskExecutionPolicy.RunAsBackgroundTask);
var rp = Scheduler.Start(Program.RunProcess(
psi, customEnvironment: environment
), TaskExecutionPolicy.RunAsBackgroundTask);

using (Activities.AddItem("Generating heap diff"))
using (rp)
Expand Down
18 changes: 15 additions & 3 deletions Program.cs
Expand Up @@ -232,8 +232,13 @@ static class Program {
);
}

public static IEnumerator<object> RunProcess (ProcessStartInfo psi, ProcessPriorityClass? priority = null) {
var rtc = new RunToCompletion<RunProcessResult>(RunProcessWithResult(psi, priority));
public static IEnumerator<object> RunProcess (
ProcessStartInfo psi, ProcessPriorityClass? priority = null,
IEnumerable<KeyValuePair<string, string>> customEnvironment = null
) {
var rtc = new RunToCompletion<RunProcessResult>(RunProcessWithResult(
psi, priority, customEnvironment
));
yield return rtc;

if ((rtc.Result.StdOut ?? "").Trim().Length > 0)
Expand All @@ -245,13 +250,20 @@ static class Program {
throw new Exception(String.Format("Process exited with code {0}", rtc.Result.ExitCode));
}

public static IEnumerator<object> RunProcessWithResult (ProcessStartInfo psi, ProcessPriorityClass? priority = null) {
public static IEnumerator<object> RunProcessWithResult (
ProcessStartInfo psi, ProcessPriorityClass? priority = null,
IEnumerable<KeyValuePair<string, string>> customEnvironment = null
) {
psi.UseShellExecute = false;
psi.CreateNoWindow = true;
psi.RedirectStandardOutput = true;
psi.RedirectStandardError = true;
psi.WindowStyle = ProcessWindowStyle.Hidden;

if (customEnvironment != null)
foreach (var kvp in customEnvironment)
psi.EnvironmentVariables.Add(kvp.Key, kvp.Value);

var fProcess = StartProcess(psi);
yield return fProcess;

Expand Down

0 comments on commit ad70884

Please sign in to comment.