/// <summary> /// Merges a collection of CallTreeNodes into one CallTreeNode, all values are accumulated. /// </summary> /// <param name="nodes">The collection of nodes to process.</param> /// <returns>A new CallTreeNode.</returns> public override CallTreeNode Merge(IEnumerable <CallTreeNode> nodes) { SQLiteCallTreeNode mergedNode = new SQLiteCallTreeNode(0, null, this.provider); List <int> mergedIds = new List <int>(); bool initialised = false; foreach (SQLiteCallTreeNode node in nodes) { mergedIds.AddRange(node.IdList); mergedNode.callCount += node.callCount; mergedNode.cpuCyclesSpent += node.cpuCyclesSpent; mergedNode.cpuCyclesSpentSelf += node.cpuCyclesSpentSelf; mergedNode.activeCallCount += node.activeCallCount; mergedNode.hasChildren |= node.hasChildren; if (!initialised || mergedNode.nameId == node.nameId) { mergedNode.nameId = node.nameId; } else { mergedNode.nameId = 0; } initialised = true; } mergedIds.Sort(); mergedNode.IdList = mergedIds.ToArray(); return(mergedNode); }
public override bool Equals(CallTreeNode other) { SQLiteCallTreeNode node = other as SQLiteCallTreeNode; if (node != null) { int[] a = this.IdList; int[] b = node.IdList; if (a.Length != b.Length) { return(false); } for (int i = 0; i < a.Length; i++) { if (a[i] != b[i]) { return(false); } } return(true); } return(false); }
/// <summary> /// Merges a collection of CallTreeNodes into one CallTreeNode, all values are accumulated. /// </summary> /// <param name="nodes">The collection of nodes to process.</param> /// <returns>A new CallTreeNode.</returns> public override CallTreeNode Merge(IEnumerable <CallTreeNode> nodes) { SQLiteCallTreeNode mergedNode = new SQLiteCallTreeNode(0, null, this.provider); mergedNode.selectionStartIndex = int.MaxValue; bool initialised = false; foreach (SQLiteCallTreeNode node in nodes) { mergedNode.ids.AddRange(node.ids); mergedNode.hasChildren |= node.hasChildren; mergedNode.selectionStartIndex = Math.Min(mergedNode.selectionStartIndex, node.selectionStartIndex); mergedNode.callCount += node.callCount; mergedNode.activeCallCount += node.activeCallCount; mergedNode.cpuCyclesSpent += node.cpuCyclesSpent; if (!initialised || mergedNode.nameId == node.nameId) { mergedNode.nameId = node.nameId; } else { mergedNode.nameId = 0; } initialised = true; } return(mergedNode); }
internal IQueryable<CallTreeNode> GetCallers(SQLiteCallTreeNode item) { return GetMergedFunctionData(@"id IN( SELECT parentid FROM FunctionData WHERE id IN(" + string.Join(",", item.ids.Select(s => s.ToString()).ToArray()) + ")" + ")", item.selectionStartIndex); }
internal IQueryable <CallTreeNode> GetCallers(SQLiteCallTreeNode item) { return(GetMergedFunctionData(@"id IN( SELECT parentid FROM FunctionData WHERE id IN(" + string.Join(",", item.ids.Select(s => s.ToString()).ToArray()) + ")" + ")", item.selectionStartIndex)); }
internal IQueryable<CallTreeNode> GetChildren(SQLiteCallTreeNode parent) { string[] ids = parent.ids .Select(a => a.ToString(CultureInfo.InvariantCulture)) .ToArray(); return GetMergedFunctionData("parentid IN(" + string.Join(",", ids) + ")", parent.selectionStartIndex); }
internal IQueryable <CallTreeNode> GetChildren(SQLiteCallTreeNode parent) { string[] ids = parent.ids .Select(a => a.ToString(CultureInfo.InvariantCulture)) .ToArray(); return(GetMergedFunctionData("parentid IN(" + string.Join(",", ids) + ")", parent.selectionStartIndex)); }
internal IList <CallTreeNode> RunSQLNodeList(SQLiteQueryProvider queryProvider, string command, bool hasIdList) { List <CallTreeNode> result = new List <CallTreeNode>(); SQLiteCommand cmd; using (LockAndCreateCommand(out cmd)) { cmd.CommandText = command; using (SQLiteDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { SQLiteCallTreeNode node = new SQLiteCallTreeNode(reader.GetInt32(0), null, queryProvider); node.callCount = reader.GetInt32(3); node.cpuCyclesSpent = reader.GetInt64(1); node.cpuCyclesSpentSelf = reader.GetInt64(2); if (hasIdList) { object ids = reader.GetValue(6); if (ids is long) { node.IdList = new int[] { (int)(long)ids }; } else { int[] idList = ids.ToString().Split(',').Select(s => int.Parse(s)).ToArray(); Array.Sort(idList); node.IdList = idList; } } node.hasChildren = reader.GetBoolean(4); node.activeCallCount = reader.GetInt32(5); result.Add(node); } } } return(result); }
IQueryable <CallTreeNode> GetMergedFunctionData(string condition, int startIndex) { IList <CallTreeNode> result = new List <CallTreeNode>(); SQLiteCommand cmd; using (LockAndCreateCommand(out cmd)) { cmd.CommandText = @"SELECT GROUP_CONCAT(id), nameid, SUM(timespent), SUM(callcount), MAX(id != endid) AS hasChildren, SUM((datasetid = " + startIndex + @") AND isActiveAtStart) AS activeCallCount FROM FunctionData WHERE " + condition + @" GROUP BY nameid;" ; using (SQLiteDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { SQLiteCallTreeNode node = new SQLiteCallTreeNode(reader.GetInt32(1), null, this); node.selectionStartIndex = startIndex; node.callCount = reader.GetInt32(3); node.cpuCyclesSpent = (ulong)reader.GetInt64(2); node.ids = reader.GetString(0).Split(',').Select(s => int.Parse(s)).ToList(); node.ids.Sort(); node.hasChildren = reader.GetBoolean(4); node.activeCallCount = reader.GetInt32(5); // Can not do filtering of root and thread nodes here, // because retrieval of names needs access to DB // which is forbidden now (we are inside the lock!) result.Add(node); } } } return(result.AsQueryable()); }
/// <inheritdoc/> public override CallTreeNode GetRoot(int startIndex, int endIndex) { if (startIndex > endIndex) { int help = startIndex; startIndex = endIndex; endIndex = help; } SQLiteCommand cmd; using (LockAndCreateCommand(out cmd)) { cmd.CommandText = @"SELECT id, nameid, callcount, timespent FROM FunctionData WHERE id IN( SELECT rootid FROM DataSets WHERE id BETWEEN " + startIndex + " AND " + endIndex + @" ) ORDER BY id;" ; using (SQLiteDataReader reader = cmd.ExecuteReader()) { SQLiteCallTreeNode root = new SQLiteCallTreeNode(0, null, this); root.selectionStartIndex = startIndex; while (reader.Read()) { root.callCount += reader.GetInt32(2); root.cpuCyclesSpent += (ulong)reader.GetInt64(3); root.ids.Add(reader.GetInt32(0)); } return(root); } } }
public override bool Equals(CallTreeNode other) { if (other is SQLiteCallTreeNode) { SQLiteCallTreeNode node = other as SQLiteCallTreeNode; if (node.ids.Count != this.ids.Count) { return(false); } for (int i = 0; i < this.ids.Count; i++) { if (node.ids[i] != this.ids[i]) { return(false); } } return(true); } return(false); }
/// <summary> /// Merges a collection of CallTreeNodes into one CallTreeNode, all values are accumulated. /// </summary> /// <param name="nodes">The collection of nodes to process.</param> /// <returns>A new CallTreeNode.</returns> public override CallTreeNode Merge(IEnumerable<CallTreeNode> nodes) { SQLiteCallTreeNode mergedNode = new SQLiteCallTreeNode(0, null, this.provider); List<int> mergedIds = new List<int>(); bool initialised = false; foreach (SQLiteCallTreeNode node in nodes) { mergedIds.AddRange(node.IdList); mergedNode.callCount += node.callCount; mergedNode.cpuCyclesSpent += node.cpuCyclesSpent; mergedNode.cpuCyclesSpentSelf += node.cpuCyclesSpentSelf; mergedNode.activeCallCount += node.activeCallCount; mergedNode.hasChildren |= node.hasChildren; if (!initialised || mergedNode.nameId == node.nameId) mergedNode.nameId = node.nameId; else mergedNode.nameId = 0; initialised = true; } mergedIds.Sort(); mergedNode.IdList = mergedIds.ToArray(); return mergedNode; }
internal IList<CallTreeNode> RunSQLNodeList(SQLiteQueryProvider queryProvider, string command, bool hasIdList) { List<CallTreeNode> result = new List<CallTreeNode>(); SQLiteCommand cmd; using (LockAndCreateCommand(out cmd)) { cmd.CommandText = command; using (SQLiteDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { SQLiteCallTreeNode node = new SQLiteCallTreeNode(reader.GetInt32(0), null, queryProvider); node.callCount = reader.GetInt32(3); node.cpuCyclesSpent = reader.GetInt64(1); node.cpuCyclesSpentSelf = reader.GetInt64(2); if (hasIdList) { object ids = reader.GetValue(6); if (ids is long) { node.IdList = new int[] { (int)(long)ids }; } else { int[] idList = ids.ToString().Split(',').Select(s => int.Parse(s)).ToArray(); Array.Sort(idList); node.IdList = idList; } } node.hasChildren = reader.GetBoolean(4); node.activeCallCount = reader.GetInt32(5); result.Add(node); } } } return result; }
/// <summary> /// Merges a collection of CallTreeNodes into one CallTreeNode, all values are accumulated. /// </summary> /// <param name="nodes">The collection of nodes to process.</param> /// <returns>A new CallTreeNode.</returns> public override CallTreeNode Merge(IEnumerable<CallTreeNode> nodes) { SQLiteCallTreeNode mergedNode = new SQLiteCallTreeNode(0, null, this.provider); mergedNode.selectionStartIndex = int.MaxValue; bool initialised = false; foreach (SQLiteCallTreeNode node in nodes) { mergedNode.ids.AddRange(node.ids); mergedNode.hasChildren |= node.hasChildren; mergedNode.selectionStartIndex = Math.Min(mergedNode.selectionStartIndex, node.selectionStartIndex); mergedNode.callCount += node.callCount; mergedNode.activeCallCount += node.activeCallCount; mergedNode.cpuCyclesSpent += node.cpuCyclesSpent; if (!initialised || mergedNode.nameId == node.nameId) mergedNode.nameId = node.nameId; else mergedNode.nameId = 0; initialised = true; } return mergedNode; }
IQueryable<CallTreeNode> GetMergedFunctionData(string condition, int startIndex) { IList<CallTreeNode> result = new List<CallTreeNode>(); SQLiteCommand cmd; using (LockAndCreateCommand(out cmd)) { cmd.CommandText = @"SELECT GROUP_CONCAT(id), nameid, SUM(timespent), SUM(callcount), MAX(id != endid) AS hasChildren, SUM((datasetid = " + startIndex + @") AND isActiveAtStart) AS activeCallCount FROM FunctionData WHERE " + condition + @" GROUP BY nameid;"; using (SQLiteDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { SQLiteCallTreeNode node = new SQLiteCallTreeNode(reader.GetInt32(1), null, this); node.selectionStartIndex = startIndex; node.callCount = reader.GetInt32(3); node.cpuCyclesSpent = (ulong)reader.GetInt64(2); node.ids = reader.GetString(0).Split(',').Select(s => int.Parse(s)).ToList(); node.ids.Sort(); node.hasChildren = reader.GetBoolean(4); node.activeCallCount = reader.GetInt32(5); // Can not do filtering of root and thread nodes here, // because retrieval of names needs access to DB // which is forbidden now (we are inside the lock!) result.Add(node); } } } return result.AsQueryable(); }
/// <inheritdoc/> public override CallTreeNode GetRoot(int startIndex, int endIndex) { if (startIndex > endIndex) { int help = startIndex; startIndex = endIndex; endIndex = help; } SQLiteCommand cmd; using (LockAndCreateCommand(out cmd)) { cmd.CommandText = @"SELECT id, nameid, callcount, timespent FROM FunctionData WHERE id IN( SELECT rootid FROM DataSets WHERE id BETWEEN " + startIndex + " AND " + endIndex + @" ) ORDER BY id;"; using (SQLiteDataReader reader = cmd.ExecuteReader()) { SQLiteCallTreeNode root = new SQLiteCallTreeNode(0, null, this); root.selectionStartIndex = startIndex; while (reader.Read()) { root.callCount += reader.GetInt32(2); root.cpuCyclesSpent += (ulong)reader.GetInt64(3); root.ids.Add(reader.GetInt32(0)); } return root; } } }