Browse Source

prepared profiler for public testing

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@4039 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Siegfried Pammer 17 years ago
parent
commit
10c1982f8a
  1. 4
      src/AddIns/Misc/Profiler/Controller/Controller.csproj
  2. 46
      src/AddIns/Misc/Profiler/Controller/Profiler.cs
  3. 4
      src/AddIns/Misc/Profiler/Frontend/AddIn/ICSharpCode.Profiler.AddIn.addin
  4. 20
      src/AddIns/Misc/Profiler/Hook/SharedMemory.cpp
  5. 15
      src/AddIns/Misc/Profiler/X64Converter/Program.cs

4
src/AddIns/Misc/Profiler/Controller/Controller.csproj

@ -81,7 +81,9 @@
<Compile Include="Data\UnmanagedCallTreeNode64.cs"> <Compile Include="Data\UnmanagedCallTreeNode64.cs">
<DependentUpon>UnmanagedCallTreeNode.cs</DependentUpon> <DependentUpon>UnmanagedCallTreeNode.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="Data\UnmanagedProfilingDataSet.cs" /> <Compile Include="Data\UnmanagedProfilingDataSet.cs">
<DependentUpon>ProfilingDataSQLiteWriter.cs</DependentUpon>
</Compile>
<Compile Include="ExtendedRegistry.cs" /> <Compile Include="ExtendedRegistry.cs" />
<Compile Include="ExtensionMethods.cs" /> <Compile Include="ExtensionMethods.cs" />
<Compile Include="Interprocess\AtomicBoolean.cs" /> <Compile Include="Interprocess\AtomicBoolean.cs" />

46
src/AddIns/Misc/Profiler/Controller/Profiler.cs

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

4
src/AddIns/Misc/Profiler/Frontend/AddIn/ICSharpCode.Profiler.AddIn.addin

@ -71,10 +71,10 @@
<Path name="/SharpDevelop/Dialogs/OptionsDialog"> <Path name="/SharpDevelop/Dialogs/OptionsDialog">
<DialogPanel id = "Profiling" <DialogPanel id = "Profiling"
label = "${res:Dialog.Options.IDEOptions.Profiling}" label = "Profiling"
insertbefore = "TextEditorOptions"> insertbefore = "TextEditorOptions">
<DialogPanel id = "General" <DialogPanel id = "General"
label = "${res:Dialog.Options.IDEOptions.Profiling.General}" label = "General"
class = "ICSharpCode.Profiler.AddIn.OptionsPanels.General"/> class = "ICSharpCode.Profiler.AddIn.OptionsPanels.General"/>
</DialogPanel> </DialogPanel>
</Path> </Path>

20
src/AddIns/Misc/Profiler/Hook/SharedMemory.cpp

@ -19,16 +19,30 @@ CSharedMemory::CSharedMemory(char *name)
DebugWriteLine(L"MapViewOfFile returned nullptr"); DebugWriteLine(L"MapViewOfFile returned nullptr");
MessageBox(nullptr, TEXT("Could not open Shared Memory, please restart the profiler!"), TEXT("Profiler Error"), MB_OK); MessageBox(nullptr, TEXT("Could not open Shared Memory, please restart the profiler!"), TEXT("Profiler Error"), MB_OK);
} }
this->header = (SharedMemoryHeader*)this->startPtr; SharedMemoryHeader *header = (SharedMemoryHeader*)this->startPtr;
if (this->header->Magic != '~SM1') { #ifdef DEBUG
if (header->Magic != '~DBG') {
DebugWriteLine(L"Corrupted shared memory header");
if (header->Magic == '~SM1') {
MessageBox(nullptr, TEXT("Wrong build configuration; DEBUG needed!"), TEXT("Profiler Error"), MB_OK);
}
}
#else
if (header->Magic != '~SM1') {
DebugWriteLine(L"Corrupted shared memory header"); DebugWriteLine(L"Corrupted shared memory header");
if (header->Magic == '~DBG') {
MessageBox(nullptr, TEXT("Wrong build configuration; RELEASE needed!"), TEXT("Profiler Error"), MB_OK);
}
} }
this->length = this->header->TotalLength; #endif
this->length = header->TotalLength;
UnmapViewOfFile(this->startPtr); UnmapViewOfFile(this->startPtr);
this->startPtr = MapViewOfFile(this->fileHandle, FILE_MAP_ALL_ACCESS, 0, 0, this->length); this->startPtr = MapViewOfFile(this->fileHandle, FILE_MAP_ALL_ACCESS, 0, 0, this->length);
if (startPtr == nullptr) { if (startPtr == nullptr) {
DebugWriteLine(L"second MapViewOfFile returned nullptr"); DebugWriteLine(L"second MapViewOfFile returned nullptr");
MessageBox(nullptr, TEXT(""), TEXT("Profiler Error"), MB_OK);
} }
this->header = (SharedMemoryHeader*)this->startPtr;
} }
CSharedMemory::~CSharedMemory(void) CSharedMemory::~CSharedMemory(void)

15
src/AddIns/Misc/Profiler/X64Converter/Program.cs

@ -35,10 +35,11 @@ namespace X64Converter
return 2; return 2;
} }
parser.CompilationUnit.AcceptVisitor(new Converter(), null); var specials = parser.Lexer.SpecialTracker.RetrieveSpecials().Where(item => item is PreprocessingDirective);
parser.CompilationUnit.AcceptVisitor(new Converter(), null);
CSharpOutputVisitor output = new CSharpOutputVisitor(); CSharpOutputVisitor output = new CSharpOutputVisitor();
SpecialNodesInserter.Install(specials, output);
parser.CompilationUnit.AcceptVisitor(output, null); parser.CompilationUnit.AcceptVisitor(output, null);
if (!File.Exists(path + "64.cs") || File.ReadAllText(path + "64.cs") != output.Text) { if (!File.Exists(path + "64.cs") || File.ReadAllText(path + "64.cs") != output.Text) {
@ -84,8 +85,7 @@ namespace X64Converter
{ {
if (methodDeclaration.Name.EndsWith("32")) if (methodDeclaration.Name.EndsWith("32"))
methodDeclaration.Name = methodDeclaration.Name.Replace("32", "64"); methodDeclaration.Name = methodDeclaration.Name.Replace("32", "64");
else else {
{
if (!this.copyAllMembers) if (!this.copyAllMembers)
this.RemoveCurrentNode(); this.RemoveCurrentNode();
} }
@ -136,13 +136,10 @@ namespace X64Converter
public override object VisitTypeDeclaration(TypeDeclaration typeDeclaration, object data) public override object VisitTypeDeclaration(TypeDeclaration typeDeclaration, object data)
{ {
if (typeDeclaration.Name.EndsWith("32")) if (typeDeclaration.Name.EndsWith("32")) {
{
this.copyAllMembers = true; this.copyAllMembers = true;
typeDeclaration.Name = typeDeclaration.Name.Replace("32", "64"); typeDeclaration.Name = typeDeclaration.Name.Replace("32", "64");
} } else {
else
{
if ((typeDeclaration.Modifier & Modifiers.Partial) != Modifiers.Partial) if ((typeDeclaration.Modifier & Modifiers.Partial) != Modifiers.Partial)
this.RemoveCurrentNode(); this.RemoveCurrentNode();
else else

Loading…
Cancel
Save