Пример #1
0
        private EventHandle OpenEvent(Frame frame)
        {
            var now = DateTime.UtcNow;

            return(this.EnsureNotFrozen(
                       () =>
            {
                var handle = new EventHandle(this, frame, now);
                var addResult = this.EventHandles.TryAdd(handle, true);
                Debug.Assert(addResult);
                return handle;
            }));
        }
Пример #2
0
        public void CloseEvent(EventHandle eventHandle)
        {
            var now = DateTime.UtcNow;

            this.EnsureNotFrozen(
                () =>
            {
                var frameIndex = this.ProfileContext.TryAddFrame(eventHandle.Frame);
                var openEvent  = new OpenFrameEvent(
                    this.GetTimeValue(eventHandle.StartTime),
                    frameIndex
                    );

                this.Events.Add(openEvent);
                var removeResult = this.EventHandles.TryRemove(eventHandle, out var value);
                Debug.Assert(removeResult && value);

                var epsilon = (long)(1 / this.TickFactor * 0.001);       // 0.001 units

                if (now.Ticks - eventHandle.StartTime.Ticks <= epsilon)
                {
                    // too close, pretend as if it was never happened
                    return;
                }

                // make some gap between this event and whatever event which may be open in the
                // same time, otherwise speedscope may (mistakenly) treat this event as the parent
                // of the upcoming event
                now = now.AddTicks(-epsilon);

                var closeEvent = new CloseFrameEvent(
                    this.GetTimeValue(now),
                    frameIndex);

                this.Events.Add(closeEvent);
            });
        }