/// <summary> /// Creates a new ProfilerRunner using a ProcessStartInfo and a data writer. /// </summary> public ProfilerRunner(ProcessStartInfo startInfo, bool useTempFileDatabase, IProfilingDataWriter writer) { if (writer == null) { throw new ArgumentNullException("writer"); } if (startInfo == null) { throw new ArgumentNullException("startInfo"); } if (useTempFileDatabase) { this.database = new TempFileDatabase(); this.writer = writer; 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, General.CreateProfilerOptions()); } PrintProfilerOptions(); this.profiler.RegisterFailed += delegate { MessageService.ShowError("${res:AddIns.Profiler.Messages.RegisterFailed}"); }; this.profiler.DeregisterFailed += delegate { MessageService.ShowError("${res:AddIns.Profiler.Messages.UnregisterFailed}"); }; this.profiler.OutputUpdated += delegate { SetOutputText(profiler.ProfilerOutput); }; this.profiler.SessionEnded += delegate { FinishSession(); }; }
/// <summary> /// Creates a new profiler using a process start info of an executable and a data writer. /// </summary> public Profiler(ProcessStartInfo info, IProfilingDataWriter dataWriter, ProfilerOptions options) { if (dataWriter == null) { throw new ArgumentNullException("dataWriter"); } if (info == null) { throw new ArgumentNullException("info"); } 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); this.profilerOutput = new StringBuilder(); this.performanceCounters = options.Counters; foreach (var counter in performanceCounters) { counter.Reset(); } this.dataWriter = dataWriter; this.threadListMutex = new Mutex(false, MutexId); this.accessEventHandle = new EventWaitHandle(true, EventResetMode.ManualReset, this.AccessEventId); this.psi = info; this.psi.UseShellExecute = false; // needed to get env vars working! this.psi.EnvironmentVariables["SharedMemoryName"] = SharedMemoryId; this.psi.EnvironmentVariables["MutexName"] = MutexId; // mutex for process pause/continue sychronization 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 this.psi.EnvironmentVariables["COMPLUS_ProfAPI_ProfilerCompatibilitySetting"] = "EnableV2Profiler"; // enable CLR 2.0 for CLR 4.0 file = MemoryMappedFile.CreateSharedMemory(SharedMemoryId, profilerOptions.SharedMemorySize); fullView = file.MapView(0, profilerOptions.SharedMemorySize); this.dataWriter.ProcessorFrequency = GetProcessorFrequency(); this.logger = new Thread(new ParameterizedThreadStart(Logging)); this.logger.Name = "Logger"; this.logger.IsBackground = true; // don't let the logger thread prevent our process from exiting this.dataCollector = new Thread(new ThreadStart(DataCollection)); this.dataCollector.Name = "DataCollector"; this.dataCollector.IsBackground = true; }
/// <summary> /// Creates a new profiler using the path to an executable to profile and a data writer. /// </summary> 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); } this.psi.WorkingDirectory = Path.GetDirectoryName(pathToExecutable); }
/// <summary> /// Creates a new UnitTestWriter instance. /// </summary> /// <param name="targetWriter">The target IProfilingDataWriter where the output should be written to.</param> /// <param name="unitTestNames">The fully qualified names of the unit test methods.</param> public UnitTestWriter(IProfilingDataWriter targetWriter, string[] unitTestNames) { if (targetWriter == null) throw new ArgumentNullException("targetWriter"); if (unitTestNames == null) throw new ArgumentNullException("unitTestNames"); this.targetWriter = targetWriter; this.unitTestNames = new HashSet<string>(unitTestNames); }
public ProfilerProcessRunner(IProfilingDataWriter writer, ProfilerOptions options) { if (writer == null) throw new ArgumentNullException("writer"); if (options == null) throw new ArgumentNullException("options"); this.writer = writer; this.options = options; this.psi = new ProcessStartInfo(); wasStarted = false; }
/// <summary> /// Copies all data to a different writer. /// </summary> /// <param name="writer"></param> /// <param name="progressReport">Used to report the progress of writing all DataSets, returning false tells WriteTo to cancel the process.</param> public void WriteTo(IProfilingDataWriter writer, Predicate <double> progressReport) { writer.ProcessorFrequency = this.processorFrequency; writer.WriteMappings(this.nameMappings.Values); for (int i = 0; i < this.DataSetCount; i++) { using (UnmanagedProfilingDataSet dataSet = this.LoadDataSet(i)) writer.WriteDataSet(dataSet); if (!progressReport.Invoke((i + 1) / (double)this.DataSetCount)) { break; } } }
public ProfilerProcessRunner(IProfilingDataWriter writer, ProfilerOptions options) { if (writer == null) { throw new ArgumentNullException("writer"); } if (options == null) { throw new ArgumentNullException("options"); } this.writer = writer; this.options = options; this.psi = new ProcessStartInfo(); wasStarted = false; }
/// <summary> /// Creates a new UnitTestWriter instance. /// </summary> /// <param name="targetWriter">The target IProfilingDataWriter where the output should be written to.</param> /// <param name="unitTestNames">The fully qualified names of the unit test methods.</param> public UnitTestWriter(IProfilingDataWriter targetWriter, string[] unitTestNames) { if (targetWriter == null) { throw new ArgumentNullException("targetWriter"); } if (unitTestNames == null) { throw new ArgumentNullException("unitTestNames"); } this.targetWriter = targetWriter; this.unitTestNames = new HashSet <string>(unitTestNames); }
/// <summary> /// Copies all data to a different writer. /// </summary> /// <param name="writer"></param> /// <param name="progressReport">Used to report the progress of writing all DataSets, returning false tells WriteTo to cancel the process.</param> public void WriteTo(IProfilingDataWriter writer, Predicate <double> progressReport) { writer.ProcessorFrequency = processorFrequency; writer.WriteMappings(nameMappings.Values); writer.WritePerformanceCounterData(counters); writer.WriteEventData(events); for (int i = 0; i < DataSetCount; i++) { using (UnmanagedProfilingDataSet dataSet = LoadDataSet(i)) writer.WriteDataSet(dataSet); if (!progressReport.Invoke((i + 1) / (double)DataSetCount)) { break; } } }
public static ProfilerRunner CreateRunner(IProfilingDataWriter writer) { AbstractProject currentProj = ProjectService.CurrentProject as AbstractProject; if (currentProj == null) { return(null); } if (!currentProj.IsStartable) { if (MessageService.AskQuestion("${res:AddIns.Profiler.Messages.NoStartableProjectWantToProfileStartupProject}")) { currentProj = ProjectService.OpenSolution.StartupProject as AbstractProject; if (currentProj == null) { MessageService.ShowError("${res:AddIns.Profiler.Messages.NoStartableProjectFound}"); return(null); } } else { return(null); } } if (!File.Exists(currentProj.OutputAssemblyFullPath)) { MessageService.ShowError("${res:AddIns.Profiler.Messages.FileNotFound}"); return(null); } ProcessStartInfo startInfo; try { startInfo = currentProj.CreateStartInfo(); } catch (ProjectStartException ex) { MessageService.ShowError(ex.Message); return(null); } ProfilerRunner runner = new ProfilerRunner(startInfo, true, writer); return(runner); }
/// <summary> /// Creates a new ProfilerRunner using a ProcessStartInfo and a data writer. /// </summary> public ProfilerRunner(ProcessStartInfo startInfo, bool useTempFileDatabase, IProfilingDataWriter writer) { if (writer == null) throw new ArgumentNullException("writer"); if (startInfo == null) throw new ArgumentNullException("startInfo"); if (useTempFileDatabase) { this.database = new TempFileDatabase(); this.writer = writer; 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, General.CreateProfilerOptions()); } PrintProfilerOptions(); this.profiler.RegisterFailed += delegate { MessageService.ShowError("${res:AddIns.Profiler.Messages.RegisterFailed}"); }; this.profiler.DeregisterFailed += delegate { MessageService.ShowError("${res:AddIns.Profiler.Messages.UnregisterFailed}"); }; this.profiler.OutputUpdated += delegate { SetOutputText(profiler.ProfilerOutput); }; this.profiler.SessionEnded += delegate { FinishSession(); }; }
/// <summary> /// Copies all data to a different writer. /// </summary> /// <param name="writer"></param> /// <param name="progressReport">Used to report the progress of writing all DataSets, returning false tells WriteTo to cancel the process.</param> public void WriteTo(IProfilingDataWriter writer, Predicate<double> progressReport) { writer.ProcessorFrequency = this.processorFrequency; writer.WriteMappings(this.nameMappings.Values); for (int i = 0; i < this.DataSetCount; i++) { using (UnmanagedProfilingDataSet dataSet = this.LoadDataSet(i)) writer.WriteDataSet(dataSet); if (!progressReport.Invoke((i + 1) / (double)this.DataSetCount)) break; } }
public static ProfilerRunner CreateRunner(IProfilingDataWriter writer) { AbstractProject currentProj = ProjectService.CurrentProject as AbstractProject; if (currentProj == null) return null; if (!currentProj.IsStartable) { if (MessageService.AskQuestion("${res:AddIns.Profiler.Messages.NoStartableProjectWantToProfileStartupProject}")) { currentProj = ProjectService.OpenSolution.StartupProject as AbstractProject; if (currentProj == null) { MessageService.ShowError("${res:AddIns.Profiler.Messages.NoStartableProjectFound}"); return null; } } else return null; } if (!File.Exists(currentProj.OutputAssemblyFullPath)) { MessageService.ShowError("${res:AddIns.Profiler.Messages.FileNotFound}"); return null; } ProcessStartInfo startInfo; try { startInfo = currentProj.CreateStartInfo(); } catch (ProjectStartException ex) { MessageService.ShowError(ex.Message); return null; } ProfilerRunner runner = new ProfilerRunner(startInfo, true, writer); return runner; }
ProfilerRunner CreateRunner(string path, string workingDirectory, string args, IProfilingDataWriter writer) { if (args == null) throw new ArgumentNullException("args"); if (workingDirectory == null) throw new ArgumentNullException("workingdirectory"); if (path == null) throw new ArgumentNullException("path"); if (!File.Exists(path)) throw new FileNotFoundException("file '" + path + "' was not found!"); if (!Directory.Exists(workingDirectory)) throw new DirectoryNotFoundException("directory '" + workingDirectory + "' was not found!"); ProcessStartInfo info = new ProcessStartInfo(path, args); info.WorkingDirectory = workingDirectory; ProfilerRunner runner = new ProfilerRunner(info, true, writer); return runner; }
/// <summary> /// Creates a new profiler using a process start info of an executable and a data writer. /// </summary> public Profiler(ProcessStartInfo info, IProfilingDataWriter dataWriter, ProfilerOptions options) { if (dataWriter == null) throw new ArgumentNullException("dataWriter"); if (info == null) throw new ArgumentNullException("info"); 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); this.profilerOutput = new StringBuilder(); this.performanceCounters = options.Counters; foreach (var counter in performanceCounters) counter.Reset(); this.dataWriter = dataWriter; this.threadListMutex = new Mutex(false, MutexId); this.accessEventHandle = new EventWaitHandle(true, EventResetMode.ManualReset, this.AccessEventId); this.psi = info; this.psi.UseShellExecute = false; // needed to get env vars working! this.psi.EnvironmentVariables["SharedMemoryName"] = SharedMemoryId; this.psi.EnvironmentVariables["MutexName"] = MutexId; // mutex for process pause/continue sychronization 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 this.psi.EnvironmentVariables["COMPLUS_ProfAPI_ProfilerCompatibilitySetting"] = "EnableV2Profiler"; // enable CLR 2.0 for CLR 4.0 file = MemoryMappedFile.CreateSharedMemory(SharedMemoryId, profilerOptions.SharedMemorySize); fullView = file.MapView(0, profilerOptions.SharedMemorySize); this.dataWriter.ProcessorFrequency = GetProcessorFrequency(); this.logger = new Thread(new ParameterizedThreadStart(Logging)); this.logger.Name = "Logger"; this.logger.IsBackground = true; // don't let the logger thread prevent our process from exiting this.dataCollector = new Thread(new ThreadStart(DataCollection)); this.dataCollector.Name = "DataCollector"; this.dataCollector.IsBackground = true; }
/// <summary> /// Creates a new profiler using the path to an executable to profile and a data writer. /// </summary> 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); this.psi.WorkingDirectory = Path.GetDirectoryName(pathToExecutable); }
/// <summary> /// Copies all data to a different writer. /// </summary> /// <param name="writer"></param> /// <param name="progressReport">Used to report the progress of writing all DataSets, returning false tells WriteTo to cancel the process.</param> public void WriteTo(IProfilingDataWriter writer, Predicate<double> progressReport) { writer.ProcessorFrequency = processorFrequency; writer.WriteMappings(nameMappings.Values); writer.WritePerformanceCounterData(counters); writer.WriteEventData(events); for (int i = 0; i < DataSetCount; i++) { using (UnmanagedProfilingDataSet dataSet = LoadDataSet(i)) writer.WriteDataSet(dataSet); if (!progressReport.Invoke((i + 1) / (double)DataSetCount)) break; } }
ProfilerRunner CreateRunner(string path, string workingDirectory, string args, IProfilingDataWriter writer) { if (args == null) { throw new ArgumentNullException("args"); } if (workingDirectory == null) { throw new ArgumentNullException("workingdirectory"); } if (path == null) { throw new ArgumentNullException("path"); } if (!File.Exists(path)) { throw new FileNotFoundException("file '" + path + "' was not found!"); } if (!Directory.Exists(workingDirectory)) { throw new DirectoryNotFoundException("directory '" + workingDirectory + "' was not found!"); } ProcessStartInfo info = new ProcessStartInfo(path, args); info.WorkingDirectory = workingDirectory; ProfilerRunner runner = new ProfilerRunner(info, true, writer); return(runner); }