diff --git a/src/AddIns/Misc/Profiler/Controller/Profiler.cs b/src/AddIns/Misc/Profiler/Controller/Profiler.cs index 81a9554bf5..0e6cfec793 100644 --- a/src/AddIns/Misc/Profiler/Controller/Profiler.cs +++ b/src/AddIns/Misc/Profiler/Controller/Profiler.cs @@ -119,15 +119,10 @@ namespace ICSharpCode.Profiler.Controller ProfilerOptions profilerOptions = new ProfilerOptions(); /// - /// Gets and sets all settings used by this profiler instance. + /// Gets all settings used by this profiler instance. /// public ProfilerOptions ProfilerOptions { get { return profilerOptions; } - set { - if (isRunning) - throw new InvalidOperationException("Can not change settings while the profiler is executing!"); - profilerOptions = value; - } } SharedMemoryHeader32* memHeader32; @@ -206,8 +201,8 @@ namespace ICSharpCode.Profiler.Controller /// /// Creates a new profiler using the path to an executable to profile and a data writer. /// - public Profiler(string pathToExecutable, IProfilingDataWriter dataWriter) - : this(new ProcessStartInfo(pathToExecutable), dataWriter) + public Profiler(string pathToExecutable, IProfilingDataWriter dataWriter, ProfilerOptions options) + : this(new ProcessStartInfo(pathToExecutable), dataWriter, options) { if (!File.Exists(pathToExecutable)) throw new FileNotFoundException("File not found!", pathToExecutable); @@ -218,7 +213,7 @@ namespace ICSharpCode.Profiler.Controller /// /// Creates a new profiler using a process start info of an executable and a data writer. /// - public Profiler(ProcessStartInfo info, IProfilingDataWriter dataWriter) + public Profiler(ProcessStartInfo info, IProfilingDataWriter dataWriter, ProfilerOptions options) { if (dataWriter == null) throw new ArgumentNullException("dataWriter"); @@ -228,6 +223,8 @@ namespace ICSharpCode.Profiler.Controller if (!DetectBinaryType.IsDotNetExecutable(info.FileName)) throw new ProfilerException("File is not a valid .NET executable file!"); + + this.profilerOptions = options; this.is64Bit = DetectBinaryType.RunsAs64Bit(info.FileName); @@ -245,7 +242,7 @@ namespace ICSharpCode.Profiler.Controller this.psi.EnvironmentVariables["AccessEventName"] = AccessEventId; // name for access event of controller this.psi.EnvironmentVariables["COR_ENABLE_PROFILING"] = "1"; // enable profiling; 0 = disable this.psi.EnvironmentVariables["COR_PROFILER"] = ProfilerGuid; // GUID for the profiler - + file = MemoryMappedFile.CreateSharedMemory(SharedMemoryId, profilerOptions.SharedMemorySize); fullView = file.MapView(0, profilerOptions.SharedMemorySize); diff --git a/src/AddIns/Misc/Profiler/Frontend/AddIn/AddIn.csproj b/src/AddIns/Misc/Profiler/Frontend/AddIn/AddIn.csproj index 6f0c5a3f66..6f7f2f94a1 100644 --- a/src/AddIns/Misc/Profiler/Frontend/AddIn/AddIn.csproj +++ b/src/AddIns/Misc/Profiler/Frontend/AddIn/AddIn.csproj @@ -94,7 +94,8 @@ - + + ProfileExecutableForm.xaml diff --git a/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/ProfilerRunner.cs b/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/ProfilerRunner.cs index ef1f6b8dbf..e99e0ed710 100644 --- a/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/ProfilerRunner.cs +++ b/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/ProfilerRunner.cs @@ -49,14 +49,14 @@ namespace ICSharpCode.Profiler.AddIn if (useTempFileDatabase) { this.database = new TempFileDatabase(); this.writer = writer; - this.profiler = new Controller.Profiler(startInfo, this.database.GetWriter()); + this.profiler = new Controller.Profiler(startInfo, this.database.GetWriter(), General.CreateProfilerOptions()); } else { this.database = null; this.writer = writer; - this.profiler = new Controller.Profiler(startInfo, writer); + this.profiler = new Controller.Profiler(startInfo, writer, General.CreateProfilerOptions()); } - this.profiler.ProfilerOptions = General.CreateProfilerOptions(); + PrintProfilerOptions(); this.profiler.RegisterFailed += delegate { MessageService.ShowError("Could not register the profiler into COM Registry. Cannot start profiling!"); }; this.profiler.DeregisterFailed += delegate { MessageService.ShowError("Could not unregister the profiler from COM Registry!"); }; @@ -64,8 +64,18 @@ namespace ICSharpCode.Profiler.AddIn this.profiler.SessionEnded += delegate { FinishSession(); }; } - void FinishSession() + void PrintProfilerOptions() { + var options = General.CreateProfilerOptions(); + LoggingService.Info("Profiler settings:"); + LoggingService.Info("Shared memory size: " + options.SharedMemorySize + " (" + (options.SharedMemorySize / 1024 / 1024) + " MB)"); + LoggingService.Info("Combine recursive calls: " + options.CombineRecursiveFunction); + LoggingService.Info("Enable DC: " + options.EnableDC); + LoggingService.Info("Profile .NET internals: " + (!options.DoNotProfileDotNetInternals)); + } + + void FinishSession() + { using (AsynchronousWaitDialog dlg = AsynchronousWaitDialog.ShowWaitDialog("Preparing for analysis", true)) { if (database != null) { database.WriteTo(writer, progress => !dlg.IsCancelled); @@ -82,6 +92,7 @@ namespace ICSharpCode.Profiler.AddIn public void Run() { + WorkbenchSingleton.Workbench.GetPad(typeof(CompilerMessageView)).BringPadToFront(); profiler.Start(); } diff --git a/src/AddIns/Misc/Profiler/Frontend/BenchmarkRunner/BenchmarkRunner.cs b/src/AddIns/Misc/Profiler/Frontend/BenchmarkRunner/BenchmarkRunner.cs index 67e235a94c..78dcdb815b 100644 --- a/src/AddIns/Misc/Profiler/Frontend/BenchmarkRunner/BenchmarkRunner.cs +++ b/src/AddIns/Misc/Profiler/Frontend/BenchmarkRunner/BenchmarkRunner.cs @@ -85,7 +85,7 @@ namespace BenchmarkRunner File.Delete(fileName); using (var profiler = new Profiler( - startInfo, new ProfilingDataSQLiteWriter(fileName) + startInfo, new ProfilingDataSQLiteWriter(fileName), new ProfilerOptions() )) { using (ManualResetEvent mre = new ManualResetEvent(false)) { profiler.SessionEnded += delegate { diff --git a/src/AddIns/Misc/Profiler/Frontend/Gui/Window1.xaml.cs b/src/AddIns/Misc/Profiler/Frontend/Gui/Window1.xaml.cs index 131d08867c..c49cd47eaf 100644 --- a/src/AddIns/Misc/Profiler/Frontend/Gui/Window1.xaml.cs +++ b/src/AddIns/Misc/Profiler/Frontend/Gui/Window1.xaml.cs @@ -57,7 +57,7 @@ namespace ICSharpCode.Profiler.Frontend this.database = new TempFileDatabase(); - this.profiler = new Profiler.Controller.Profiler(path, database.GetWriter()); + this.profiler = new Profiler.Controller.Profiler(path, database.GetWriter(), new ProfilerOptions()); profiler.RegisterFailed += delegate { MessageBox.Show("register failed"); }; profiler.DeregisterFailed += delegate { MessageBox.Show("deregister failed"); }; diff --git a/src/AddIns/Misc/Profiler/Hook/SharedMemory.cpp b/src/AddIns/Misc/Profiler/Hook/SharedMemory.cpp index aae2f6ed10..151b24cacc 100644 --- a/src/AddIns/Misc/Profiler/Hook/SharedMemory.cpp +++ b/src/AddIns/Misc/Profiler/Hook/SharedMemory.cpp @@ -37,10 +37,13 @@ CSharedMemory::CSharedMemory(char *name) #endif this->length = header->TotalLength; UnmapViewOfFile(this->startPtr); + DebugWriteLine(L"Length: %d", this->length); this->startPtr = MapViewOfFile(this->fileHandle, FILE_MAP_ALL_ACCESS, 0, 0, this->length); if (startPtr == nullptr) { + char buffer[512]; + sprintf_s(buffer, 512, "Error while creating temporary storage file (shared memory)!\n\nError: %d", GetLastError()); DebugWriteLine(L"second MapViewOfFile returned nullptr"); - MessageBox(nullptr, TEXT(""), TEXT("Profiler Error"), MB_OK); + MessageBox(nullptr, buffer, TEXT("Profiler Error"), MB_OK); } this->header = (SharedMemoryHeader*)this->startPtr; }