JD2022-TU1/main/extern/ProfileEventViewer4/ProfileEventViewer.cs

1082 lines
No EOL
42 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using System.IO;
using TD.SandDock;
using ObjectID = System.UInt64;
namespace ProfileEventViewer
{
public partial class ProfileEventViewerForm : Form
{
private List<ProfileEventTrace> m_ProfileTraces = new List<ProfileEventTrace>();
private string m_LastOpenedPath = string.Empty;
private List<UserTabbedDocument> m_WindowHistory = new List<UserTabbedDocument>();
private DirSummary m_DirSummary;
public DirSummary dirSummary
{
get { return m_DirSummary; }
}
private void Init()
{
m_DirSummary = new DirSummary();
InitializeComponent();
menuButtonItemZoomIn.PrimaryShortcut = Keys.Oemplus;
menuButtonItemZoomOut.PrimaryShortcut = Keys.OemMinus;
menuButtonItemClearEventsFilter.PrimaryShortcut = (Keys.Control | Keys.Back);
menuButtonItemClearContextsFilter.PrimaryShortcut = (Keys.Control | Keys.Shift | Keys.Back);
UpdateButtonStates();
}
public ProfileEventViewerForm()
{
Init();
}
public ProfileEventViewerForm(string initFileName)
{
Init();
OpenFile(initFileName);
}
private void OpenFile(string fileName)
{
// get the file name and open a stream
Stream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
if (stream != null)
{
ProfileEventDoc newDoc = new ProfileEventDoc();
newDoc.Data = new ProfileEventData(stream);
newDoc.Name = Path.GetFileName(fileName);
newDoc.PathName = Path.GetDirectoryName(fileName);
newDoc.FullFileName = Path.GetFullPath(fileName);
m_LastOpenedPath = newDoc.PathName;
stream.Close();
ProfileEventTrace trace = new ProfileEventTrace(newDoc);
m_ProfileTraces.Add(trace);
trace.Manager = sandDockManager;
trace.ShowThreadInfo = menuShowTSInfo.Checked;
trace.ToolTipText = fileName;
trace.DragEnter += ProfileEventViewerForm_DragEnter;
trace.DragDrop += ProfileEventViewerForm_DragDrop;
trace.EventsFilterChanged += ProfileEventTrace_FilterChanged;
trace.ContextsFilterChanged += ProfileEventTrace_FilterChanged;
trace.RangeSelectionChanged += ProfileEventTrace_RangeSelectionChanged;
newDoc.SelectedProfileEventChanged += ProfileEventDoc_SelectedEventChanged;
newDoc.SelectedDataEventChanged += ProfileEventDoc_SelectedEventChanged;
trace.Open(WindowOpenMethod.OnScreen);
// if (newDoc.Data.Tasks.Count > 0)
// {
// TaskGraph graph = new TaskGraph(newDoc);
// graph.Manager = sandDockManager;
// graph.Open(WindowOpenMethod.OnScreen);
// trace.TaskGraph = graph;
// AddDocumentToWindowHistory(graph);
// }
trace.Open();
UpdateWindowMenu(null);
UpdateButtonStates();
}
}
void ProfileEventDoc_SelectedEventChanged(ProfileEventDoc doc)
{
UpdateButtonStates();
}
void ProfileEventTrace_RangeSelectionChanged(ProfileEventTrace sender, bool markingEnded, bool contentChanged)
{
UpdateButtonStates();
}
void ProfileEventTrace_FilterChanged(ProfileEventTrace sender)
{
UpdateButtonStates();
UpdateStatusBarFilter();
}
private void openPelFile_Activate(object sender, EventArgs e)
{
// ask for file
OpenFileDialog fileDialog = new OpenFileDialog();
fileDialog.CheckFileExists = true;
fileDialog.CheckPathExists = true;
fileDialog.DereferenceLinks = true;
fileDialog.DefaultExt = "pel2";
// The Filter property requires a search string after the pipe ( | )
fileDialog.Filter = "Profile event log (*.pel2)|*.pel2";
fileDialog.Multiselect = true;
fileDialog.Title = "Select the Profile Event Log file";
fileDialog.ValidateNames = true;
if (fileDialog.ShowDialog() == DialogResult.OK)
{
// get the file name and open a stream
foreach (string fileName in fileDialog.FileNames)
OpenFile(fileName);
}
}
private void menuButtonItemLoadingLogs_Activate(object sender, EventArgs e)
{
// Look for loading logs
OpenFileDialog fileDialog = new OpenFileDialog();
fileDialog.CheckFileExists = true;
fileDialog.CheckPathExists = true;
fileDialog.DereferenceLinks = true;
fileDialog.DefaultExt = "csv";
// The Filter property requires a search string after the pipe ( | )
fileDialog.Filter = "Loading logs (*.csv)|*.csv";
fileDialog.Multiselect = true;
fileDialog.Title = "Select all loading logs to generate a profile event log from:";
fileDialog.ValidateNames = true;
if (fileDialog.ShowDialog() == DialogResult.OK)
{
try
{
string savedFileName = LoadingLogsToTrace.CreateTraceFromLoadingLogs(fileDialog.FileNames);
if (!string.IsNullOrEmpty(savedFileName))
OpenFile(savedFileName);
}
catch (FormatException formatException)
{
MessageBox.Show(string.Format("A format exception was thrown. Please verify that the log file contains only one log session (by checking if the header line is repeated). Also, verify whether the last line of the log is well-formed.\n\n{0}", formatException.Message));
}
catch (Exception exception)
{
MessageBox.Show(string.Format("An exception of type {1} was thrown:\n\n{0}", exception.Message, exception.GetType().ToString()));
}
}
}
private void menuButtonShowSummary_Activate(object sender, EventArgs e)
{
ProfileEventTrace pet = GetCurrentProfileEventTrace();
if (pet != null)
{
if (menuButtonShowSummary.Checked == true)
{
pet.Summary.Manager = sandDockManager;
pet.Summary.Open();
}
else
{
pet.Summary.Close();
}
}
}
private void ProfileEventViewerForm_DragDrop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
string[] fileNames = (string[])e.Data.GetData(DataFormats.FileDrop, false);
List<string> loadingLogFileNames = fileNames.Where(f => LoadingLogsToTrace.IsLoadingLog(f)).ToList();
List<string> pelFileNames = fileNames.Where(f => f.EndsWith(".pel2", StringComparison.InvariantCultureIgnoreCase)).ToList();
foreach (string fileName in pelFileNames)
{
if (File.Exists(fileName))
{
OpenFile(fileName);
}
}
try
{
if (loadingLogFileNames.Count > 0)
{
string savedFileName = LoadingLogsToTrace.CreateTraceFromLoadingLogs(loadingLogFileNames);
if (!string.IsNullOrEmpty(savedFileName))
OpenFile(savedFileName);
}
}
catch (FormatException formatException)
{
MessageBox.Show(string.Format("A format exception was thrown. Please verify that the log file contains only one log session (by checking if the header line is repeated). Also, verify whether the last line of the log is well-formed.\n\n{0}", formatException.Message));
}
catch (Exception exception)
{
MessageBox.Show(string.Format("An exception of type {1} was thrown:\n\n{0}", exception.Message, exception.GetType().ToString()));
}
}
}
private void ProfileEventViewerForm_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.None;
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
string[] fileNames = (string[])e.Data.GetData(DataFormats.FileDrop, false);
bool containsPELs = fileNames.Any(f => f.EndsWith(".pel2", StringComparison.InvariantCultureIgnoreCase));
bool containsLoadingLogs = fileNames.Any(f => LoadingLogsToTrace.IsLoadingLog(f));
if (containsPELs || containsLoadingLogs)
e.Effect = DragDropEffects.All;
}
}
private void menuShowTSInfo_Activate(object sender, EventArgs e)
{
ProfileEventTrace pet = GetCurrentProfileEventTrace();
if (pet != null)
pet.ShowThreadInfo = menuShowTSInfo.Checked;
}
private void menuButtonItemTSInfoContexts_Activate(object sender, EventArgs e)
{
ProfileEventTrace pet = GetCurrentProfileEventTrace();
if (pet != null)
pet.ShowThreadInfoContexts = menuButtonItemTSInfoContexts.Checked;
}
private void sandDockManager_ActiveTabbedDocumentChanged(object sender, EventArgs e)
{
UpdateWindowMenu(sandDockManager.ActiveTabbedDocument as UserTabbedDocument);
UpdateButtonStates();
UpdateStatusBar();
}
private void UpdateWindowMenu(UserTabbedDocument document)
{
// Update history
AddDocumentToWindowHistory(document);
// Populate the menu
int index = menuBarItemWindow.Items.IndexOf(menuButtonItemCloseAllTaskGraphs) + 1;
while (menuBarItemWindow.Items.Count > index)
menuBarItemWindow.Items.RemoveAt(index);
for (int i = 0; i < m_WindowHistory.Count; ++i)
{
TD.SandBar.MenuButtonItem menuItem = new TD.SandBar.MenuButtonItem();
if (i != 10)
menuItem.Text = string.Format("&{0} {1}", i + 1, m_WindowHistory[i].Text);
else
menuItem.Text = string.Format("1&0 {0}", m_WindowHistory[i].Text);
menuItem.Tag = m_WindowHistory[i];
menuItem.Activate += WindowMenuActivate;
if (i == 0)
{
menuItem.BeginGroup = true;
menuItem.Checked = true;
}
menuBarItemWindow.Items.Add(menuItem);
}
}
private void AddDocumentToWindowHistory(UserTabbedDocument document)
{
if (document != null)
{
m_WindowHistory.Remove(document);
m_WindowHistory.Insert(0, document);
while (m_WindowHistory.Count > 10) // Maximum of ten elements in there... should be enough!
m_WindowHistory.RemoveAt(9);
}
}
private void WindowMenuActivate(object sender, EventArgs e)
{
TD.SandBar.MenuButtonItem menuItem = (TD.SandBar.MenuButtonItem)sender;
UserTabbedDocument document = (UserTabbedDocument)menuItem.Tag;
document.Open();
}
private ProfileEventTrace GetCurrentProfileEventTrace()
{
if (sandDockManager.ActiveTabbedDocument != null)
if (m_ProfileTraces.Count != 0 && sandDockManager.ActiveTabbedDocument is ProfileEventTrace)
return (ProfileEventTrace)sandDockManager.ActiveTabbedDocument;
return null;
}
private void UpdateButtonStates()
{
ProfileEventTrace pet = GetCurrentProfileEventTrace();
bool isTrace = (pet != null);
menuBarItemEdit.Enabled = isTrace;
menuBarItemEdit.Visible = isTrace;
menuButtonTimeLine.Visible = isTrace;
menuButtonShowSummary.Enabled = isTrace;
if (!isTrace)
{
menuButtonShowSummary.Checked = false;
}
else
{
menuButtonShowSummary.Checked = pet.Summary.IsOpen;
menuButtonItemCopy.Enabled = pet.HasProfileEventSelection || pet.HasDataEventSelection;
menuButtonItemDeselectAll.Enabled = pet.HasSelection;
menuButtonItemTrimSelection.Enabled = pet.HasSelection;
menuButtonItemAdjustRangeToSelectedEvent.Enabled = pet.HasProfileEventSelection;
menuButtonItemExtendRangeToSelectedEvent.Enabled = pet.HasProfileEventSelection;
menuButtonItemZoomSelection.Enabled = pet.HasProfileEventSelection;
menuButtonItemZoomSelectionExtent.Enabled = pet.HasSelection;
menuButtonItemSelectEngineFrames.Enabled = pet.HasSelection;
menuButtonItemSelectGraphicFrames.Enabled = pet.HasSelection;
menuButtonShowTimeLine.Checked = pet.ShowTimeLine;
menuButtonShowSecondaryMarkers.Enabled = pet.ShowTimeLine;
menuButtonShowSecondaryMarkers.Checked = pet.ShowSecondaryTimeLineMarkers;
menuButtonItemClearEventsFilter.Enabled = !string.IsNullOrEmpty(pet.GetOriginalEventsFilterString());
menuButtonItemClearContextsFilter.Enabled = !string.IsNullOrEmpty(pet.GetOriginalContextsVisibilityFilterString()) && pet.GetOriginalContextsVisibilityFilterString() != ".*";
}
}
private void UpdateStatusBar()
{
ProfileEventTrace pet = GetCurrentProfileEventTrace();
if (pet != null)
{
int contextCount = 0;
int eventCount = 0;
int dataEventCount = 0;
foreach (ProfileEventData.ProfileContext context in pet.Data.Contexts.Values)
{
if (!context.ContainsAnyEvents() || context.IsHidden)
continue;
++contextCount;
eventCount += context.Heads.Count;
dataEventCount += context.DataEvents.Count;
}
statusBarItemCount.Text = string.Format("Context count: {0} / Event count: {1} / Data event count: {2}", contextCount, eventCount, dataEventCount);
}
else
{
statusBarItemCount.Text = string.Empty;
}
UpdateStatusBarFilter();
}
private void UpdateStatusBarFilter()
{
ProfileEventTrace pet = GetCurrentProfileEventTrace();
if (pet != null)
{
// Events contextsFilter
string eventsFilterLabel = "Events Filter: ";
string eventsFilter = pet.GetOriginalEventsFilterString();
Color eventsFilterColor = Color.FromKnownColor(KnownColor.ControlText);
if (string.IsNullOrEmpty(eventsFilter))
{
eventsFilter = string.Empty;
eventsFilterLabel = "No active events filter";
eventsFilterColor = Color.FromKnownColor(KnownColor.GrayText);
}
statusBarItemEventsFilter.ForeColor = eventsFilterColor;
statusBarItemEventsFilter.Text = eventsFilterLabel;
statusBarItemEventsFilterValue.Text = eventsFilter;
// Contexts contextsFilter
string contextsFilterLabel = "Contexts Filter: ";
string contextsFilter = pet.GetOriginalContextsVisibilityFilterString();
Color contextFilterColor = Color.FromKnownColor(KnownColor.ControlText);
if (string.IsNullOrEmpty(contextsFilter) || contextsFilter == ".*")
{
contextsFilter = string.Empty;
contextsFilterLabel = "No active contexts filter";
contextFilterColor = Color.FromKnownColor(KnownColor.GrayText);
}
statusBarItemContextsFilter.ForeColor = contextFilterColor;
statusBarItemContextsFilter.Text = contextsFilterLabel;
statusBarItemContextsFilterValue.Text = contextsFilter;
}
else
{
statusBarItemEventsFilter.Text = string.Empty;
statusBarItemEventsFilterValue.Text = string.Empty;
statusBarItemContextsFilter.Text = string.Empty;
statusBarItemContextsFilterValue.Text = string.Empty;
}
}
private void menuButtonItemControls_Activate(object sender, EventArgs e)
{
MessageBox.Show(
@"Controls in the PEL viewer:
Select an event: Left click
Copy the name of the selected event: Ctrl + C
Select all viewable events: Ctrl + A
Range selection (for reports): Right click and drag mouse horizontally
Modify range selection (for reports): Shift + Right click and drag mouse horizontally
Clicking inside or to the right of the selection modifies the right selection boundary
Clicking to the left of the selection modifies the left selection boundary
Trim range selection to nearest events: Ctrl + T
Adjust range selection to selected event: Ctrl + Shift + R OR Ctrl + Double Click
Extend range selection to selected event: Ctrl + Shift + X OR Ctrl + Shift + Double Click
Extend selection to engine frames: Ctrl + Shift + E
Extend selection to graphic frames: Ctrl + Shift + G
Pan: (Shift + left click OR middle click) + drag mouse
Zoom: Mousewheel OR + OR -
Zoom on location: Ctrl + left click and drag mouse
Zoom to selected event extents: Ctrl + E
Zoom to range selection extents: Shift + Z
Zoom to all extents: Ctrl + Z
Show timeline (with primary markers): Ctrl + L
Show timeline secondary markers: Ctrl + Shift + L
Filter events: Ctrl + F, then enter a filter
Clear events fitler: Ctrl + Backspace
Filter to a given event: Double click on the event
Filter contexts for summary: Ctrl + Right click and drag vertically
Clear contexts filter for summary: Ctrl + Right click (without dragging)
Filter contexts' visibility: Ctrl + Shift + F, then enter a C# regular expression to filter contexts (also affects summary)
Clear contexts' visibility filter: Ctrl + Shift + Backspace (also affects summary)
Change context display height: Left click on the + or - signs to the left of the context's name
Expand/Collapse context display height: Ctrl + Left click on the + or - signs to the left of the context's name
Show/Hide contexts containing no profile events: Ctrl + Shift + I
Controls in the summary report:
Selection: Click
Multiple selection: (Shift AND/OR Ctrl) + Click
Select All: Ctrl + A
Focus on filter box: Alt + F
Center PEL viewer on task: Double click (when enabled in context menu)
Zoom PEL viewer on task: Double click (when enabled in context menu)
Filter contexts: Right-click in the list and choose the contexts to filter
"
);
}
private void menuButtonItemAboutLoadingLogs_Activate(object sender, EventArgs e)
{
MessageBox.Show(
@"It is possible to generate PELs from loading logs by using the
File -> Generate PEL from Loading Logs menu options.
These logs are generated by running Scimitar in engine with the
following command line options:
* /loadingprofiler
** Generates loadingprofile.csv
* /logprecisefastloadstreamingstats
** Generates precisefastloadstreamingstats_*.csv
You can also compile with specific #defines to create more logs:
* #define POP_FASTLOADMANAGER_STATS
** Generates flm_objectloadingstat.csv
You can create a merged version of the logs into the PEL file by
selecting all the logs you want to see merged when generating the PEL.",
"About Loading Logs...", MessageBoxButtons.OK, MessageBoxIcon.Question);
}
private void menuButtonItemDirectoryReport_Activate(object sender, EventArgs e)
{
RefreshDirectorySummary();
}
private void RefreshDirectorySummary()
{
//Get the open file directory if any
FolderBrowserDialog fbd = new FolderBrowserDialog();
fbd.ShowNewFolderButton = false;
fbd.RootFolder = Environment.SpecialFolder.MyComputer;
if (!string.IsNullOrEmpty(m_LastOpenedPath))
fbd.SelectedPath = m_LastOpenedPath;
if (fbd.ShowDialog() != DialogResult.OK)
{
return;
}
string[] allPELFiles = Directory.GetFiles(fbd.SelectedPath, "*.pel2", SearchOption.AllDirectories);
if (allPELFiles.Length == 0)
{
MessageBox.Show("No '*.pel2' files found under {0}.\nReport aborted.", fbd.SelectedPath);
return;
}
//convert to List
List<string> fileList = new List<string>();
for (int i = 0; i < allPELFiles.Length; ++i)
{
fileList.Add(allPELFiles[i]);
}
GenerateReportFromFileList(fileList);
m_DirSummary.Text = String.Format("Summary of PELS found under {0}\\*.pel2", fbd.SelectedPath);
m_DirSummary.SortByColumnIndex(0);
m_DirSummary.ShowDialog();
}
private void GenerateReportFromFileList(List<string> fileList)
{
int ind = 0;
m_DirSummary.ClearAll();
Processing processBar = new Processing();
processBar.Show();
foreach (string fileName in fileList)
{
ind++;
processBar.SetProgressName(String.Format("Processing {0}", fileName));
processBar.SetProgressRatio(ind * 100 / fileList.Count);
// get the file name and open a stream
Stream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
if (stream != null)
{
ProfileEventDoc newDoc = new ProfileEventDoc();
newDoc.Data = new ProfileEventData(stream);
newDoc.Name = Path.GetFileName(fileName);
newDoc.PathName = Path.GetDirectoryName(fileName);
newDoc.FullFileName = Path.GetFullPath(fileName);
stream.Close();
ProfileEventTrace trace = new ProfileEventTrace(newDoc);
trace.SelectAll();
trace.Summary.UpdateWithTrace(true);
//Copy Summary in DirSummary
m_DirSummary.Populate(trace.Summary.ListViewInfos, newDoc.Name, trace);
}
}
processBar.Close();
}
private void menuButtonItemCaptureX360_Activate(object sender, EventArgs e)
{
CaptureForm capture = new CaptureForm(CaptureForm.Platform.x360);
DialogResult result = capture.ShowDialog(this);
if (result == DialogResult.OK)
{
OpenFile(capture.FileName);
}
}
private void menuButtonItemSaveAs_Activate(object sender, EventArgs e)
{
ProfileEventTrace pet = GetCurrentProfileEventTrace();
if (pet != null)
{
ProfileEventDoc doc = pet.Doc;
string sourceFullFileName = doc.FullFileName;
if (File.Exists(sourceFullFileName))
{
// ask for file
SaveFileDialog fileDialog = new SaveFileDialog();
fileDialog.CheckFileExists = false;
fileDialog.CheckPathExists = false;
fileDialog.DereferenceLinks = true;
fileDialog.DefaultExt = "pel2";
// The Filter property requires a search string after the pipe ( | )
fileDialog.Filter = "Profile event log (*.pel2)|*.pel2";
fileDialog.Title = "Save pel2 file as...";
fileDialog.ValidateNames = true;
if (fileDialog.ShowDialog() == DialogResult.OK)
{
string destFullFileName = fileDialog.FileName;
try
{
File.Copy(sourceFullFileName, destFullFileName, true);
if (File.Exists(destFullFileName))
OpenFile(destFullFileName);
}
catch (Exception)
{ }
}
}
}
}
private void menuButtonItemMerge_Activate(object sender, EventArgs e)
{
// Ask for files
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.CheckFileExists = true;
openFileDialog.CheckPathExists = true;
openFileDialog.DereferenceLinks = true;
openFileDialog.DefaultExt = "pel2";
// The Filter property requires a search string after the pipe ( | )
openFileDialog.Filter = "Profile event log (*.pel2)|*.pel2";
openFileDialog.Multiselect = true;
openFileDialog.Title = "Select the Profile Event Log (PEL) files to merge";
openFileDialog.ValidateNames = true;
List<string> pelFiles = new List<string>();
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
List<EventFile> eventFiles = new List<EventFile>();
// Get the file name and open a stream
foreach (string fileName in openFileDialog.FileNames)
{
try
{
EventFile eventFile = new EventFile();
Stream readStream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
BinaryReader reader = new BinaryReader(readStream);
eventFile.Serialize(reader);
eventFiles.Add(eventFile);
}
catch (Exception ex)
{
MessageBox.Show(string.Format("An error occurred while reading file {0}:\n\n{1}", fileName, ex.ToString()), "Error while loading files", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
try
{
// Merge the files
for (int i = 1; i < eventFiles.Count; ++i)
eventFiles[0].Merge(eventFiles[i]);
}
catch (Exception ex)
{
MessageBox.Show(string.Format("An error occurred while merging the files.\n\n{0}", ex.ToString()), "Error while merging files", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
// Save the merged file
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.CheckFileExists = false;
saveFileDialog.CheckPathExists = false;
saveFileDialog.DereferenceLinks = true;
saveFileDialog.DefaultExt = "pel2";
// The Filter property requires a search string after the pipe ( | )
saveFileDialog.Filter = "Profile event log (*.pel2)|*.pel2";
saveFileDialog.Title = "Save the merged Profile Event Log (PEL) file as...";
saveFileDialog.ValidateNames = true;
saveFileDialog.FileName = string.Format("{0}_Merged", Path.GetFileNameWithoutExtension(openFileDialog.FileNames[0]));
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
string destFullFileName = saveFileDialog.FileName;
try
{
using (Stream writeStream = new FileStream(destFullFileName, FileMode.Create, FileAccess.Write))
using (BinaryWriter writer = new BinaryWriter(writeStream))
{
EventFile mergedEventFile = eventFiles[0];
mergedEventFile.Serialize(writer);
}
if (File.Exists(destFullFileName))
OpenFile(destFullFileName);
}
catch (Exception ex)
{
MessageBox.Show(string.Format("An error occurred while saving the merged file.\n\n{0}", ex.ToString()), "Error while saving merged file", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
}
}
private void menuButtonShowTimeLine_Activate(object sender, EventArgs e)
{
ProfileEventTrace pet = GetCurrentProfileEventTrace();
if (pet == null)
return;
pet.ShowTimeLine = menuButtonShowTimeLine.Checked;
menuButtonShowSecondaryMarkers.Enabled = menuButtonShowTimeLine.Checked;
}
private void menuButtonShowSecondaryMarkers_Activate(object sender, EventArgs e)
{
ProfileEventTrace pet = GetCurrentProfileEventTrace();
if (pet != null)
pet.ShowSecondaryTimeLineMarkers = menuButtonShowSecondaryMarkers.Checked;
}
private void menuButtonItemCopy_Activate(object sender, EventArgs e)
{
ProfileEventTrace pet = GetCurrentProfileEventTrace();
if (pet != null)
{
try
{
pet.CopySelectedEventNameToClipboard();
}
catch (Exception exception)
{
MessageBox.Show(string.Format("Could not copy event name to clipboard.\n\n{0}", exception.ToString()), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void menuButtonItemSelectAll_Activate(object sender, EventArgs e)
{
ProfileEventTrace pet = GetCurrentProfileEventTrace();
if (pet != null)
pet.SelectAll();
}
private void menuButtonItemDeselectAll_Activate(object sender, EventArgs e)
{
ProfileEventTrace pet = GetCurrentProfileEventTrace();
if (pet != null)
pet.DeselectAll();
}
private void menuButtonItemTrimSelection_Activate(object sender, EventArgs e)
{
ProfileEventTrace pet = GetCurrentProfileEventTrace();
if (pet != null)
pet.TrimSelection();
}
private void menuButtonItemAdjustRangeToSelectedEvent_Activate(object sender, EventArgs e)
{
ProfileEventTrace pet = GetCurrentProfileEventTrace();
if (pet != null)
pet.AdjustRangeToSelectedEvent(false);
}
private void menuButtonItemExtendRangeToSelectedEvent_Activate(object sender, EventArgs e)
{
ProfileEventTrace pet = GetCurrentProfileEventTrace();
if (pet != null)
pet.AdjustRangeToSelectedEvent(true);
}
private void menuButtonItemSelectEngineFrames_Activate(object sender, EventArgs e)
{
ProfileEventTrace pet = GetCurrentProfileEventTrace();
if (pet != null)
pet.SelectEngineFrames();
}
private void menuButtonItemSelectGraphicFrames_Activate(object sender, EventArgs e)
{
ProfileEventTrace pet = GetCurrentProfileEventTrace();
if (pet != null)
pet.SelectGraphicFrames();
}
private void menuButtonItemZoomIn_Activate(object sender, EventArgs e)
{
ProfileEventTrace pet = GetCurrentProfileEventTrace();
if (pet != null)
pet.ZoomIn();
}
private void menuButtonItemZoomOut_Activate(object sender, EventArgs e)
{
ProfileEventTrace pet = GetCurrentProfileEventTrace();
if (pet != null)
pet.ZoomOut();
}
private void menuButtonItemZoomSelection_Activate(object sender, EventArgs e)
{
ProfileEventTrace pet = GetCurrentProfileEventTrace();
if (pet != null)
pet.ZoomOnSelectedEvent();
}
private void menuButtonItemZoomExtent_Activate(object sender, EventArgs e)
{
ProfileEventTrace pet = GetCurrentProfileEventTrace();
if (pet != null)
pet.ZoomExtentAll();
}
private void menuButtonItemZoomSelectionExtent_Activate(object sender, EventArgs e)
{
ProfileEventTrace pet = GetCurrentProfileEventTrace();
if (pet != null)
pet.ZoomExtentSelected();
}
private void menuButtonItemFilter_Activate(object sender, EventArgs e)
{
FilterEvents();
}
private void statusBarItemEventsFilter_Activate(object sender, EventArgs e)
{
FilterEvents();
}
private void statusBarItemEventsFilterValue_Activate(object sender, EventArgs e)
{
FilterEvents();
}
private void FilterEvents()
{
ProfileEventTrace pet = GetCurrentProfileEventTrace();
if (pet != null)
{
string filter = pet.GetOriginalEventsFilterString();
if (string.IsNullOrEmpty(filter))
filter = "Enter a eventsFilter";
string newFilterValue = Microsoft.VisualBasic.Interaction.InputBox("Enter a new event filter value.\nWords separated by spaces will be used as distinct filter keywords.\nTo use spaces in a filter, surround the filter with quotes.",
"Change event filter", filter, -1, -1);
pet.SetEventsFilterString(newFilterValue);
}
}
private void menuButtonItemClearFilter_Activate(object sender, EventArgs e)
{
ProfileEventTrace pet = GetCurrentProfileEventTrace();
if (pet != null)
{
pet.SetEventsFilterString(string.Empty);
}
}
private void menuButtonItemFilterContexts_Activate(object sender, EventArgs e)
{
FilterContexts();
}
private void statusBarItemContextsFilter_Activate(object sender, EventArgs e)
{
FilterContexts();
}
private void statusBarItemContextsFilterValue_Activate(object sender, EventArgs e)
{
FilterContexts();
}
private void FilterContexts()
{
ProfileEventTrace pet = GetCurrentProfileEventTrace();
if (pet != null)
{
string filter = pet.GetOriginalContextsVisibilityFilterString();
if (string.IsNullOrEmpty(filter) || filter == ".*")
filter = "Enter a C# regular expression";
string newFilterValue = Microsoft.VisualBasic.Interaction.InputBox("Enter a new contexts filter value.\nThis filter is a C# regular expression.",
"Change context filter", filter, -1, -1);
if (!pet.SetContextsVisibilityFilterString(newFilterValue))
MessageBox.Show("The entered value was not a valid C# regular expression.", "Error in filter", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void menuButtonItemClearContextsFilter_Activate(object sender, EventArgs e)
{
ProfileEventTrace pet = GetCurrentProfileEventTrace();
if (pet != null)
{
pet.SetContextsVisibilityFilterString(string.Empty);
}
}
private void menuButtonItemShowParentShadow_Activate(object sender, EventArgs e)
{
ProfileEventTrace pet = GetCurrentProfileEventTrace();
if (pet != null)
{
pet.SetParentShadowActive();
}
}
private void menuButtonItemShowTinyEvents_Activate(object sender, EventArgs e)
{
ProfileEventTrace pet = GetCurrentProfileEventTrace();
if (pet != null)
{
pet.SetShowTinyEvents();
}
}
private void menuButtonItemAdjustTime_Activate(object sender, EventArgs e)
{
ProfileEventTrace pet = GetCurrentProfileEventTrace();
if (pet != null)
{
Stack<ProfileEventData.ProfileContext.Event> allEvents = new Stack<ProfileEventData.ProfileContext.Event>();
int adjustedCount = 0;
// Adjust times of unfinished events.
foreach (ProfileEventData.ProfileContext context in pet.Data.Contexts.Values)
foreach (ProfileEventData.ProfileContext.Event evt in context.Heads)
evt.AdjustTime(ref adjustedCount);
MessageBox.Show(string.Format("{0} events needed adjustment (they were missing their end time).\n\nThe PEL may not represent real times in the adjusted parts.", adjustedCount), "Handling missing events", MessageBoxButtons.OK, MessageBoxIcon.Information);
if (adjustedCount > 0)
{
pet.Redraw();
}
}
}
private void sandDockManager_DockControlClosing(object sender, DockControlClosingEventArgs e)
{
UserTabbedDocument document = e.DockControl as UserTabbedDocument;
m_WindowHistory.Remove(document);
if (e.DockControl is Summary)
{
ProfileEventTrace pet = GetCurrentProfileEventTrace();
if (pet != null)
{
Summary summary = (Summary)e.DockControl;
if (pet.Summary == summary)
{
menuButtonShowSummary.Checked = false;
}
}
}
else if (e.DockControl is ProfileEventTrace)
{
ProfileEventTrace pet = (ProfileEventTrace)e.DockControl;
pet.DragEnter -= ProfileEventViewerForm_DragEnter;
pet.DragDrop -= ProfileEventViewerForm_DragDrop;
pet.EventsFilterChanged -= ProfileEventTrace_FilterChanged;
pet.ContextsFilterChanged -= ProfileEventTrace_FilterChanged;
pet.RangeSelectionChanged -= ProfileEventTrace_RangeSelectionChanged;
pet.Doc.SelectedProfileEventChanged -= ProfileEventDoc_SelectedEventChanged;
pet.Doc.SelectedDataEventChanged -= ProfileEventDoc_SelectedEventChanged;
int index = m_ProfileTraces.FindIndex(p => p == pet);
m_ProfileTraces.RemoveAt(index);
if (pet.TaskGraph != null)
m_WindowHistory.Remove(pet.TaskGraph);
}
UpdateWindowMenu(null);
}
private void menuButtonItemExit_Activate(object sender, EventArgs e)
{
Close();
}
private void menuButtonItemCloseAll_Activate(object sender, EventArgs e)
{
List<ProfileEventTrace> traces = m_ProfileTraces.ToList(); // Copy the list; it may be modified by callbacks.
foreach (ProfileEventTrace trace in traces)
{
trace.Close();
}
// Make sure the list is empty
m_ProfileTraces.Clear();
}
private void menuButtonItemCloseAllTaskGraph_Activate(object sender, EventArgs e)
{
foreach (ProfileEventTrace trace in m_ProfileTraces)
{
if (trace.TaskGraph != null)
{
m_WindowHistory.Remove(trace.TaskGraph);
trace.TaskGraph.Close();
trace.TaskGraph = null;
}
}
UpdateWindowMenu(null);
}
private void menuButtonTileHorizontally_Activate(object sender, EventArgs e)
{
sandDockManager.ActiveTabbedDocumentChanged -= new System.EventHandler(this.sandDockManager_ActiveTabbedDocumentChanged);
foreach (ProfileEventTrace trace in m_ProfileTraces)
{
if (trace.LayoutSystem.Controls.Count > 1)
trace.Split(DockSide.Top);
if (trace.TaskGraph != null)
{
if (trace.TaskGraph.LayoutSystem.Controls.Count > 1)
trace.TaskGraph.Split(DockSide.Top);
}
}
if (m_WindowHistory.Count > 0)
m_WindowHistory[0].Open();
sandDockManager.ActiveTabbedDocumentChanged += new System.EventHandler(this.sandDockManager_ActiveTabbedDocumentChanged);
}
private void menuButtonItemRegroup_Activate(object sender, EventArgs e)
{
sandDockManager.ActiveTabbedDocumentChanged -= new System.EventHandler(this.sandDockManager_ActiveTabbedDocumentChanged);
UserTabbedDocument originalDocument = null;
foreach (ProfileEventTrace trace in m_ProfileTraces)
{
if (originalDocument == null)
originalDocument = trace;
if (trace != originalDocument)
trace.OpenWith(originalDocument);
if (trace.TaskGraph != null)
trace.TaskGraph.OpenWith(originalDocument);
}
if (m_WindowHistory.Count > 0)
m_WindowHistory[0].Open();
sandDockManager.ActiveTabbedDocumentChanged += new System.EventHandler(this.sandDockManager_ActiveTabbedDocumentChanged);
}
}
}