public unsafe List <IEvent> BuildChildren(IEvent parent, byte[] data, int offset)
        {
            List <IEvent> events = new List <IEvent>();

            fixed(byte *dataPointer = data)
            {
                byte *parentPointer = dataPointer + offset;
                short parentDepth   = NativeEventHelper.GetDepth(parentPointer);
                short targetDepth   = (short)(parentDepth + 1);

                offset += NativeEventHelper.EventSize;
                for (;
                     offset < data.Length && NativeEventHelper.GetDepth(dataPointer + offset) > parentDepth;
                     offset += NativeEventHelper.EventSize)
                {
                    if (NativeEventHelper.GetDepth(dataPointer + offset) == targetDepth)
                    {
                        IEvent @event = new Event(parent, data, offset, this);
                        events.Add(@event);
                    }
                }
            }

            return(events);
        }
        public unsafe List <IEvent> BuildChildren(IEventTree parent, byte[] data)
        {
            List <IEvent> events = new List <IEvent>();

            fixed(byte *dataPointer = data)
            {
                for (int offset = 0; offset < data.Length; offset += NativeEventHelper.EventSize)
                {
                    if (NativeEventHelper.GetDepth(dataPointer + offset) == 0)
                    {
                        IEvent @event = new Event(parent, data, offset, this);
                        events.Add(@event);
                    }
                }
            }

            return(events);
        }
 private IEventTree[] MergeByThreads(IEnumerable <ISingleEventTree> source)
 {
     IGrouping <uint, ISingleEventTree>[] groups = source.GroupBy(x => x.ThreadUid).ToArray();
     IEventTree[] result = new IEventTree[groups.Length];
     for (int i = 0; i < groups.Length; i++)
     {
         ISingleEventTree[] items        = groups[i].ToArray();
         uint            beginLifetime   = items.Min(x => x.BeginLifetime);
         uint            endLifetime     = items.Max(x => x.EndLifetime);
         uint            threadOsId      = items[0].ThreadOsId;
         uint            threadUid       = items[0].ThreadUid;
         List <byte[]>   data            = items.Select(x => x.GetBinaryData()).ToList();
         uint            hits            = 1;
         uint            time            = (uint)data.Sum(x => NativeEventHelper.GetTime(x));
         byte[]          mergedData      = _agentLibrary.MergeEventTrees(data, NativeEventHelper.CreateEvent(ThreadEventTreeMessage.EventType, 0, threadUid, time, hits));
         ThreadEventTree threadEventTree = new ThreadEventTree(threadUid, threadOsId, beginLifetime, endLifetime, mergedData);
         result[i] = threadEventTree;
     }
     return(result);
 }