|
|
|
@ -70,8 +70,7 @@ namespace ICSharpCode.Profiler.Controller
@@ -70,8 +70,7 @@ namespace ICSharpCode.Profiler.Controller
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int ProcessorFrequency |
|
|
|
|
{ |
|
|
|
|
get |
|
|
|
|
{ |
|
|
|
|
get { |
|
|
|
|
if (this.is64Bit) |
|
|
|
|
return this.memHeader64->ProcessorFrequency; |
|
|
|
|
else |
|
|
|
@ -97,10 +96,12 @@ namespace ICSharpCode.Profiler.Controller
@@ -97,10 +96,12 @@ namespace ICSharpCode.Profiler.Controller
|
|
|
|
|
EventWaitHandle accessEventHandle; |
|
|
|
|
Thread logger; |
|
|
|
|
Thread dataCollector; |
|
|
|
|
Thread counterCollector; |
|
|
|
|
UnmanagedCircularBuffer nativeToManagedBuffer; |
|
|
|
|
IProfilingDataWriter dataWriter; |
|
|
|
|
|
|
|
|
|
Dictionary<string, PerformanceCounter> performanceCounters; |
|
|
|
|
PerformanceCounter cpuUsageCounter; |
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The currently used data provider.
|
|
|
|
|
/// </summary>
|
|
|
|
@ -132,8 +133,6 @@ namespace ICSharpCode.Profiler.Controller
@@ -132,8 +133,6 @@ namespace ICSharpCode.Profiler.Controller
|
|
|
|
|
SharedMemoryHeader32* memHeader32; |
|
|
|
|
SharedMemoryHeader64* memHeader64; |
|
|
|
|
|
|
|
|
|
TimeSpan lastTotalProcessorTime; |
|
|
|
|
|
|
|
|
|
StringBuilder profilerOutput; |
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -233,7 +232,7 @@ namespace ICSharpCode.Profiler.Controller
@@ -233,7 +232,7 @@ namespace ICSharpCode.Profiler.Controller
|
|
|
|
|
this.is64Bit = DetectBinaryType.RunsAs64Bit(info.FileName); |
|
|
|
|
|
|
|
|
|
this.profilerOutput = new StringBuilder(); |
|
|
|
|
|
|
|
|
|
this.performanceCounters = new Dictionary<string, PerformanceCounter>(); |
|
|
|
|
this.dataWriter = dataWriter; |
|
|
|
|
|
|
|
|
|
this.threadListMutex = new Mutex(false, MutexId); |
|
|
|
@ -260,16 +259,18 @@ namespace ICSharpCode.Profiler.Controller
@@ -260,16 +259,18 @@ namespace ICSharpCode.Profiler.Controller
|
|
|
|
|
this.dataCollector = new Thread(new ThreadStart(DataCollection)); |
|
|
|
|
this.dataCollector.Name = "DataCollector"; |
|
|
|
|
this.dataCollector.IsBackground = true; |
|
|
|
|
|
|
|
|
|
this.counterCollector = new Thread(new ThreadStart(CounterCollection)); |
|
|
|
|
this.counterCollector.Name = "CounterCollector"; |
|
|
|
|
this.counterCollector.IsBackground = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void InitializeHeader32() |
|
|
|
|
{ |
|
|
|
|
memHeader32 = (SharedMemoryHeader32*)fullView.Pointer; |
|
|
|
|
#if DEBUG
|
|
|
|
|
// '~DBG'
|
|
|
|
|
memHeader32->Magic = 0x7e444247; |
|
|
|
|
#else
|
|
|
|
|
// '~SM1'
|
|
|
|
|
memHeader32->Magic = 0x7e534d31; |
|
|
|
|
#endif
|
|
|
|
|
memHeader32->TotalLength = profilerOptions.SharedMemorySize; |
|
|
|
|
memHeader32->NativeToManagedBufferOffset = Align(sizeof(SharedMemoryHeader32)); |
|
|
|
|
memHeader32->ThreadDataOffset = Align(memHeader32->NativeToManagedBufferOffset + bufferSize); |
|
|
|
@ -297,11 +298,6 @@ namespace ICSharpCode.Profiler.Controller
@@ -297,11 +298,6 @@ namespace ICSharpCode.Profiler.Controller
|
|
|
|
|
throw new ArgumentException("The Processor Frequency could not be read!"); |
|
|
|
|
return freq; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void CounterCollection() |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void DataCollection() |
|
|
|
|
{ |
|
|
|
@ -354,11 +350,9 @@ namespace ICSharpCode.Profiler.Controller
@@ -354,11 +350,9 @@ namespace ICSharpCode.Profiler.Controller
|
|
|
|
|
memHeader32->NativeAddress + memHeader32->HeapOffset, |
|
|
|
|
memHeader32->Allocator.startPos - memHeader32->NativeAddress, |
|
|
|
|
memHeader32->Allocator.pos - memHeader32->Allocator.startPos, |
|
|
|
|
this.profilee.TotalProcessorTime.Subtract(lastTotalProcessorTime).TotalMilliseconds / 500.0, |
|
|
|
|
(cpuUsageCounter == null) ? 0 : cpuUsageCounter.NextValue(), |
|
|
|
|
memHeader32->RootFuncInfoAddress); |
|
|
|
|
|
|
|
|
|
lastTotalProcessorTime = this.profilee.TotalProcessorTime; |
|
|
|
|
|
|
|
|
|
ZeroMemory(new IntPtr(TranslatePointer(memHeader32->Allocator.startPos)), new IntPtr(memHeader32->Allocator.pos - memHeader32->Allocator.startPos)); |
|
|
|
|
|
|
|
|
|
memHeader32->Allocator.pos = memHeader32->Allocator.startPos; |
|
|
|
@ -477,8 +471,6 @@ namespace ICSharpCode.Profiler.Controller
@@ -477,8 +471,6 @@ namespace ICSharpCode.Profiler.Controller
|
|
|
|
|
|
|
|
|
|
RegisterProfiler(); |
|
|
|
|
|
|
|
|
|
this.lastTotalProcessorTime = new TimeSpan(0); |
|
|
|
|
|
|
|
|
|
if (is64Bit) { |
|
|
|
|
nativeToManagedBuffer = UnmanagedCircularBuffer.Create( |
|
|
|
|
new IntPtr(fullView.Pointer + memHeader64->NativeToManagedBufferOffset), bufferSize); |
|
|
|
@ -506,12 +498,13 @@ namespace ICSharpCode.Profiler.Controller
@@ -506,12 +498,13 @@ namespace ICSharpCode.Profiler.Controller
|
|
|
|
|
Debug.WriteLine("Launching profiler for " + this.psi.FileName + "..."); |
|
|
|
|
this.profilee.Start(); |
|
|
|
|
|
|
|
|
|
this.cpuUsageCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total", "."); |
|
|
|
|
|
|
|
|
|
this.logger.Start(nativeToManagedBuffer.CreateReadingStream()); |
|
|
|
|
|
|
|
|
|
// GC references currentSession
|
|
|
|
|
if (this.profilerOptions.EnableDC) { |
|
|
|
|
this.dataCollector.Start(); |
|
|
|
|
this.counterCollector.Start(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
OnSessionStarted(EventArgs.Empty); |
|
|
|
@ -582,11 +575,12 @@ namespace ICSharpCode.Profiler.Controller
@@ -582,11 +575,12 @@ namespace ICSharpCode.Profiler.Controller
|
|
|
|
|
Debug.WriteLine("Joining logger thread..."); |
|
|
|
|
this.logger.Join(); |
|
|
|
|
Debug.WriteLine("Logger thread joined!"); |
|
|
|
|
if (this.profilerOptions.EnableDC) { |
|
|
|
|
if (this.profilerOptions.EnableDC) |
|
|
|
|
this.dataCollector.Join(); |
|
|
|
|
this.counterCollector.Join(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// unload all counters to prevent exception during last collection!
|
|
|
|
|
this.cpuUsageCounter = null; |
|
|
|
|
this.performanceCounters = null; |
|
|
|
|
// Take last shot
|
|
|
|
|
if (this.is64Bit) |
|
|
|
|
CollectData64(); |
|
|
|
@ -783,10 +777,6 @@ namespace ICSharpCode.Profiler.Controller
@@ -783,10 +777,6 @@ namespace ICSharpCode.Profiler.Controller
|
|
|
|
|
if (dataCollector != null && dataCollector.IsAlive) { |
|
|
|
|
this.dataCollector.Join(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (counterCollector != null && counterCollector.IsAlive) { |
|
|
|
|
this.counterCollector.Join(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.fullView.Dispose(); |
|
|
|
|
this.file.Close(); |
|
|
|
|