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

            if (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 (EndingStates.ContainsKey(schedEvent.Switch.PreviousThreadID) &&
                    EndingStates[schedEvent.Switch.PreviousThreadID].Key == LinuxThreadState.CPU_TIME) // Blocking
                {
                    sampleInfo = EndingStates[schedEvent.Switch.PreviousThreadID];

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

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

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

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

            EndingCpuUsage[linuxEvent.CpuNumber] = linuxEvent.ThreadID;
        }
 public bool IsThreadBlocked(int threadId)
 {
     return(EndingStates.ContainsKey(threadId) && EndingStates[threadId].Key == LinuxThreadState.BLOCKED_TIME);
 }
        private void DoMetrics(LinuxEvent linuxEvent)
        {
            KeyValuePair <LinuxThreadState, LinuxEvent> sampleInfo;

            // 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 (EndingStates.ContainsKey(schedEvent.Switch.PreviousThreadID) &&
                    EndingStates[schedEvent.Switch.PreviousThreadID].Key == LinuxThreadState.CPU_TIME) // Blocking
                {
                    // PreviousThreadID is now blocking.  linuxEvent contains its blocking stack, so save it here.
                    // When it unblocks (becomes NextThreadID below, we'll log a sample for it.)
                    EndingStates[schedEvent.Switch.PreviousThreadID] =
                        new KeyValuePair <LinuxThreadState, LinuxEvent>(LinuxThreadState.BLOCKED_TIME, linuxEvent);
                }

                if (EndingStates.TryGetValue(schedEvent.Switch.NextThreadID, out sampleInfo) &&
                    sampleInfo.Key == LinuxThreadState.BLOCKED_TIME) // Unblocking
                {
                    sampleInfo.Value.Period = linuxEvent.TimeMSec - sampleInfo.Value.TimeMSec;
                    AddThreadPeriod(sampleInfo.Value.ThreadID, sampleInfo.Value.TimeMSec, linuxEvent.TimeMSec);
                    StackSource.AddSample(StackSource.CreateSampleFor(sampleInfo.Value, this));

                    EndingStates[schedEvent.Switch.NextThreadID] =
                        new KeyValuePair <LinuxThreadState, LinuxEvent>(LinuxThreadState.CPU_TIME, linuxEvent);
                }
            }
            else if (linuxEvent.Kind == EventKind.ThreadExit)
            {
                ThreadExitEvent exitEvent = (ThreadExitEvent)linuxEvent;
                if (EndingStates.TryGetValue(exitEvent.Exit.ThreadID, out sampleInfo))
                {
                    if (sampleInfo.Key == LinuxThreadState.BLOCKED_TIME) // Blocked on exit
                    {
                        sampleInfo.Value.Period = linuxEvent.TimeMSec - sampleInfo.Value.TimeMSec;
                        AddThreadPeriod(sampleInfo.Value.ThreadID, sampleInfo.Value.TimeMSec, linuxEvent.TimeMSec);
                        StackSource.AddSample(StackSource.CreateSampleFor(sampleInfo.Value, this));
                    }
                    else // Unblocked on exit
                    {
                        linuxEvent.Period = linuxEvent.TimeMSec - sampleInfo.Value.TimeMSec;
                        StackSource.AddSample(StackSource.CreateSampleFor(linuxEvent, this));
                    }

                    // Remove the thread so that any events that might come after the exit are ignored.
                    EndingStates.Remove(exitEvent.Exit.ThreadID);
                }
            }
            else if (linuxEvent.Kind == EventKind.Cpu)
            {
                // Keep track of the last CPU sample for each CPU, and use its timestamp
                // to determine how much weight to give the sample.
                if (LastCpuUsage.TryGetValue(linuxEvent.CpuNumber, out LinuxEvent lastCpuEvent))
                {
                    lastCpuEvent.Period = linuxEvent.TimeMSec - lastCpuEvent.TimeMSec;
                    StackSource.AddSample(StackSource.CreateSampleFor(lastCpuEvent, this));
                }

                LastCpuUsage[linuxEvent.CpuNumber] = linuxEvent;
            }
        }
