private void DoMetrics(LinuxEvent linuxEvent)
        {
            KeyValuePair <LinuxThreadState, LinuxEvent> sampleInfo;

            if (this.EndingStates.TryGetValue(linuxEvent.ThreadID, out sampleInfo))
            {
                linuxEvent.Period = linuxEvent.TimeMSec - sampleInfo.Value.TimeMSec;
            }

            // This is check for completed scheduler events, ones that start with prev_comm and have
            //   corresponding next_comm.
            if (linuxEvent.Kind == EventKind.Scheduler)
            {
                SchedulerEvent schedEvent = (SchedulerEvent)linuxEvent;
                if (this.EndingStates.ContainsKey(schedEvent.Switch.PreviousThreadID) &&
                    this.EndingStates[schedEvent.Switch.PreviousThreadID].Key == LinuxThreadState.CPU_TIME) // Blocking
                {
                    sampleInfo = this.EndingStates[schedEvent.Switch.PreviousThreadID];

                    this.EndingStates[schedEvent.Switch.PreviousThreadID] =
                        new KeyValuePair <LinuxThreadState, LinuxEvent>(LinuxThreadState.BLOCKED_TIME, linuxEvent);

                    linuxEvent.Period = linuxEvent.TimeMSec - sampleInfo.Value.TimeMSec;
                }

                if (this.EndingStates.TryGetValue(schedEvent.Switch.NextThreadID, out sampleInfo) &&
                    sampleInfo.Key == LinuxThreadState.BLOCKED_TIME) // Unblocking
                {
                    this.EndingStates[schedEvent.Switch.NextThreadID] =
                        new KeyValuePair <LinuxThreadState, LinuxEvent>(LinuxThreadState.CPU_TIME, linuxEvent);

                    // sampleInfo.Value.Period = linuxEvent.Time - sampleInfo.Value.Time;
                    this.AddThreadPeriod(linuxEvent.ThreadID, sampleInfo.Value.TimeMSec, linuxEvent.TimeMSec);
                }
            }
            else if (linuxEvent.Kind == EventKind.Cpu)
            {
                int threadid;
                if (this.EndingCpuUsage.TryGetValue(linuxEvent.CpuNumber, out threadid) && threadid != linuxEvent.ThreadID) // Unblocking
                {
                    if (this.EndingStates.TryGetValue(threadid, out sampleInfo))
                    {
                        this.EndingStates[threadid] =
                            new KeyValuePair <LinuxThreadState, LinuxEvent>(LinuxThreadState.CPU_TIME, linuxEvent);
                        sampleInfo.Value.Period = linuxEvent.TimeMSec - sampleInfo.Value.TimeMSec;
                        this.AddThreadPeriod(linuxEvent.ThreadID, sampleInfo.Value.TimeMSec, linuxEvent.TimeMSec);
                    }
                }
            }

            this.EndingCpuUsage[linuxEvent.CpuNumber] = linuxEvent.ThreadID;
        }
        /// <summary>
        /// Given a Linux event gotten from the trace, make its corresponding sample for the stack source.
        /// </summary>
        public StackSourceSample CreateSampleFor(LinuxEvent linuxEvent, BlockedTimeAnalyzer blockedTimeAnalyzer)
        {
            IEnumerable <Frame>       frames     = linuxEvent.CallerStacks;
            StackSourceCallStackIndex stackIndex = this.currentStackIndex;

            var sample = new StackSourceSample(this);

            sample.TimeRelativeMSec = linuxEvent.TimeMSec;
            sample.Metric           = 1;

            stackIndex        = this.InternFrames(frames.GetEnumerator(), stackIndex, linuxEvent.ProcessID, linuxEvent.ThreadID, blockedTimeAnalyzer);
            sample.StackIndex = stackIndex;

            return(sample);
        }
        public void UpdateThreadState(LinuxEvent linuxEvent)
        {
            if (this.TimeStamp < linuxEvent.TimeMSec)
            {
                this.TimeStamp = linuxEvent.TimeMSec;
            }

            if (!this.BeginningStates.ContainsKey(linuxEvent.ThreadID))
            {
                this.BeginningStates.Add(
                    linuxEvent.ThreadID,
                    new KeyValuePair <LinuxThreadState, LinuxEvent>(LinuxThreadState.CPU_TIME, linuxEvent));

                this.EndingStates[linuxEvent.ThreadID] = this.BeginningStates[linuxEvent.ThreadID];
            }

            this.DoMetrics(linuxEvent);
        }
 public void LinuxEventSampleAssociation(LinuxEvent linuxEvent, StackSourceSample sample)
 {
     this.LinuxEventSamples[linuxEvent] = sample;
 }