Browse Source

Added event and time markers to extended timeline

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@5201 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Siegfried Pammer 16 years ago
parent
commit
7d4b8a4cb6
  1. 1
      src/AddIns/Misc/Profiler/Controller/Profiler.cs
  2. 3
      src/AddIns/Misc/Profiler/Frontend/Controls/ExtendedTimeLineControl.xaml.cs
  3. 75
      src/AddIns/Misc/Profiler/Frontend/Controls/TimeLineControl.cs
  4. 4
      src/AddIns/Misc/Profiler/Hook/Profiler.cpp
  5. 4
      src/AddIns/Misc/Profiler/Hook/constants.cpp
  6. 2
      src/AddIns/Misc/Profiler/Hook/global.h

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

@ -50,6 +50,7 @@ namespace ICSharpCode.Profiler.Controller
volatile bool stopDC; volatile bool stopDC;
volatile bool enableDC; volatile bool enableDC;
volatile bool isFirstDC; volatile bool isFirstDC;
volatile int millisecondsStartTime;
/// <summary> /// <summary>
/// Gets whether the profiler is running inside a 64-bit profilee process or not. /// Gets whether the profiler is running inside a 64-bit profilee process or not.

3
src/AddIns/Misc/Profiler/Frontend/Controls/ExtendedTimeLineControl.xaml.cs

@ -39,6 +39,7 @@ namespace ICSharpCode.Profiler.Controls
this.perfCounterList.ItemsSource = this.provider.GetPerformanceCounters(); this.perfCounterList.ItemsSource = this.provider.GetPerformanceCounters();
this.perfCounterList.SelectedIndex = 0; this.perfCounterList.SelectedIndex = 0;
this.timeLine.Provider = provider;
Update(); Update();
} }
@ -84,7 +85,7 @@ namespace ICSharpCode.Profiler.Controls
this.timeLine.Format = selectedPerformanceCounter.Format; this.timeLine.Format = selectedPerformanceCounter.Format;
for (int i = 0; i < values.Length; i++) for (int i = 0; i < values.Length; i++)
segments.Add(new TimeLineSegment() { Value = values[i], TimeOffset = 0, DisplayMarker = markers[i], Events = provider.GetEventDataEntries(i) }); segments.Add(new TimeLineSegment() { Value = values[i], DisplayMarker = markers[i], Events = provider.GetEventDataEntries(i) });
this.timeLine.ValuesList.AddRange(segments); this.timeLine.ValuesList.AddRange(segments);
} }

75
src/AddIns/Misc/Profiler/Frontend/Controls/TimeLineControl.cs

