protected override Value GetValueInternal(bool execute = true) { Value value = NullValue.Null; while (true) { bool condition = (bool)Condition.GetValue(Callstack, execute).CastTo <BooleanValue>(true); if (!condition) { break; } Callstack.ResetCallStackFlags(); value = WhileBlock.GetValue(Callstack, execute); if ((Callstack.Flags & CallStack.ReturnFlags.Break) != 0) { break; } if ((Callstack.Flags & CallStack.ReturnFlags.Continue) != 0) { continue; } if ((Callstack.Flags & CallStack.ReturnFlags.Return) != 0) { return(Callstack.Result); } } return(value); }
public static void AddToCallstack(ulong chainID, Callstack.Item item) { Callstack curStack = callstacks.Find(x => x.chainID == chainID); if (curStack == null) { curStack = new Callstack(chainID); callstacks.Insert(0, curStack); } curStack.items.Add(item); if (callstacks.Count > maxCallstacks) { callstacks.RemoveAt(maxCallstacks); } }
public Task<Result> Execute(SocketUserMessage e, ulong id) { Callstack callstack = callstacks.Find (x => x.chainID == id); if (callstack != null) { string message = ""; foreach (Callstack.Item item in callstack.items) { string arguments = " "; for (int i = 0; i < item.arguments.Count; i++) { arguments += item.arguments[i] + (i == item.arguments.Count - 1 ? "" : "; "); } message += Utility.UniformStrings (item.command.helpPrefix + item.command.command + arguments, item.returnObj == null ? "null" : item.returnObj.ToString (), " -> ", 50) + "\n"; } Program.messageControl.SendMessage (e.Channel as ISocketMessageChannel, message, allowInMain, "```"); return TaskResult (message, ""); } return TaskResult (null, "Error - No callstack found for given ID."); }
internal static Callstack AddCallstack(List <Callstack> stacks, Dictionary <CallstackKey, Callstack> callstackMap, CallstackKey key) { Callstack callstackObj; if (callstackMap.TryGetValue(key, out callstackObj)) { callstackObj.m_hitCount++; } else { callstackObj = new Callstack(key.Frames); callstackMap.Add(callstackObj, callstackObj); stacks.Add(callstackObj); } return(callstackObj); }
public override int GetHashCode() { unchecked // overflow is fine, just wrap { var hash = 17; hash *= 23 + LogLevel.GetHashCode(); hash *= 23 + (EnvironmentName != null ? EnvironmentName.GetHashCode() : 0); hash *= 23 + (ClientId.HasValue ? ClientId.GetHashCode() : 0); hash *= 23 + (ClientVersion != null ? ClientVersion.GetHashCode() : 0); hash *= 23 + (MachineName != null ? MachineName.GetHashCode() : 0); hash *= 23 + (TenantId.HasValue ? TenantId.GetHashCode() : 0); hash *= 23 + (UserId.HasValue ? UserId.GetHashCode() : 0); hash *= 23 + (UserName != null ? UserName.GetHashCode() : 0); hash *= 23 + (SessionId.HasValue ? SessionId.GetHashCode() : 0); hash *= 23 + (DeviceId.HasValue ? DeviceId.GetHashCode() : 0); hash *= 23 + (CorrelationId.HasValue ? CorrelationId.GetHashCode() : 0); hash *= 23 + (Source != null ? Source.GetHashCode() : 0); hash *= 23 + (Message != null ? Message.GetHashCode() : 0); hash *= 23 + (Callstack != null ? Callstack.GetHashCode() : 0); return(hash); } }
ThreadData GenerateSamplingThread(FrameGroup group, ThreadData thread) { List <Entry> entries = new List <Entry>(); List <Entry> stack = new List <Entry>(); List <EventFrame> frames = new List <EventFrame>(); Callstack current = new Callstack(); for (int csIndex = 0; csIndex < thread.Callstacks.Count; ++csIndex) { Callstack callstack = thread.Callstacks[csIndex]; if (current.Start == callstack.Start) { continue; } int matchCount = 0; for (int i = 0; i < Math.Min(current.Count, callstack.Count); ++i, ++matchCount) { if (current[i].Name != callstack[i].Name) { break; } } for (int i = matchCount; i < stack.Count; ++i) { stack[i].Finish = callstack.Start; } stack.RemoveRange(matchCount, stack.Count - matchCount); if (stack.Count == 0 && matchCount > 0) { FrameHeader h = new FrameHeader() { Start = entries.Min(e => e.Start), Finish = entries.Max(e => e.Finish), }; frames.Add(new EventFrame(h, entries, group)); entries.Clear(); } for (int i = matchCount; i < callstack.Count; ++i) { Entry entry = new Entry(new EventDescription(callstack[i].Name), callstack.Start, long.MaxValue); entries.Add(entry); stack.Add(entry); } current = callstack; } foreach (Entry e in stack) { e.Finish = current.Start; } FrameHeader header = new FrameHeader() { Start = thread.Callstacks.First().Start, Finish = thread.Callstacks.Last().Start, }; frames.Add(new EventFrame(header, entries, group)); ThreadData result = new ThreadData(null) { Events = frames }; return(result); }
/// <summary> /// Reads in a file that contains the text from the debugger's output window and analyises the tracepoint callstacks /// </summary> /// <param name="path">Path to a file containing the saved output window text</param> /// <param name="filter">Optional delegate to filter out callstacks that are uninteresting</param> /// <param name="stacks">Returns a list of all the callstacks in the output with their hit count</param> /// <param name="callTreeRoots">Returns the roots of the tracepoint call trees</param> static public void ReadFile(string path, CallstackFilter filter, out List <Callstack> stacks, out List <CallTreeNode> callTreeRoots) { int currentLine = 0; int currentRefCount = 0; Dictionary <CallstackFunction, CallTreeNode> callTreeRootMap = new Dictionary <CallstackFunction, CallTreeNode>(); Dictionary <CallstackKey, Callstack> callstackMap = new Dictionary <CallstackKey, Callstack>(); stacks = new List <Callstack>(); StreamReader inputFile = File.OpenText(path); List <string> currentCallstack = null; Regex callstackStartLineFormat = new Regex(@"[0-9]+\:\ ?\t.+(\.dll|\.exe)\!.+"); while (!inputFile.EndOfStream) { currentLine++; string line = inputFile.ReadLine(); if (currentCallstack == null) { Match match = callstackStartLineFormat.Match(line); if (match.Success && match.Index == 0) { string s = line.Substring(line.IndexOf('\t') + 1).Trim(); //Additional code to validate the debug output. Useful when figuring out why a //call stack may have gotten dropped. string refcountStr = line.Substring(0, line.IndexOf(':')); int newRefCount = int.Parse(refcountStr); // mscordbi - ignore the 'InterlockedCompareExchange frame' if (inputFile.EndOfStream) { Debugger.Break(); } currentLine++; line = inputFile.ReadLine(); s = line.Substring(line.IndexOf('\t') + 1).Trim(); // Is an AddRef frame? if (s.EndsWith("::AddRef") || s.Contains("InterlockedIncrement")) { if (newRefCount != currentRefCount + 1) { //Debugger.Break(); } currentRefCount++; } // Is a release frame? else if (s.EndsWith("::Release") || s.Contains("InterlockedDecrement")) { if (newRefCount != currentRefCount - 1) { //Debugger.Break(); } currentRefCount--; } else { Debugger.Break(); } // Create a new call stack currentCallstack = new List <string>(); currentCallstack.Add(s); currentRefCount = newRefCount; } } else { if (IsOnlyWhiteSpace(line)) { CallstackFunction[] frames = CallstackFunction.GetObjects(currentCallstack); CallstackKey key = new CallstackKey(frames); if (filter == null || filter(key)) { Callstack.AddCallstack(stacks, callstackMap, key); CallTreeNode.AddCallstack(callTreeRootMap, key); } currentCallstack = null; } else if (line.Length > 1 && line[0] == '\t') { string s = line.Substring(1); currentCallstack.Add(s); } } } callTreeRoots = new List <CallTreeNode>(callTreeRootMap.Values); }
protected override Value GetValueInternal(bool execute = true) { return(Callstack.GetThis() ?? NullValue.Null); }