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 16 years ago
parent
commit
10c1982f8a
  1. 4
      src/AddIns/Misc/Profiler/Controller/Controller.csproj
  2. 48
      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. 19
      src/AddIns/Misc/Profiler/X64Converter/Program.cs

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

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

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

@ -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();

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

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

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

@ -19,16 +19,30 @@ CSharedMemory::CSharedMemory(char *name) @@ -19,16 +19,30 @@ CSharedMemory::CSharedMemory(char *name)
DebugWriteLine(L"MapViewOfFile returned nullptr");
MessageBox(nullptr, TEXT("Could not open Shared Memory, please restart the profiler!"), TEXT("Profiler Error"), MB_OK);
}
this->header = (SharedMemoryHeader*)this->startPtr;
if (this->header->Magic != '~SM1') {
SharedMemoryHeader *header = (SharedMemoryHeader*)this->startPtr;
#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");
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);
this->startPtr = MapViewOfFile(this->fileHandle, FILE_MAP_ALL_ACCESS, 0, 0, this->length);
if (startPtr == nullptr) {
DebugWriteLine(L"second MapViewOfFile returned nullptr");
MessageBox(nullptr, TEXT(""), TEXT("Profiler Error"), MB_OK);
}
this->header = (SharedMemoryHeader*)this->startPtr;
}
CSharedMemory::~CSharedMemory(void)

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

@ -34,11 +34,12 @@ namespace X64Converter @@ -34,11 +34,12 @@ namespace X64Converter
File.WriteAllText(path + "64.cs", message);
return 2;
}
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);
if (!File.Exists(path + "64.cs") || File.ReadAllText(path + "64.cs") != output.Text) {
@ -84,8 +85,7 @@ namespace X64Converter @@ -84,8 +85,7 @@ namespace X64Converter
{
if (methodDeclaration.Name.EndsWith("32"))
methodDeclaration.Name = methodDeclaration.Name.Replace("32", "64");
else
{
else {
if (!this.copyAllMembers)
this.RemoveCurrentNode();
}
@ -136,13 +136,10 @@ namespace X64Converter @@ -136,13 +136,10 @@ namespace X64Converter
public override object VisitTypeDeclaration(TypeDeclaration typeDeclaration, object data)
{
if (typeDeclaration.Name.EndsWith("32"))
{
if (typeDeclaration.Name.EndsWith("32")) {
this.copyAllMembers = true;
typeDeclaration.Name = typeDeclaration.Name.Replace("32", "64");
}
else
{
} else {
if ((typeDeclaration.Modifier & Modifiers.Partial) != Modifiers.Partial)
this.RemoveCurrentNode();
else

Loading…
Cancel
Save