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(); }
private void treeView1_AfterSelect_1(object sender, TreeViewEventArgs e) { if (displayData == false) { return; } progressBarControl1.progressBar1.Value = 0; progressBarControl1.Show(); progressBarControl1.Refresh(); TreeNode node = treeView1.SelectedNode; if (treeView1.SelectedNode != rootNode) { NativeProfilerUnit parentUnit = (NativeProfilerUnit)treeNodes[node]; uint parentLevel = parentUnit.NestingLevel; uint parentIndex = parentUnit.NItem; uint startTime = parentUnit.EntryTime; uint endTime = parentUnit.ReturnTime; uint level = parentLevel; uint index = parentUnit.NItem; uint parentInclTime = profiler.GetUnitInclTime(index); if (parentUnit != null && lastSelectedNode != treeView1.SelectedNode) // If the node has child nodes it was already processed, and we should not add there the same nodes. { dataGridView1.DataSource = null; dataGridView1.Rows.Clear(); dataGridView1.Refresh(); bool needUpdate = false; uint nodesCount = 0; while (profiler.GetUnit(index + nodesCount) != null && profiler.GetUnit(index + nodesCount).EntryTime <= endTime) { nodesCount++; } while (profiler.GetUnit(index) != null && profiler.GetUnit(index).EntryTime <= endTime) { NativeProfilerUnit unit = profiler.GetUnit(index); uint percentage = (uint)((long)100 * (index - parentUnit.NItem) / (long)nodesCount); if (percentage % 5 == 0 && needUpdate == false) { needUpdate = true; } else if (percentage % 5 != 0 && needUpdate == true) { needUpdate = false; progressBarControl1.progressBar1.Value = (int)(0.5 * progressBarControl1.progressBar1.Maximum * ((double)(index - parentUnit.NItem) / (double)nodesCount)); progressBarControl1.progressBar1.Refresh(); } String functionName = ""; for (uint count = 0; count < unit.NestingLevel - parentLevel; count++) { functionName += " "; } functionName += profiler.GetUnitFunctionName(index); uint inclTime = profiler.GetUnitInclTime(index); uint exclTime = profiler.GetUnitExclTime(index); double inclTimePer = 10000.00 * (double)inclTime / (double)(parentInclTime); double exclTimePer = 10000.00 * (double)exclTime / (double)(parentInclTime); inclTimePer = Math.Truncate(inclTimePer) / 100; exclTimePer = Math.Truncate(exclTimePer) / 100; String[] row; if (parentInclTime == 0) { row = new String[] { (index - parentIndex).ToString(), "", "", (profiler.GetUnitNestingLevel(index) - parentLevel).ToString(), functionName, "", "" }; } else if (inclTime != exclTime) { row = new String[] { (index - parentIndex).ToString(), inclTimePer.ToString(), exclTimePer.ToString(), (profiler.GetUnitNestingLevel(index) - parentLevel).ToString(), functionName, inclTime.ToString(), exclTime.ToString() }; } else { row = new String[] { (index - parentIndex).ToString(), "", exclTimePer.ToString(), (profiler.GetUnitNestingLevel(index) - parentLevel).ToString(), functionName, "", exclTime.ToString() }; } dataGridView1.Rows.Add(row); index++; } if (addedTwoLevels[node] == null) { addedTwoLevels[node] = true; node.Nodes.Clear(); index = parentUnit.NItem + 1; needUpdate = false; while (profiler.GetUnit(index) != null && profiler.GetUnit(index).EntryTime <= endTime) { NativeProfilerUnit unit = profiler.GetUnit(index); uint percentage = (uint)((long)100 * (index - parentUnit.NItem) / (long)nodesCount); 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 - parentUnit.NItem) / (double)nodesCount)); progressBarControl1.progressBar1.Refresh(); } if (unit.NestingLevel <= (parentLevel + 2)) { if (profiler.GetUnitExclTime(unit.NItem) > 0) { if (unit.NestingLevel <= level) { for (int count = 0; count <= level - unit.NestingLevel; count++) { node = node.Parent; } uint inclTime = profiler.GetUnitInclTime(unit.NItem); TreeNode tempNode = new TreeNode(); tempNode.Text = string.Format("{0,-80}{1}", profiler.GetUnitFunctionName(index), inclTime + " microseconds"); tempNode.Name = string.Format("{0,-80}{1}", profiler.GetUnitFunctionName(index), inclTime + " microseconds"); node.Nodes.Add(tempNode); node = tempNode; } else { for (int count = 0; count < unit.NestingLevel - level; count++) { TreeNode tempNode = new TreeNode(); tempNode.Text = "unknown function time"; tempNode.Name = "unknown function time"; node.Nodes.Add(tempNode); node = tempNode; } uint inclTime = profiler.GetUnitInclTime(unit.NItem); node.Text = string.Format("{0,-80}{1}", profiler.GetUnitFunctionName(unit), inclTime + " microseconds"); node.Name = string.Format("{0,-80}{1}", profiler.GetUnitFunctionName(unit), inclTime + " microseconds"); } } level = profiler.GetUnitNestingLevel(index); treeNodes[node] = unit; } index++; } } lastSelectedNode = treeView1.SelectedNode; } } else if (lastSelectedNode != rootNode) { uint index = 0; dataGridView1.DataSource = null; dataGridView1.Rows.Clear(); dataGridView1.Refresh(); bool 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 * ((double)index / (double)profiler.GetNMax())); progressBarControl1.progressBar1.Refresh(); } String functionName = ""; for (uint count = 0; count < unit.NestingLevel; 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; } progressBarControl1.Hide(); }