@ -6,9 +6,11 @@
// </file> // </file>
using System; using System;
using System.Collections.ObjectModel; using System.Linq;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics; using System.Diagnostics;
using System.Globalization;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Documents; using System.Windows.Documents;
@ -23,7 +25,6 @@ namespace ICSharpCode.Profiler.Controls
public class TimeLineSegment { public class TimeLineSegment {
public float Value { get; set; } public float Value { get; set; }
public bool DisplayMarker { get; set; } public bool DisplayMarker { get; set; }
public long TimeOffset { get; set; }
public EventDataEntry[] Events { get; set; } public EventDataEntry[] Events { get; set; }
} }
@ -51,6 +52,8 @@ namespace ICSharpCode.Profiler.Controls
public string Format { get; set; } public string Format { get; set; }
public ProfilingDataProvider Provider { get; set; }
public int SelectedEndIndex public int SelectedEndIndex
{ {
get { return selectedEndIndex; } get { return selectedEndIndex; }
@ -140,11 +143,23 @@ namespace ICSharpCode.Profiler.Controls
drawingContext.DrawGeometry(b, new Pen(b, 1), geometry); drawingContext.DrawGeometry(b, new Pen(b, 1), geometry);
DateTime time = new DateTime(1,1,1,0,0,0,0);
for (int i = 0; i < this.valuesList.Count; i++) { for (int i = 0; i < this.valuesList.Count; i++) {
if (this.valuesList[i].DisplayMarker) if (this.valuesList[i].DisplayMarker)
drawingContext.DrawLine(p, new Point(pieceWidth * i, offsetFromTop), drawingContext.DrawLine(p, new Point(pieceWidth * i, offsetFromTop),
new Point(pieceWidth * i, this.RenderSize.Height)); new Point(pieceWidth * i, this.RenderSize.Height));
if (i % 3 == 0) {
FormattedText textFormat = new FormattedText(
time.ToString("mm:ss.fff"),
CultureInfo.CurrentCulture, FlowDirection.LeftToRight,
new Typeface("Segoe UI"), 12, Brushes.Black
);
drawingContext.DrawText(textFormat, new Point(pieceWidth * i, 0));
}
var events = this.valuesList[i].Events; var events = this.valuesList[i].Events;
if (events != null && events.Length > 0) { if (events != null && events.Length > 0) {
@ -159,6 +174,8 @@ namespace ICSharpCode.Profiler.Controls
); );
} }
} }
time = time.AddMilliseconds(500);
} }
drawingContext.DrawRectangle( drawingContext.DrawRectangle(
@ -174,15 +191,16 @@ namespace ICSharpCode.Profiler.Controls
protected override void OnMouseUp(System.Windows.Input.MouseButtonEventArgs e) protected override void OnMouseUp(System.Windows.Input.MouseButtonEventArgs e)
{ {
bool valid; bool valid;
int index = TransformToIndex(e.GetPosition(this), out valid); Point pos = e.GetPosition(this);
int index = TransformToIndex(pos, out valid);
if (pos.Y >= 40) {
if (index < this.selectedStartIndex) { if (index < this.selectedStartIndex) {
this.selectedEndIndex = this.selectedStartIndex; this.selectedEndIndex = this.selectedStartIndex;
this.selectedStartIndex = index; this.selectedStartIndex = index;
} else } else
this.selectedEndIndex = index; this.selectedEndIndex = index;
}
Console.WriteLine("start: {0} end: {1} count: {2}", SelectedStartIndex, SelectedEndIndex, valuesList.Count);
this.InvalidateMeasure(); this.InvalidateMeasure();
this.InvalidateVisual(); this.InvalidateVisual();
@ -192,9 +210,11 @@ namespace ICSharpCode.Profiler.Controls
protected override void OnMouseDown(System.Windows.Input.MouseButtonEventArgs e) protected override void OnMouseDown(System.Windows.Input.MouseButtonEventArgs e)
{ {
this.CaptureMouse(); this.CaptureMouse();
Point pos = e.GetPosition(this);
bool valid; bool valid;
int index = TransformToIndex(e.GetPosition(this), out valid); int index = TransformToIndex(pos, out valid);
if (pos.Y >= 40)
this.selectedStartIndex = this.selectedEndIndex = index; this.selectedStartIndex = this.selectedEndIndex = index;
this.InvalidateMeasure(); this.InvalidateMeasure();
@ -216,15 +236,52 @@ namespace ICSharpCode.Profiler.Controls
} else if (tooltip == null && valid) { } else if (tooltip == null && valid) {
tooltip = new ToolTip(); tooltip = new ToolTip();
if (pos.Y < 20) if (pos.Y < 20)
tooltip.Content = "Time: "; tooltip.Content = "Time: " + new DateTime(0).AddMilliseconds(index * 500).ToString("mm:ss.fff");
else if (pos.Y < 40) else if (pos.Y < 40)
tooltip.Content = "Event: "; tooltip.Content = CreateTooltipForEvents(index);
else else
tooltip.Content = "Value: " + this.valuesList[index].Value.ToString(this.Format) + " " + this.Unit; tooltip.Content = "Value: " + this.valuesList[index].Value.ToString(this.Format) + " " + this.Unit;
tooltip .IsOpen = true; tooltip .IsOpen = tooltip.Content != null;
} }
} }
object CreateTooltipForEvents(int index)
{
EventDataEntry[] events = this.ValuesList[index].Events;
TextBlock block = events.Any() ? new TextBlock() : null;
foreach (var e in events) {
if (block.Inlines.Any())
block.Inlines.Add(new LineBreak());
NameMapping mapping = Provider.GetMapping(e.NameId);
string fullSignature = mapping.ReturnType + " " + mapping.Name + "(" + string.Join(", ", mapping.Parameters) + ")";
block.Inlines.Add(new Bold { Inlines = { fullSignature } });
switch (e.Type) {
case EventType.Console:
break;
case EventType.WindowsForms:
string target = e.Data.Substring(0, e.Data.IndexOf(':'));
string text = e.Data.Substring(e.Data.IndexOf(':') + 1);
block.Inlines.Add(new LineBreak());
block.Inlines.Add(new Bold { Inlines = { "Source: " } });
block.Inlines.Add(target);
block.Inlines.Add(new LineBreak());
block.Inlines.Add(new Bold { Inlines = { "Text: " } });
block.Inlines.Add(text);
break;
case EventType.Exception:
case EventType.WindowsPresentationFoundation:
break;
}
}
return block;
}
protected override void OnLostMouseCapture(MouseEventArgs e) protected override void OnLostMouseCapture(MouseEventArgs e)
{ {
base.OnLostMouseCapture(e); base.OnLostMouseCapture(e);

4
src/AddIns/Misc/Profiler/Hook/Profiler.cpp

@ -711,7 +711,6 @@ void CProfiler::Rewrite(FunctionID functionID, int type, int nameId)
COR_ILMETHOD_TINY *method = (COR_ILMETHOD_TINY *)header; COR_ILMETHOD_TINY *method = (COR_ILMETHOD_TINY *)header;
if (method->GetCodeSize() + sizeof(activateCall) + sizeof(loggerCall) + sizeof(deactivateCall) + 2 < MAX_CODE_SIZE_TINY) { if (method->GetCodeSize() + sizeof(activateCall) + sizeof(loggerCall) + sizeof(deactivateCall) + 2 < MAX_CODE_SIZE_TINY) {
LogString(L"is tiny!");
// Copy the header elements. // Copy the header elements.
memcpy(&codeBuf[0], method, TINY_HEADER_SIZE); memcpy(&codeBuf[0], method, TINY_HEADER_SIZE);
@ -731,7 +730,6 @@ void CProfiler::Rewrite(FunctionID functionID, int type, int nameId)
// 2 upper bits are the tiny header 6 lower bits are length // 2 upper bits are the tiny header 6 lower bits are length
codeBuf[0] = (byte)((newLength - 1) << 2 | 0x2); codeBuf[0] = (byte)((newLength - 1) << 2 | 0x2);
} else { } else {
LogString(L"is tiny but exceeds!");
ConvertToFat((byte *)codeBuf, &newLength); ConvertToFat((byte *)codeBuf, &newLength);
SetInjectionCode(metaData, codeBuf, &newLength, activateCall, loggerCall, deactivateCall, type, nameId); SetInjectionCode(metaData, codeBuf, &newLength, activateCall, loggerCall, deactivateCall, type, nameId);
@ -744,8 +742,6 @@ void CProfiler::Rewrite(FunctionID functionID, int type, int nameId)
target->CodeSize = newLength - FAT_HEADER_SIZE; target->CodeSize = newLength - FAT_HEADER_SIZE;
} }
} else if (((COR_ILMETHOD_FAT *)header)->IsFat()) { } else if (((COR_ILMETHOD_FAT *)header)->IsFat()) {
LogString(L"is fat!");
COR_ILMETHOD_FAT *method = (COR_ILMETHOD_FAT *)header; COR_ILMETHOD_FAT *method = (COR_ILMETHOD_FAT *)header;
COR_ILMETHOD_FAT *target = (COR_ILMETHOD_FAT *)codeBuf; COR_ILMETHOD_FAT *target = (COR_ILMETHOD_FAT *)codeBuf;

4
src/AddIns/Misc/Profiler/Hook/constants.cpp

@ -14,7 +14,9 @@ WCHAR *consoleGroupList[CONSOLE_GROUP_LENGTH] = {
WCHAR *winFormsGroupList[WINFORMS_GROUP_LENGTH] = { WCHAR *winFormsGroupList[WINFORMS_GROUP_LENGTH] = {
L"System.Windows.Forms.Control.OnClick", L"System.Windows.Forms.Control.OnClick",
L"System.Windows.Forms.Control.OnMouseClick" L"System.Windows.Forms.Control.OnDoubleClick",
L"System.Windows.Forms.Control.OnMouseWheel",
L"System.Windows.Forms.Control.OnKeyDown"
}; };
WCHAR *wpfGroupList[WPF_GROUP_LENGTH] = { WCHAR *wpfGroupList[WPF_GROUP_LENGTH] = {

2
src/AddIns/Misc/Profiler/Hook/global.h

@ -14,7 +14,7 @@
#include "LightweightList.h" #include "LightweightList.h"
#define CONSOLE_GROUP_LENGTH 2 #define CONSOLE_GROUP_LENGTH 2
#define WINFORMS_GROUP_LENGTH 2 #define WINFORMS_GROUP_LENGTH 4
#define WPF_GROUP_LENGTH 1 #define WPF_GROUP_LENGTH 1
extern fastAllocator stackAllocator; extern fastAllocator stackAllocator;

Loading…
Cancel
Save