Example #4
0
        private void UpdateObjects()
        {
            switch (this.playerObj.Type)
            {
                case ObjectType.Human:
                    if (this.playerObj.Y > 230f)
                    {
                        this.playerObj.Y = 230f;
                    }
                    if (this.dragonObj.Y > 230f)
                    {
                        this.dragonObj.Y = 230f;
                    }
                    this.playerObj.Update(null, PointF.Empty, true);
                    this.dragonObj.Update(null, PointF.Empty, true);
                    if (this.pState < 2)
                    {
                        this.playerObj.X += this.grassLayer.ScrollSpeed;
                    }
                    if (this.pState == 1)
                    {
                        this.dragonObj.X += this.grassLayer.ScrollSpeed;
                        this.dragonBehavior.Walk(-0.1f);
                    }
                    if ((this.pState == 0) && (this.playerObj.X < 150f))
                    {
                        this.pState = 1;
                        this.playerBehavior.DoJump();
                        return;
                    }
                    if ((this.pState == 1) && (this.playerObj.YSpeed.CurrentSpeed > 0f))
                    {
                        this.pState = 2;
                        this.playerObj.CurrentAnimation = AnimType.Attacking;
                        this.playerObj.XSpeed.SetSpeed((float) 0f);
                        this.playerObj.YSpeed.SetSpeed((float) 0f);
                        this.dragonObj.XSpeed.SetSpeed((float) 0f);
                        this.dragonObj.YSpeed.SetSpeed((float) 0f);
                        return;
                    }
                    if (this.pState != 2)
                    {
                        break;
                    }
                    if (this.state == EndingStates.Scrolling)
                    {
                        this.nextState = EndingStates.Expanding;
                    }
                    this.dragonObj.XSpeed.SetSpeed((float) 0f);
                    this.dragonObj.YSpeed.SetSpeed((float) 0f);
                    this.dragonObj.CurrentAnimation = AnimType.Attacking;
                    this.playerObj.CurrentAnimation = AnimType.Attacking;
                    if (this.playerObj.X > 50f)
                    {
                        this.playerObj.X--;
                    }
                    if (this.dragonObj.Y > 200f)
                    {
                        this.dragonObj.Y--;
                    }
                    if (this.dragonObj.X >= 260f)
                    {
                        break;
                    }
                    this.dragonObj.X++;
                    return;

                case ObjectType.Lizard:
                    if (this.playerObj.Y > 230f)
                    {
                        this.playerObj.Y = 230f;
                    }
                    if (this.dragonObj.Y > 230f)
                    {
                        this.dragonObj.Y = 230f;
                    }
                    this.playerObj.Update(null, PointF.Empty, true);
                    this.dragonObj.Update(null, PointF.Empty, true);
                    if (this.pState == 0)
                    {
                        this.dragonObj.YSpeed.SetSpeed((float) 0f);
                        this.dragonObj.XSpeed.SetSpeed((float) 1.5f);
                        this.playerObj.XSpeed.SetSpeed((float) 0f);
                        this.playerObj.CurrentDirection = Direction.Left;
                        if (this.dragonObj.X > 64f)
                        {
                            this.pState = 1;
                            return;
                        }
                        break;
                    }
                    if (this.pState == 1)
                    {
                        this.dragonObj.XSpeed.SetSpeed((float) 0f);
                        this.dragonObj.YSpeed.SetSpeed((float) 0f);
                        this.playerObj.X += this.grassLayer.ScrollSpeed;
                        if (this.playerObj.X < 260f)
                        {
                            this.pState = 2;
                            return;
                        }
                        break;
                    }
                    if (this.pState == 2)
                    {
                        this.nextState = EndingStates.Expanding;
                        this.pState = 3;
                        this.playerObj.XSpeed.SetSpeed((float) 0f);
                        this.dragonObj.XSpeed.SetSpeed((float) 0f);
                        return;
                    }
                    if (this.pState != 3)
                    {
                        break;
                    }
                    this.playerObj.YSpeed.SetSpeed((float) 0f);
                    this.playerObj.CurrentAnimation = AnimType.Attacking;
                    return;

                case ObjectType.Mouse:
                    this.playerObj.Update(null, PointF.Empty, true);
                    this.dragonObj.Update(null, PointF.Empty, true);
                    if (this.pState == 0)
                    {
                        this.playerObj.YSpeed.SetSpeed((float) -4f);
                        this.playerObj.X += this.grassLayer.ScrollSpeed;
                        this.dragonObj.XSpeed.SetSpeed((float) 7f);
                        this.dragonObj.YSpeed.SetSpeed((float) 0f);
                        if (this.playerObj.Y <= 64f)
                        {
                            this.pState = 1;
                        }
                    }
                    if (this.pState == 1)
                    {
                        this.playerObj.X += this.grassLayer.ScrollSpeed;
                        this.playerObj.YSpeed.SetSpeed((float) 0f);
                        this.dragonObj.YSpeed.SetSpeed((float) -2f);
                        if (this.dragonObj.X >= 240f)
                        {
                            this.dragonObj.XSpeed.SetSpeed((float) 0f);
                            this.dragonObj.YSpeed.SetSpeed((float) -4f);
                            this.dragonObj.CurrentAnimation = AnimType.Attacking;
                            this.dragonObj.CurrentDirection = Direction.Left;
                        }
                        if (this.playerObj.X <= 64f)
                        {
                            this.nextState = EndingStates.Expanding;
                            this.pState = 2;
                        }
                    }
                    if (this.pState != 2)
                    {
                        break;
                    }
                    this.playerObj.CurrentAnimation = AnimType.Attacking;
                    this.dragonObj.CurrentAnimation = AnimType.Attacking;
                    this.playerObj.XSpeed.SetSpeed((float) 0f);
                    this.playerObj.YSpeed.SetSpeed((float) 0f);
                    this.dragonObj.XSpeed.SetSpeed((float) 0f);
                    this.dragonObj.YSpeed.SetSpeed((float) 0f);
                    return;

                case ObjectType.Piranha:
                    this.playerObj.Update(null, PointF.Empty, true);
                    this.dragonObj.Update(null, PointF.Empty, true);
                    if (this.pState != 0)
                    {
                        if (this.pState == 1)
                        {
                            this.dragonObj.X += this.grassLayer.ScrollSpeed;
                            if (this.playerObj.X > 250f)
                            {
                                this.nextState = EndingStates.Expanding;
                                this.pState = 2;
                                return;
                            }
                            break;
                        }
                        if (this.pState != 2)
                        {
                            break;
                        }
                        this.playerObj.XSpeed.SetSpeed((float) 0f);
                        this.playerObj.YSpeed.SetSpeed((float) 0f);
                        this.playerObj.CurrentAnimation = AnimType.Attacking;
                        return;
                    }
                    if (this.playerObj.YSpeed.CurrentSpeed > -2f)
                    {
                        this.dragonObj.X += this.grassLayer.ScrollSpeed;
                    }
                    if (this.playerObj.YSpeed.CurrentSpeed <= 0f)
                    {
                        break;
                    }
                    this.pState = 1;
                    return;

                case ObjectType.Tiger:
                    this.playerObj.Update(null, PointF.Empty, true);
                    this.dragonObj.Update(null, PointF.Empty, true);
                    if (this.playerObj.Y > 230f)
                    {
                        this.playerObj.Y = 230f;
                    }
                    if (this.dragonObj.Y > 230f)
                    {
                        this.dragonObj.Y = 230f;
                    }
                    if (this.pState == 0)
                    {
                        this.dragonObj.X += this.grassLayer.ScrollSpeed;
                        if (this.dragonObj.X < 270f)
                        {
                            this.pState = 1;
                            return;
                        }
                        break;
                    }
                    if (this.pState == 1)
                    {
                        this.dragonObj.X += this.grassLayer.ScrollSpeed;
                        this.playerObj.X += this.grassLayer.ScrollSpeed;
                        this.playerBehavior.Walk(-4f);
                        if (this.playerObj.X <= (this.dragonObj.X + 32f))
                        {
                            this.dragonObj.CurrentAnimation = AnimType.Attacking;
                            this.playerObj.CurrentAnimation = AnimType.Attacking;
                            this.playerBehavior.DoJump();
                            this.pState = 2;
                            return;
                        }
                        break;
                    }
                    if (this.pState == 2)
                    {
                        this.dragonObj.X += this.grassLayer.ScrollSpeed;
                        this.playerObj.XSpeed.SetSpeed((float) 1f);
                        if (this.dragonObj.X <= 64f)
                        {
                            this.nextState = EndingStates.Expanding;
                            this.pState = 3;
                            return;
                        }
                        break;
                    }
                    if (this.pState != 3)
                    {
                        break;
                    }
                    this.dragonObj.XSpeed.SetSpeed((float) 0f);
                    this.dragonObj.YSpeed.SetSpeed((float) 0f);
                    this.playerObj.XSpeed.SetSpeed((float) 0f);
                    this.playerObj.YSpeed.SetSpeed((float) 0f);
                    return;

                case ObjectType.Hawk:
                    this.playerObj.Update(null, PointF.Empty, true);
                    this.dragonObj.Update(null, PointF.Empty, true);
                    if (this.pState != 0)
                    {
                        if (this.pState == 1)
                        {
                            this.dragonObj.XSpeed.SetSpeed((float) 0f);
                            this.dragonObj.CurrentDirection = Direction.Left;
                            this.playerObj.CurrentAnimation = AnimType.Attacking;
                        }
                        break;
                    }
                    this.playerObj.YSpeed.SetSpeed((float) 0f);
                    this.playerObj.CurrentAnimation = AnimType.Special;
                    this.playerObj.X += this.grassLayer.ScrollSpeed;
                    this.dragonObj.XSpeed.SetSpeed((float) 5.5f);
                    if (this.playerObj.X >= 64f)
                    {
                        break;
                    }
                    this.nextState = EndingStates.Expanding;
                    this.pState = 1;
                    return;

                default:
                    return;
            }
        }
