public IEnumerable <ProfilerEntry> Parse(Stream stream)
        {
            var hash = new Dictionary <int, Stack <ProfilerEntry> >();

            using (var reader = new BinaryReader(stream))
            {
                while (reader.PeekChar() != -1)
                {
                    var entry = new ProfilerEntry();
                    entry.Type       = (ProfileType)reader.ReadByte();
                    entry.Sequence   = reader.ReadInt32();
                    entry.Time       = reader.ReadDouble();
                    entry.Thread     = reader.ReadInt32();
                    entry.Functionid = reader.ReadInt64();

                    Stack <ProfilerEntry> stack;
                    if (entry.Type == ProfileType.Enter)
                    {
                        var length = reader.ReadInt32();
                        entry.Method  = string.Intern(Encoding.Unicode.GetString(reader.ReadBytes(length * 2)).Replace(", ", ","));
                        length        = reader.ReadInt32();
                        entry.Runtime = string.Intern(Hack.Generics(Encoding.Unicode.GetString(reader.ReadBytes(length * 2)).Replace(", ", ",")));
                        if (!hash.TryGetValue(entry.Thread, out stack))
                        {
                            stack = new Stack <ProfilerEntry>();
                            hash.Add(entry.Thread, stack);
                        }
                        stack.Push(entry);
                    }
                    else if (entry.Type == ProfileType.Leave)
                    {
                        if (!hash.TryGetValue(entry.Thread, out stack))
                        {
                            throw new ProfilerStackUnderFlowException();
                        }
                        var previous = GetCurrentStackPosition(stack, entry);
                        entry.Method  = previous.Method;
                        entry.Runtime = previous.Runtime;
                    }
                    else
                    {
                        //TODO GREG HANDLE TAIL CALLS
                        //if (!hash.TryGetValue(entry.Thread, out stack)) throw new ProfilerStackUnderFlowException();
                        //var current = stack.Peek();
                        //entry.Method = current.Method;
                        //entry.Runtime = current.Runtime;
                    }
                    yield return(entry);
                }
            }
            //this maybe should be here? TODO:GREG
            //if (hash.Values.Any(item => item.Count != 0))
            //{
            //    throw new ProfilerMissingLeavesException();
            //}
        }
 private ProfilerEntry GetCurrentStackPosition(Stack<ProfilerEntry> stack, ProfilerEntry entry)
 {
     while (stack.Count != 0)
     {
         var previous = stack.Pop();
         if (previous.Functionid == entry.Functionid)
             return previous;
     }
     throw new ProfilerStackUnderFlowException();
 }
        private static bool MoveEnumerator(IEnumerator <ProfilerEntry> enumerator, out ProfilerEntry entry)
        {
            var hasmore = enumerator.MoveNext();

            entry = null;
            if (hasmore)
            {
                entry = enumerator.Current;
            }
            return(!hasmore);
        }
 public bool contextChangesWhen(ProfilerEntry entry)
 {
     if (!(entry.IsTest || entry.IsSetup)) return false;
     var space = entry.Runtime.IndexOf(' ');
     if (space == -1) return false;
     var method = entry.Runtime.IndexOf("::");
     var classname = entry.Runtime.Substring(space, method - space);
     if (classname == last) return false;
     last = classname;
     return true;
 }
 private ProfilerEntry GetCurrentStackPosition(Stack <ProfilerEntry> stack, ProfilerEntry entry)
 {
     while (stack.Count != 0)
     {
         var previous = stack.Pop();
         if (previous.Functionid == entry.Functionid)
         {
             return(previous);
         }
     }
     throw new ProfilerStackUnderFlowException();
 }
        public IEnumerable<ProfilerEntry> Parse(Stream stream)
        {
            var hash = new Dictionary<int, Stack<ProfilerEntry>>();
            using(var reader = new BinaryReader(stream))
            {
                while (reader.PeekChar() != -1)
                {
                    var entry = new ProfilerEntry();
                    entry.Type = (ProfileType) reader.ReadByte();
                    entry.Sequence = reader.ReadInt32();
                    entry.Time = reader.ReadDouble(); 
                    entry.Thread = reader.ReadInt32();
                    entry.Functionid = reader.ReadInt64();

                    Stack<ProfilerEntry> stack;
                    if (entry.Type == ProfileType.Enter)
                    {
                        var length = reader.ReadInt32();
                        entry.Method = string.Intern(Encoding.Unicode.GetString(reader.ReadBytes(length * 2)).Replace(", ", ","));
                        length = reader.ReadInt32();
                        entry.Runtime = string.Intern(Hack.Generics(Encoding.Unicode.GetString(reader.ReadBytes(length * 2)).Replace(", ", ",")));
                        if(!hash.TryGetValue(entry.Thread, out stack))
                        {
                            stack = new Stack<ProfilerEntry>();
                            hash.Add(entry.Thread, stack);
                        }
                        stack.Push(entry);
                    } else if(entry.Type == ProfileType.Leave)
                    {
                        if (!hash.TryGetValue(entry.Thread, out stack)) throw new ProfilerStackUnderFlowException();
                        var previous = GetCurrentStackPosition(stack, entry);
                        entry.Method = previous.Method;
                        entry.Runtime = previous.Runtime;
                    } else
                    {
                        //TODO GREG HANDLE TAIL CALLS
                        //if (!hash.TryGetValue(entry.Thread, out stack)) throw new ProfilerStackUnderFlowException();
                        //var current = stack.Peek();
                        //entry.Method = current.Method;
                        //entry.Runtime = current.Runtime;
                    }
                    yield return entry;
                }
            }
            //this maybe should be here? TODO:GREG
            //if (hash.Values.Any(item => item.Count != 0))
            //{
            //    throw new ProfilerMissingLeavesException();
            //}
        }
 private CallChain BuildChain(Stack <CallChain> chain, ProfilerEntry entry, bool unExpected)
 {
     if (entry.Type == ProfileType.Leave || unExpected)
     {
         if (ignoredcount > 0)
         {
             ignoredcount--;
             return(null);
         }
         while (chain.Count > 0)
         {
             var current = chain.Pop();
             if (current.FunctionId == entry.Functionid || chain.Count == 0)
             {
                 current.EndTime = entry.Time;
                 return(current);
             }
         }
     }
     if (entry.Type == ProfileType.Enter)
     {
         if (chain.Count > 200)
         {
             ignoredcount++;
             return(null);
         }
         var chainEntry = new CallChain(entry.Runtime.Replace(", ", ","), entry.Runtime, entry.Functionid);
         chainEntry.StartTime = entry.Time;
         if (chain.Count != 0)
         {
             var parent = chain.Peek();
             if (parent.Children.Count < 1000)
             {
                 parent.AddChild(chainEntry);
             }
         }
         chain.Push(chainEntry);
     }
     return(null);
 }
        public bool contextChangesWhen(ProfilerEntry entry)
        {
            if (!(entry.IsTest || entry.IsSetup))
            {
                return(false);
            }
            var space = entry.Runtime.IndexOf(' ');

            if (space == -1)
            {
                return(false);
            }
            var method    = entry.Runtime.IndexOf("::");
            var classname = entry.Runtime.Substring(space, method - space);

            if (classname == last)
            {
                return(false);
            }
            last = classname;
            return(true);
        }
