private void saveFileDialog1_FileOk(object sender, CancelEventArgs e) { Regex rx = new Regex(@"[\w\W]+\.opf"); MatchCollection matches = rx.Matches(this.saveFileDialog1.FileName); try { if (matches.Count == 1) { TreeNode node = treeView1.SelectedNode; if (node == rootNode || node == null) { profiler.WriteOffViewFormat(this.saveFileDialog1.FileName); } else { NativeProfilerUnit unit = (NativeProfilerUnit)treeNodes[treeView1.SelectedNode]; profiler.WriteOffViewFormat(this.saveFileDialog1.FileName, unit); } } else { Stream newFile = new FileStream(this.saveFileDialog1.FileName, FileMode.Create, FileAccess.ReadWrite, FileShare.Read); m_tOutput.Seek(0, SeekOrigin.Begin); NativeProfiler.ReadWriteStream(m_tOutput, newFile); m_tOutput.Seek(0, SeekOrigin.End); newFile.Close(); } } catch (Exception localException) { System.Windows.Forms.MessageBox.Show(localException.ToString()); } this.saveFileDialog1.FileName = ""; }
private void button1_Click(object sender, EventArgs e) { // Check if fileName exists; try { FileStream testOpen = new FileStream(this.textBox1.Text, FileMode.Open, FileAccess.ReadWrite, FileShare.Read); testOpen.Close(); if (receivingData == false) { try { Stop_Connection(); if (m_tOutput != null) { m_tOutput.Close(); } tempFileName = @"temp.raw"; m_tOutput = new FileStream(tempFileName, FileMode.Create, FileAccess.ReadWrite, FileShare.Read); port = new SerialPort(textBox3.Text, 115200, Parity.None, 8, StopBits.One); if (port.IsOpen == false) { for (uint index = 0; index < 2; index++) { try { Stop_Connection(); port.Open(); port.DiscardInBuffer(); port.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(port_DataReceived); timeStart = DateTime.Now; receivingData = true; this.button1.Text = "Disconnect"; break; } catch (Exception exception1) { if (index == 1) { MessageBox.Show("Cannot connect to device: " + this.textBox3.Text + " " + exception1.ToString()); } } } } } catch (Exception exception2) { MessageBox.Show("Cannot connect to device: " + this.textBox3.Text + " " + exception2.ToString()); } } else { Stop_Connection(); this.button1.Text = "Connect to Device"; try { localStream = new MemoryStream((int)(m_tOutput.Length)); NativeProfiler.ReadWriteStream(m_tOutput, localStream); if (m_tOutput != null) { m_tOutput.Close(); } m_tOutput = localStream; } catch (OutOfMemoryException) { } LoadRootTree(); } } catch { MessageBox.Show("Cannot not open function names map file " + this.textBox1.Text); } }
public void LoadRootTree() { profiler = new NativeProfiler(m_tOutput, this.textBox1.Text, checkBlocksBeginEnd); if (displayData == false) { return; } progressBarControl1.progressBar1.Value = 0; progressBarControl1.Show(); progressBarControl1.Refresh(); TreeNode node; rootNode = new TreeNode(); TreeNodeCollection nodes = treeView1.Nodes; nodes.Clear(); nodes.Add(rootNode); node = rootNode; uint index = 0; treeNodes = new Hashtable(); uint totalInclRuntime = profiler.GetTotalRuntime(); bool needUpdate = false; while (profiler.GetUnit(index) != null) { NativeProfilerUnit unit = profiler.GetUnit(index); uint percentage = (uint)((long)100 * (long)index / (long)profiler.GetNMax()); if (percentage % 2 == 0 && needUpdate == false) { needUpdate = true; } else if (percentage % 2 != 0 && needUpdate == true) { needUpdate = false; progressBarControl1.progressBar1.Value = (int)(0.5 * progressBarControl1.progressBar1.Maximum * ((double)index / (double)profiler.GetNMax())); progressBarControl1.progressBar1.Refresh(); } uint level = profiler.GetUnitNestingLevel(unit.NItem); if (level <= 1 && profiler.GetUnitExclTime(unit.NItem) > 0) { if (level != 0 && node.GetNodeCount(true) == 0) { uint inclTime = profiler.GetUnitInclTime(unit.NItem); TreeNode newNode = new TreeNode(); newNode.Text = string.Format("{0,-80}{1}", profiler.GetUnitFunctionName(unit), inclTime + " microseconds"); newNode.Name = string.Format("{0,-80}{1}", profiler.GetUnitFunctionName(unit), inclTime + " microseconds"); node.Nodes.Add(newNode); treeNodes[newNode] = unit; } else if (level == 0) { uint inclTime = profiler.GetUnitInclTime(unit.NItem); TreeNode newNode = new TreeNode(); newNode.Text = string.Format("{0,-80}{1}", profiler.GetUnitFunctionName(unit), inclTime + " microseconds"); newNode.Name = string.Format("{0,-80}{1}", profiler.GetUnitFunctionName(unit), inclTime + " microseconds"); rootNode.Nodes.Add(newNode); node = newNode; treeNodes[node] = unit; } } index++; } progressBarControl1.Refresh(); rootNode.Text = string.Format("{0,-80}{1}", "All functions", totalInclRuntime + " microseconds"); rootNode.Name = string.Format("{0,-80}{1}", "All functions", totalInclRuntime + " microseconds"); index = 0; dataGridView1.DataSource = null; dataGridView1.Rows.Clear(); needUpdate = false; while (profiler.GetUnit(index) != null) { NativeProfilerUnit unit = profiler.GetUnit(index); int percentage = (int)((long)100 * (long)index / (long)profiler.GetNMax()); if (percentage % 5 == 0 && needUpdate == false) { needUpdate = true; } else if (percentage % 5 != 0 && needUpdate == true) { needUpdate = false; progressBarControl1.progressBar1.Value = (int)(progressBarControl1.progressBar1.Maximum / 2 + 0.5 * progressBarControl1.progressBar1.Maximum * ((double)index / (double)profiler.GetNMax())); progressBarControl1.progressBar1.Refresh(); } String functionName = ""; for (uint count = 0; count < profiler.GetUnitNestingLevel(unit.NItem); count++) { functionName += " "; } functionName += profiler.GetUnitFunctionName(index); uint inclTime = profiler.GetUnitInclTime(index); uint exclTime = profiler.GetUnitExclTime(index); double inclTimePer = 10000.00 * (double)inclTime / (double)profiler.GetTotalRuntime(); double exclTimePer = 10000.00 * (double)exclTime / (double)profiler.GetTotalRuntime(); inclTimePer = Math.Truncate(inclTimePer) / 100; exclTimePer = Math.Truncate(exclTimePer) / 100; String[] row; if (profiler.GetTotalRuntime() == 0) { row = new String[] { index.ToString(), "", "", (profiler.GetUnitNestingLevel(index)).ToString(), functionName, "", "" }; } else if (inclTime != exclTime) { row = new String[] { index.ToString(), inclTimePer.ToString(), exclTimePer.ToString(), (profiler.GetUnitNestingLevel(index)).ToString(), functionName, inclTime.ToString(), exclTime.ToString() }; } else { row = new String[] { index.ToString(), "", exclTimePer.ToString(), (profiler.GetUnitNestingLevel(index)).ToString(), functionName, "", exclTime.ToString() }; } dataGridView1.Rows.Add(row); index++; } lastSelectedNode = rootNode; dataGridView1.Refresh(); progressBarControl1.Hide(); }