public void SerializeTraceData(TraceData data, Stream stream) { /* write the magic to the raw stream */ stream.Write(BitConverter.GetBytes(MAGIC), 0, sizeof(uint)); stream.Write(BitConverter.GetBytes(VERSION), 0, sizeof(uint)); /* Write the magic */ WriteUint(MAGIC); /* Write the version */ WriteUint(VERSION); SerializeStatistics(data.Statistics); SerializeStackTraces(data.StackTraces); SerializeSQLStatements(data.SQLStatements); SerializeExecutionCalls(data.AllExecutionCalls); WriteLong(data.MaxCallDepth); ms.Seek(0, SeekOrigin.Begin); using (DeflateStream def = new DeflateStream(stream, CompressionLevel.Optimal)) { ms.CopyTo(def); } }
private void DrawTrees() { TraceData ltd = new TraceData(); ltd.ExecutionPath = left; UIBuilder.BuildExecutionTree(ltd, diffLeft, lSQLMap, lExecMap, true, true); TraceData rtd = new TraceData(); rtd.ExecutionPath = right; UIBuilder.BuildExecutionTree(rtd, diffRight, rSQLMap, rExecMap, true, true); }
public void ProcessorComplete(TraceData td) { foreach (ExecutionCall call in sqlCalls) { var lineNumber = call.StartLine; var sqlStatement = td.SQLStatements.Where(s => s.LineNumber == lineNumber).First(); call.SQLStatement = sqlStatement; sqlStatement.ParentCall = call.Parent; call.Duration = sqlStatement.Duration; if (sqlStatement.IsError) { call.HasError = true; var parent = call.Parent; while (parent != null) { parent.HasError = true; parent = parent.Parent; } } } /* process stack traces from TraceDatta */ foreach (StackTraceEntry traceEntry in td.StackTraces) { var x = FindCallForLineNumber(traceEntry.LineNumber); if (x == null) { // sometimes they get printed right after the exit, try 1 line number above x = FindCallForLineNumber(traceEntry.LineNumber-1); } if (x != null) { x.IsError = true; x.StackTrace = traceEntry; traceEntry.Parent = x; var parent = x.Parent; while (parent != null) { parent.HasError = true; parent = parent.Parent; } } } td.MaxCallDepth = _maxCallDepth; td.Statistics.Add(new StatisticItem() { Category = "Execution Path", Label = "Maximum Call Depth", Value = _maxCallDepth.ToString() }); td.Statistics.Add(new StatisticItem() { Category = "Execution Path", Label = "Total Calls", Value = _ppcCodeCallCount.ToString() }); td.Statistics.Add(new StatisticItem() { Category = "Execution Path", Label = "PeopleCode Exceptions", Value = _ppcExceptionCount.ToString() }); }
public CompareDialog(TraceData initData) { InitializeComponent(); if (initData != null) { leftData = initData; btnCopyToRight.Enabled = true; btnLeftSelectAll.Enabled = true; UIBuilder.BuildExecutionTree(leftData, execTreeLeft, SQLMap, ExecMap, false); } }
private void btnOpenLeft_Click(object sender, EventArgs e) { openFileDialog1.Filter = "Trace Files|*.tracesql;*.twiz"; openFileDialog1.FileName = ""; var result = openFileDialog1.ShowDialog(); if (result == DialogResult.Cancel) { return; } btnLeftSelectAll.Enabled = false; execTreeLeft.Nodes.Clear(); leftSelected.Clear(); if (result == DialogResult.OK) { string filename = openFileDialog1.FileName; // Process the file if (TraceDeserializer.IsSerializedData(filename)) { if (TraceDeserializer.IsSerializedVersionSupported(filename)) { leftData = new TraceDeserializer().DeserializeTraceData(new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.None)); UIBuilder.BuildExecutionTree(leftData, execTreeLeft, SQLMap, ExecMap, false); } else { MessageBox.Show("This version of Trace Wizard cannot import the serialized data, maybe it was serialized with an older version."); } } else { leftProcessor = new TraceProcessor(filename); leftProcessor.WorkerReportsProgress = true; leftProcessor.WorkerSupportsCancellation = true; leftProcessor.ProgressChanged += ProcessorLeft_ProgressChanged; leftProcessor.RunWorkerCompleted += ProcessorLeft_RunWorkerCompleted; leftProcessor.RunWorkerAsync(); } } }
private void Processor_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { progressBar.Value = 0; if (e.Cancelled) { MessageBox.Show("Trace file processing cancelled."); processor = null; System.GC.Collect(); return; } traceData = (TraceData)e.Result; UpdateUI(); sw.Stop(); MessageBox.Show("Trace file processed in " + sw.Elapsed.TotalSeconds + " seconds."); sw.Reset(); System.GC.Collect(); }
public static void BuildExecutionTree(TraceData traceData, TreeView executionTree, Dictionary<SQLStatement, TreeNode> SQLMapToTree, Dictionary<ExecutionCall, TreeNode> ExecCallToTree, bool showLoading = true, bool diffMode = false) { if (traceData == null) { return; } var execList = traceData.ExecutionPath; var sqlList = traceData.SQLStatements; executionTree.Nodes.Clear(); SQLMapToTree.Clear(); ExecCallToTree.Clear(); var contextList = execList.OrderBy(p => p.StartLine).Select(p => p.Context).Distinct().ToList(); var contextNodeList = new List<TreeNode>(); double totalTraceTime = 0; foreach (var ctx in contextList) { var ctxNode = new TreeNode(ctx); contextNodeList.Add(ctxNode); var rootExecCalls = execList.Where(p => p.Context.Equals(ctx)).OrderBy(p => p.StartLine); double contextTotalTime = 0; foreach (var exec in rootExecCalls) { contextTotalTime += exec.Duration; if (!diffMode) { if (exec.HasError || exec.IsError) { ctxNode.BackColor = Color.Yellow; } else if (exec.Duration >= Properties.Settings.Default.LongCall) { ctxNode.BackColor = Color.LightGreen; } } else { /* only color yellow in Diff mode if there was a MODIFIED */ if (exec.DiffStatus == DiffStatus.MODIFIED) { ctxNode.BackColor = Color.Yellow; } } UIBuilder.BuildExecutionTree(ctxNode, exec,SQLMapToTree, ExecCallToTree, showLoading,diffMode); } ctxNode.Text += " Dur: " + contextTotalTime; totalTraceTime += contextTotalTime; } foreach (var node in contextNodeList) { executionTree.Nodes.Add(node); } }
public void ProcessorInit(TraceData data) { executionCalls = data.ExecutionPath; allCalls = data.AllExecutionCalls; }
public void ProcessorComplete(TraceData td) { td.Statistics.Add(new StatisticItem() { Category = "Execution Path", Label = "Stack Trace Count", Value = StackTraces.Count.ToString() }); }
public void ProcessorInit(TraceData data) { StackTraces = data.StackTraces; }
private void ProcessorLeft_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { leftProgress.Value = 0; if (e.Cancelled) { MessageBox.Show("Trace file processing cancelled."); System.GC.Collect(); return; } leftData = (TraceData)e.Result; UIBuilder.BuildExecutionTree(leftData, execTreeLeft, SQLMap, ExecMap, false); btnCopyToRight.Enabled = true; btnLeftSelectAll.Enabled = true; if (leftData != null && rightData != null) { btnCompare.Enabled = true; } System.GC.Collect(); }
private void btnCopyToRight_Click(object sender, EventArgs e) { rightData = leftData; UIBuilder.BuildExecutionTree(rightData, execTreeRight, SQLMap, ExecMap, false); btnRightSelectAll.Enabled = true; if (leftData != null && rightData != null) { btnCompare.Enabled = true; } }
private void openToolStripMenuItem_Click(object sender, EventArgs e) { openFileDialog1.Filter = "Trace Files|*.tracesql;*.twiz"; openFileDialog1.FileName = ""; var result = openFileDialog1.ShowDialog(); executionTree.Nodes.Clear(); sqlListView.Items.Clear(); stackTraceListView.Items.Clear(); detailsBox.Items.Clear(); if (result == DialogResult.OK) { string filename = openFileDialog1.FileName; // Process the file if (TraceDeserializer.IsSerializedData(filename)) { if (TraceDeserializer.IsSerializedVersionSupported(filename)) { sw.Reset(); sw.Start(); traceData = new TraceDeserializer().DeserializeTraceData(new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.None)); UpdateUI(); sw.Stop(); MessageBox.Show("Trace data loaded in " + sw.Elapsed.TotalSeconds + " seconds."); sw.Reset(); } else { MessageBox.Show("This version of Trace Wizard cannot import the serialized data, maybe it was serialized with an older version."); } } else { processor = new TraceProcessor(filename); processor.WorkerReportsProgress = true; processor.WorkerSupportsCancellation = true; processor.ProgressChanged += Processor_ProgressChanged; processor.RunWorkerCompleted += Processor_RunWorkerCompleted; sw.Reset(); sw.Start(); processor.RunWorkerAsync(); } } }
public void ProcessorComplete(TraceData td) { if ((Statements.Count == 0) && currentStatement == null) { return; } /* add final sql statement */ Statements.Add(currentStatement); /* Group them all by Where */ var sqlByWhereList = td.SQLByWhere; var byWheres = Statements.Where(p => p.Type != SQLType.INSERT).GroupBy(p => p.WhereClause).Select( g => new SQLByWhere{ NumberOfCalls = g.Count(), TotalTime = g.Sum(i => i.Duration), WhereClause = g.Key, HasError = g.Count(p => p.IsError) > 0 ? true : false}); foreach (var byW in byWheres) { sqlByWhereList.Add(byW); } var sqlByFromList = td.SQLByFrom; var byFroms = Statements.Where(p => p.Type == SQLType.SELECT || p.Type == SQLType.DELETE).GroupBy(p => p.FromClause).Select(g => new SQLByFrom{ NumberOfCalls = g.Count(), TotalTime = g.Sum(i => i.Duration), FromClause = g.Key, HasError = g.Count(p => p.IsError) > 0 ? true : false }); foreach (var byF in byFroms) { sqlByFromList.Add(byF); } td.Statistics.Add(new StatisticItem() { Category = "SQL Statements", Label = "Total Count", Value = Statements.Count.ToString() }); SQLStatement longest = Statements.OrderBy(s => s.Duration).Reverse().First(); td.Statistics.Add(new StatisticItem() { Category = "SQL Statements", Label = "Longest Execution", Value = longest.Duration.ToString(),Tag = longest }); SQLStatement mostFetches = Statements.OrderBy(s => s.FetchCount).Reverse().First(); td.Statistics.Add(new StatisticItem() { Category = "SQL Statements", Label = "Most Fetches", Value = mostFetches.FetchCount.ToString(), Tag = mostFetches }); }
public void ProcessorInit(TraceData data) { Statements = data.SQLStatements; }