Example #9
0
 public IEnumerable <ProfilerEntry> Parse(Stream stream)
 {
     using (var reader = new BinaryReader(stream))
     {
         while (reader.PeekChar() != -1)
         {
             var entry = new ProfilerEntry();
             entry.Type       = (ProfileType)reader.ReadByte();
             entry.Sequence   = reader.ReadInt32();
             entry.Thread     = reader.ReadInt32();
             entry.Functionid = reader.ReadInt64();
             entry.Time       = reader.ReadDouble();
             if (entry.Type == ProfileType.Enter)
             {
                 var length = reader.ReadInt32();
                 entry.Method  = new string(reader.ReadChars(length));
                 length        = reader.ReadInt32();
                 entry.Runtime = new string(reader.ReadChars(length));
             }
             yield return(entry);
         }
     }
 }
 public IEnumerable<ProfilerEntry> Parse(Stream stream)
 {
     using(var reader = new BinaryReader(stream))
     {
         while (reader.PeekChar() != -1)
         {
             var entry = new ProfilerEntry();
             entry.Type = (ProfileType) reader.ReadByte();
             entry.Sequence = reader.ReadInt32();
             entry.Thread = reader.ReadInt32();
             entry.Functionid = reader.ReadInt64();
             entry.Time = reader.ReadDouble();
             if (entry.Type == ProfileType.Enter)
             {
                 var length = reader.ReadInt32();
                 entry.Method = new string(reader.ReadChars(length));
                 length = reader.ReadInt32();
                 entry.Runtime = new string(reader.ReadChars(length));
             }
             yield return entry;
         }
     }
 }
 private CallChain BuildChain(Stack<CallChain> chain, ProfilerEntry entry, bool unExpected)
 {
     if(entry.Type == ProfileType.Leave || unExpected)
     {
         if(ignoredcount > 0)
         {
             ignoredcount--;
             return null;
         }
         while (chain.Count > 0)
         {
             var current = chain.Pop();
             if (current.FunctionId == entry.Functionid || chain.Count == 0)
             {
                 current.EndTime = entry.Time;
                 return current;
             }
         }
     }
     if(entry.Type == ProfileType.Enter)
     {
         if(chain.Count > 200)
         {
             ignoredcount++;
             return null;
         }
         var chainEntry = new CallChain(entry.Runtime.Replace(", ", ","),entry.Runtime, entry.Functionid);
         chainEntry.StartTime = entry.Time;
         if (chain.Count != 0)
         {
             var parent = chain.Peek();
             if(parent.Children.Count < 1000)
                  parent.AddChild(chainEntry);
         }
         chain.Push(chainEntry);
     }
     return null;
 }
 private static bool MoveEnumerator(IEnumerator<ProfilerEntry> enumerator, out ProfilerEntry entry)
 {
     var hasmore = enumerator.MoveNext();
     entry = null;
     if(hasmore)
         entry = enumerator.Current;
     return !hasmore;
 }
 public bool contextChangesWhen(ProfilerEntry entry)
 {
     return(entry.IsTest);
 }
 public bool contextChangesWhen(ProfilerEntry entry)
 {
     return entry.IsTest;
 }
 public bool contextChangesWhen(ProfilerEntry entry)
 {
     if (entry.IsSetup)
     {
         return true;
     }
     return entry.Type == ProfileType.Enter && entry.IsFixtureConstructor;
 }
 public void Enrich(ProfilerEntry entry)
 {
     var node = TryGetEfferentCouplingNode(entry.Runtime.Replace('+', '/'));
     entry.Found = node != null;
     if (node != null)
     {
         var tmpname = _testIdentifiers.GetSpecificallyMangledName(node.MemberReference as MethodReference);
         
         if(tmpname != null)
         {
             entry.Method = tmpname;
             entry.Runtime = tmpname;
         }
         entry.IsTest = _testIdentifiers.IsProfilerTest(node.MemberReference as MethodReference);
         entry.IsSetup = _testIdentifiers.IsProfilerSetup(node.MemberReference as MethodReference);
         entry.IsTeardown = _testIdentifiers.IsProfilerTeardown(node.MemberReference as MethodReference);
         entry.IsFixtureConstructor = IsFixtureConstructor(node);
         entry.Reference = node.MemberReference;
     }
 }