From 904606717573093564a8971cbf418c81aa2b8246 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer <siegfriedpammer@gmail.com> Date: Sat, 23 Jun 2012 17:23:59 +0200 Subject: [PATCH] improve error message if accessing the performance counters fails --- .../Analysis/Profiler/Controller/Profiler.cs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/AddIns/Analysis/Profiler/Controller/Profiler.cs b/src/AddIns/Analysis/Profiler/Controller/Profiler.cs index 138cf1aad2..253764d6b1 100644 --- a/src/AddIns/Analysis/Profiler/Controller/Profiler.cs +++ b/src/AddIns/Analysis/Profiler/Controller/Profiler.cs @@ -410,17 +410,26 @@ namespace ICSharpCode.Profiler.Controller } } + bool usePerformanceCounters = true; + unsafe void AddDataset(byte *ptr, TargetProcessPointer nativeStartPosition, long offset, long length, bool isFirst, TargetProcessPointer nativeRootFuncInfoPosition) { using (DataSet dataSet = new DataSet(this, ptr + offset, length, nativeStartPosition, nativeRootFuncInfoPosition, isFirst, is64Bit)) { lock (this.dataWriter) { this.dataWriter.WriteDataSet(dataSet); - if (performanceCounterInstanceName == null) - performanceCounterInstanceName = PerformanceCounterDescriptor.GetProcessInstanceName(profilee.Id); - - if (performanceCounterInstanceName == null) - LogString("instance not found!"); + if (usePerformanceCounters) { + if (performanceCounterInstanceName == null) + performanceCounterInstanceName = PerformanceCounterDescriptor.GetProcessInstanceName(profilee.Id); + + if (performanceCounterInstanceName == null) { + usePerformanceCounters = false; + LogString("Warning: One or more performance counters could not be accessed. " + + "Please ensure that the perfmon service is enabled and running. " + + "If the problem still persists try rebuilding the performance counters " + + "by executing \"lodctr /R\" from a command line with administrative rights."); + } + } foreach (var counter in performanceCounters) counter.Collect(performanceCounterInstanceName);