2019-03-04 00:06:27 +00:00
|
|
|
using Profiler.Data;
|
2020-02-05 20:51:54 +00:00
|
|
|
using Profiler.Controls.ViewModels;
|
2019-03-04 00:06:27 +00:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows;
|
|
|
|
|
using System.Windows.Controls;
|
|
|
|
|
using System.Windows.Data;
|
|
|
|
|
using System.Windows.Documents;
|
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
using System.Windows.Media;
|
|
|
|
|
using System.Windows.Media.Imaging;
|
|
|
|
|
using System.Windows.Navigation;
|
|
|
|
|
using System.Windows.Shapes;
|
|
|
|
|
|
2020-02-05 20:51:54 +00:00
|
|
|
namespace Profiler.Controls
|
2019-03-04 00:06:27 +00:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Interaction logic for SamlingThreadView.xaml
|
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class SamplingThreadView : UserControl
|
|
|
|
|
{
|
|
|
|
|
public SamplingThreadView()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2019-05-09 22:18:01 +01:00
|
|
|
|
|
|
|
|
DataContextChanged += SamplingThreadView_DataContextChanged;
|
|
|
|
|
IsVisibleChanged += SamplingThreadView_IsVisibleChanged;
|
2019-03-04 00:06:27 +00:00
|
|
|
}
|
|
|
|
|
|
2019-05-09 22:18:01 +01:00
|
|
|
private void VM_OnLoaded(SamplingFrame frame)
|
2019-03-04 00:06:27 +00:00
|
|
|
{
|
2019-05-09 22:18:01 +01:00
|
|
|
InitThreadList(frame);
|
|
|
|
|
}
|
2019-03-04 00:06:27 +00:00
|
|
|
|
2019-05-09 22:18:01 +01:00
|
|
|
private void SamplingThreadView_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
VM = DataContext as SamplingViewModel;
|
|
|
|
|
VM.OnLoaded += VM_OnLoaded;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SamplingViewModel VM { get; set; }
|
|
|
|
|
|
|
|
|
|
private void SamplingThreadView_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
VM?.SetActive(IsVisible);
|
2019-03-04 00:06:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BuildEntryList(List<Entry> entries, SamplingNode node, double offset)
|
|
|
|
|
{
|
|
|
|
|
if (node.Description != null)
|
2019-04-22 20:55:08 +01:00
|
|
|
entries.Add(new Entry(new EventDescription(node.NameWithModule), Durable.MsToTick(offset), Durable.MsToTick(offset + node.Duration)));
|
2019-03-04 00:06:27 +00:00
|
|
|
|
2019-03-14 12:21:50 +00:00
|
|
|
offset += node.SelfDuration * 0.5;
|
|
|
|
|
|
2019-03-04 00:06:27 +00:00
|
|
|
foreach (SamplingNode child in node.Children)
|
|
|
|
|
{
|
|
|
|
|
BuildEntryList(entries, child, offset);
|
|
|
|
|
offset += child.Duration;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-05 20:51:54 +00:00
|
|
|
private ThreadViewSettings Settings { get; set; } = new ThreadViewSettings();
|
|
|
|
|
|
2019-03-04 00:06:27 +00:00
|
|
|
void InitThreadList(SamplingFrame frame)
|
|
|
|
|
{
|
|
|
|
|
Frame = frame;
|
|
|
|
|
|
|
|
|
|
List<ThreadRow> rows = new List<ThreadRow>();
|
|
|
|
|
|
|
|
|
|
if (frame != null)
|
|
|
|
|
{
|
|
|
|
|
List<Entry> entries = new List<Entry>();
|
|
|
|
|
|
|
|
|
|
SamplingNode root = frame.Root;
|
|
|
|
|
|
|
|
|
|
BuildEntryList(entries, root, 0.0);
|
|
|
|
|
|
|
|
|
|
EventFrame eventFrame = new EventFrame(new FrameHeader() { Start = 0, Finish = Durable.MsToTick(root.Duration) }, entries, frame.Group);
|
2019-04-20 00:45:50 +01:00
|
|
|
ThreadData threadData = new ThreadData(null) { Events = new List<EventFrame> { eventFrame } };
|
2020-02-05 20:51:54 +00:00
|
|
|
EventsThreadRow row = new EventsThreadRow(frame.Group, new ThreadDescription() { Name = "Sampling Node" }, threadData, Settings);
|
2019-08-30 01:11:11 +01:00
|
|
|
row.LimitMaxDepth = false;
|
2019-03-04 00:06:27 +00:00
|
|
|
row.EventNodeHover += Row_EventNodeHover;
|
|
|
|
|
rows.Add(row);
|
|
|
|
|
ThreadViewControl.Scroll.ViewUnit.Width = 1.0;
|
|
|
|
|
ThreadViewControl.InitRows(rows, eventFrame.Header);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ThreadViewControl.InitRows(rows, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Row_EventNodeHover(Point mousePos, Rect rect, ThreadRow row, EventNode node)
|
|
|
|
|
{
|
2020-02-05 20:51:54 +00:00
|
|
|
ThreadViewControl.ToolTipPanel = node != null ? new ThreadViewControl.TooltipInfo { Text = String.Format("{0} {1:0.#} ({2:0.#}%)", node.Description.FullName, node.Duration, 100.0 * node.Duration / Frame.Root.Duration), Rect = rect } : null;
|
2019-03-04 00:06:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private FrameGroup Group { get; set; }
|
|
|
|
|
private EventDescription Description { get; set; }
|
|
|
|
|
private SamplingFrame Frame { get; set; }
|
|
|
|
|
}
|
|
|
|
|
}
|