Пример #1
0
        private float AddEvent(float x, int maxDepth, int index, EventGPU[] events, ContainerControl parent)
        {
            EventGPU e = events[index];

            double scale = 100.0;
            float  width = (float)(e.Time * scale);

            var control = new Timeline.Event(x, e.Depth, width)
            {
                Name        = e.Name,
                TooltipText = string.Format("{0}, {1} ms", e.Name, ((int)(e.Time * 10000.0) / 10000.0f)),
                Parent      = parent,
            };

            // Spawn sub events
            int childrenDepth = e.Depth + 1;

            if (childrenDepth <= maxDepth)
            {
                // Count sub events total duration
                double subEventsDuration = 0;
                int    tmpIndex          = index;
                while (++tmpIndex < events.Length)
                {
                    int subDepth = events[tmpIndex].Depth;

                    if (subDepth <= e.Depth)
                    {
                        break;
                    }
                    if (subDepth == childrenDepth)
                    {
                        subEventsDuration += events[tmpIndex].Time;
                    }
                }

                // Skip if has no sub events
                if (subEventsDuration > 0)
                {
                    // Apply some offset to sub-events (center them within this event)
                    x += (float)((e.Time - subEventsDuration) * scale) * 0.5f;

                    while (++index < events.Length)
                    {
                        int subDepth = events[index].Depth;

                        if (subDepth <= e.Depth)
                        {
                            break;
                        }
                        if (subDepth == childrenDepth)
                        {
                            x += AddEvent(x, maxDepth, index, events, parent);
                        }
                    }
                }
            }

            return(width);
        }
Пример #2
0
        private void AddEvent(double startTime, int maxDepth, float xOffset, int depthOffset, int index, EventCPU[] events, ContainerControl parent)
        {
            EventCPU e = events[index];

            double length = e.End - e.Start;
            double scale  = 100.0;
            float  x      = (float)((e.Start - startTime) * scale);
            float  width  = (float)(length * scale);

            var control = new Timeline.Event(x + xOffset, e.Depth + depthOffset, width)
            {
                Name        = e.Name,
                TooltipText = string.Format("{0}, {1} ms", e.Name, ((int)(length * 1000.0) / 1000.0f)),
                Parent      = parent,
            };

            // Spawn sub events
            int childrenDepth = e.Depth + 1;

            if (childrenDepth <= maxDepth)
            {
                while (++index < events.Length)
                {
                    int subDepth = events[index].Depth;

                    if (subDepth <= e.Depth)
                    {
                        break;
                    }
                    if (subDepth == childrenDepth)
                    {
                        AddEvent(startTime, maxDepth, xOffset, depthOffset, index, events, parent);
                    }
                }
            }
        }