Example #5
0
        public override void Update(bool inFade)
        {
            if (this.nextState != EndingStates.None)
            {
                this.state = this.nextState;
                this.nextState = EndingStates.None;
            }
            switch (this.state)
            {
                case EndingStates.Scrolling:
                    this.cloudLayer.Update(null, PointF.Empty, false);
                    this.castleLayer.Update(null, PointF.Empty, false);
                    foreach (ScrollLayer layer in this.waterLayer)
                    {
                        layer.Update(null, PointF.Empty, false);
                    }
                    this.grassLayer.Update(null, PointF.Empty, false);
                    if ((this.playerObj == null) && this.stateTimer.Update())
                    {
                        this.PlaceObjects();
                    }
                    if (this.playerObj != null)
                    {
                        this.UpdateObjects();
                    }
                    return;

                case EndingStates.Expanding:
                    this.UpdateObjects();
                    this.ExpandRectangle(ref this.blackRec[0], Direction.Left);
                    if (this.ExpandRectangle(ref this.blackRec[1], Direction.Right))
                    {
                        this.stateTimer.Max = 120;
                        this.stateTimer.Timer = this.stateTimer.Max;
                        this.nextState = EndingStates.ShowingNames;
                    }
                    return;

                case EndingStates.ShowingNames:
                    this.UpdateObjects();
                    if (this.playerObj.X <= this.dragonObj.X)
                    {
                        this.playerName.CenterText(this.blackRec[0].Left, this.blackRec[0].Width);
                        this.bossNameTop.CenterText(this.blackRec[1].Left, this.blackRec[1].Width);
                        this.bossNameBottom.CenterText(this.blackRec[1].Left, this.blackRec[1].Width);
                        break;
                    }
                    this.playerName.CenterText(this.blackRec[1].Left, this.blackRec[1].Width);
                    this.bossNameTop.CenterText(this.blackRec[0].Left, this.blackRec[0].Width);
                    this.bossNameBottom.CenterText(this.blackRec[0].Left, this.blackRec[0].Width);
                    break;

                case EndingStates.Contracting:
                    this.ContractRectangle(ref this.blackRec[0]);
                    if (this.ContractRectangle(ref this.blackRec[1]))
                    {
                        if (this.transform <= ObjectType.Hawk)
                        {
                            this.nextState = EndingStates.Scrolling;
                            this.stateTimer.Max = 120;
                            this.stateTimer.Timer = this.stateTimer.Max;
                            return;
                        }
                        GameEngine.Game.GotoSpecialScene(SpecialScenes.Credits);
                    }
                    return;

                default:
                    return;
            }
            if (this.stateTimer.Update())
            {
                this.nextState = EndingStates.Contracting;
                this.playerObj = null;
            }
        }
Example #6
0
 public override void InitScene()
 {
     GameEngine.Framework.PlayMusic(Songs.Credits);
     this.state = EndingStates.Scrolling;
 }