예제 #1
0
		public void StartingTwiceWithoutStoppingThrowsException()
		{
			var profiler = new CodeProfiler();
			profiler.Start(ProfilingMode.Rendering, Section);
			Assert.Throws<CodeProfilerSection.AlreadyStarted>(
				() => profiler.Start(ProfilingMode.Rendering, Section));
		}
		public void StartingOneSection()
		{
			var profiler = new CodeProfiler();
			profiler.Start(ProfilingMode.Rendering, Section1);
			Assert.IsTrue(
				profiler.GetProfilingResultsSummary(ProfilingMode.Rendering).StartsWith(OneSection));
		}
예제 #3
0
		public void ChangeMaximumPollsPerSecond()
		{
			var profiler = new CodeProfiler(5);
			Assert.AreEqual(5, profiler.MaximumPollsPerSecond);
			profiler.MaximumPollsPerSecond = 2;
			Assert.AreEqual(2, profiler.MaximumPollsPerSecond);
		}
예제 #4
0
		public void ChangeResetInterval()
		{
			var profiler = new CodeProfiler(5, 10);
			Assert.AreEqual(10, profiler.ResetInterval);
			profiler.ResetInterval = 2;
			Assert.AreEqual(2, profiler.ResetInterval);
		}
예제 #5
0
        public void StoppingWithoutHavingStartedThrowsException()
        {
            var profiler = new CodeProfiler();

            Assert.Throws <CodeProfiler.SectionNeverStarted>(
                () => profiler.Stop(ProfilingMode.Rendering, Section));
        }
예제 #6
0
 private static void RunOneFrameOfProfiling(CodeProfiler profiler)
 {
     profiler.BeginFrame();
     profiler.Start(ProfilingMode.Rendering, Section);
     profiler.Stop(ProfilingMode.Rendering, Section);
     profiler.EndFrame();
 }
        public void NeverStartingReportsNothingProfiled()
        {
            var profiler = new CodeProfiler();

            Assert.AreEqual(NothingProfiled,
                            profiler.GetProfilingResultsSummary(ProfilingMode.Rendering));
        }
예제 #8
0
        private void Initialize()
        {
            Cards        = new FlashCardCollection();
            OptionDialog = new SelectionDialog();
            UseThread    = true;

            SpellingModeHintInterval        = 5000;
            SpellingModeHintIntervalInitial = 1000;

            CodeProfiler.Start("Load Characters");
            Debug.WriteLine("Loading characters audio...");
            string soundPath = RootPath + "\\System\\Characters\\";

            Characters = new Dictionary <char, NAudioPlayerWrapper>();
            for (char tChar = 'A'; tChar <= 'Z'; tChar++)
            {
                try
                {
                    string audioFile = soundPath + "Char_" + tChar.ToString() + ".mp3";
                    if (File.Exists(audioFile))
                    {
                        NAudioPlayerWrapper charPlayer = new NAudioPlayerWrapper(audioFile);
                        charPlayer.Load();
                        Characters.Add(tChar, charPlayer);
                    }
                    Debug.WriteLine("WARNING: Audio file for char " + tChar + "not found!");
                }
                catch
                {
                    Debug.WriteLine("WARNING: Unable to load audio file for char " + tChar);
                }
            }
            CodeProfiler.Stop("Load Characters");
        }
예제 #9
0
        public void DoesNotResetIfTooShortATimeHasPassed()
        {
            var profiler = new CodeProfiler(1, 1);

            Thread.Sleep(2);
            profiler.BeginFrame();
            Assert.AreEqual(0.0f, profiler.lastResetTime);
        }
예제 #10
0
        public void ChangeMaximumPollsPerSecond()
        {
            var profiler = new CodeProfiler(5);

            Assert.AreEqual(5, profiler.MaximumPollsPerSecond);
            profiler.MaximumPollsPerSecond = 2;
            Assert.AreEqual(2, profiler.MaximumPollsPerSecond);
        }
예제 #11
0
        public void ChangeResetInterval()
        {
            var profiler = new CodeProfiler(5, 10);

            Assert.AreEqual(10, profiler.ResetInterval);
            profiler.ResetInterval = 2;
            Assert.AreEqual(2, profiler.ResetInterval);
        }
예제 #12
0
        public void StartingTwiceWithoutStoppingThrowsException()
        {
            var profiler = new CodeProfiler();

            profiler.Start(ProfilingMode.Rendering, Section);
            Assert.Throws <CodeProfilerSection.AlreadyStarted>(
                () => profiler.Start(ProfilingMode.Rendering, Section));
        }
        public void StartingOneSection()
        {
            var profiler = new CodeProfiler();

            profiler.Start(ProfilingMode.Rendering, Section1);
            Assert.IsTrue(
                profiler.GetProfilingResultsSummary(ProfilingMode.Rendering).StartsWith(OneSection));
        }
예제 #14
0
        public void ResetsIfEnoughTimeHasPassed()
        {
            var profiler = new CodeProfiler(1, 0.0001f);

            Thread.Sleep(2);
            RunOneFrameOfProfiling(profiler);
            profiler.BeginFrame();
            Assert.IsTrue(profiler.lastResetTime > 0.0f);
        }
예제 #15
0
        public void EmptyProfilingSummary()
        {
            var profilingResults          = new CodeProfilingResults(new List <CodeProfilerSection>());
            var profilingResultsFormatter = new CodeProfilingResultsFormatter(profilingResults);
            var profiler = new CodeProfiler();

            Assert.AreEqual(profilingResultsFormatter.Summary,
                            profiler.GetProfilingResultsSummary(ProfilingMode.Rendering));
        }
예제 #16
0
		public void StoppingUpdatesSectionTotalTime()
		{
			var profiler = new CodeProfiler();
			profiler.Start(ProfilingMode.Rendering, Section);
			Thread.Sleep(1);
			profiler.Stop(ProfilingMode.Rendering, Section);
			CodeProfilerSection section = profiler.Sections[2][0];
			Assert.AreEqual(1, section.Calls);
			Assert.IsTrue(section.TotalTime > 0.0f);
		}
예제 #17
0
        public void OnlyProfilesOnceIfTooShortATimeHasPassed()
        {
            var profiler = new CodeProfiler(1);
            int count    = 0;

            profiler.Updated += () => count++;
            RunOneFrameOfProfiling(profiler);
            RunOneFrameOfProfiling(profiler);
            Assert.AreEqual(1, count);
        }
예제 #18
0
 private void LoadCardsData()
 {
     for (int x = 1; x < Cards.Count; x++)
     {
         CodeProfiler.Start("LoadCard " + Cards[x].Name);
         Cards[x].Load();
         CodeProfiler.Stop("LoadCard " + Cards[x].Name);
     }
     Debug.WriteLine("All cards loaded.");
 }
		private static CodeProfiler StartAndStopTwoSections()
		{
			var profiler = new CodeProfiler();
			profiler.Start(ProfilingMode.Rendering, Section1);
			Thread.Sleep(1);
			profiler.Start(ProfilingMode.Rendering, Section2);
			Thread.Sleep(1);
			profiler.Stop(ProfilingMode.Rendering, Section1);
			profiler.Stop(ProfilingMode.Rendering, Section2);
			return profiler;
		}
예제 #20
0
        public void ProfilesTwiceIfEnoughTimeHasPassed()
        {
            var profiler = new CodeProfiler(1000);
            int count    = 0;

            profiler.Updated += () => count++;
            RunOneFrameOfProfiling(profiler);
            Thread.Sleep(2);
            RunOneFrameOfProfiling(profiler);
            Assert.AreEqual(2, count);
        }
예제 #21
0
		public void StartingCreatesASection()
		{
			var profiler = new CodeProfiler();
			profiler.Start(ProfilingMode.Rendering, Section);
			const int SectionNumber = 2;
			CodeProfilerSection section = profiler.Sections[SectionNumber][0];
			Assert.AreEqual(Section, section.Name);
			Assert.AreEqual(0, section.Calls);
			Assert.AreEqual(0.0f, section.TotalTime);
			Assert.AreEqual(1, profiler.SectionMaps[SectionNumber].Count);
			Assert.AreEqual(1, profiler.Sections[SectionNumber].Count);
		}
        private static CodeProfiler StartAndStopTwoSections()
        {
            var profiler = new CodeProfiler();

            profiler.Start(ProfilingMode.Rendering, Section1);
            Thread.Sleep(1);
            profiler.Start(ProfilingMode.Rendering, Section2);
            Thread.Sleep(1);
            profiler.Stop(ProfilingMode.Rendering, Section1);
            profiler.Stop(ProfilingMode.Rendering, Section2);
            return(profiler);
        }
예제 #23
0
        public void ProfilingWhenInactiveDoesNothing()
        {
            var profiler = new CodeProfiler {
                IsActive = false
            };

            profiler.BeginFrame();
            profiler.Start(ProfilingMode.Rendering, Section);
            profiler.Stop(ProfilingMode.Rendering, Section);
            profiler.EndFrame();
            Assert.AreEqual(0, profiler.Sections[(int)ProfilingMode.Rendering].Count);
        }
예제 #24
0
        public void StoppingUpdatesSectionTotalTime()
        {
            var profiler = new CodeProfiler();

            profiler.Start(ProfilingMode.Rendering, Section);
            Thread.Sleep(1);
            profiler.Stop(ProfilingMode.Rendering, Section);
            CodeProfilerSection section = profiler.Sections[2][0];

            Assert.AreEqual(1, section.Calls);
            Assert.IsTrue(section.TotalTime > 0.0f);
        }
예제 #25
0
        public void StartingCreatesASection()
        {
            var profiler = new CodeProfiler();

            profiler.Start(ProfilingMode.Rendering, Section);
            const int           SectionNumber = 2;
            CodeProfilerSection section       = profiler.Sections[SectionNumber][0];

            Assert.AreEqual(Section, section.Name);
            Assert.AreEqual(0, section.Calls);
            Assert.AreEqual(0.0f, section.TotalTime);
            Assert.AreEqual(1, profiler.SectionMaps[SectionNumber].Count);
            Assert.AreEqual(1, profiler.Sections[SectionNumber].Count);
        }
예제 #26
0
    public static CodeProfiler Step(decimal maxExecutionSeconds, string stepName)
    {
        CodeProfiler profiler;

        if (!s_Pool.TryTake(out profiler))
        {
            profiler = new CodeProfiler();
        }

        profiler.StartTicks          = DateTime.Now.Ticks;
        profiler.MaxExecutionSeconds = maxExecutionSeconds;
        profiler.StepName            = stepName;

        return(profiler);
    }
예제 #27
0
        static void Main(string[] args)
        {
            Action action = () =>
            {
                for (int i = 0; i < 10000000; i++)
                {
                    Math.Sqrt(i);
                }
            };

            for (int i = 1; i <= 16; i++)
            {
                Console.WriteLine(i + " thread(s):\t" + CodeProfiler.ProfileAction(action, 100, i));
            }

            Console.Read();
        }
예제 #28
0
        public Layout_01(FlashCardController controller)
        {
            CodeProfiler.Start("Begin Create Layout");
            InitializeComponent();

            Controller = controller;
            SetStyle(ControlStyles.SupportsTransparentBackColor, true);
            Controller.LessonLoaded += new EventHandler(Controller_LessonLoaded);
            Controller.MenuLoad     += new EventHandler(Controller_MenuLoad);

            BackColor = Color.Transparent;
            Stars.DimmedImageIndex = 2;
            InitializeControls();

            BtMenu.Text        = "Menu";
            lbCardCounter.Text = string.Empty;
            CodeProfiler.Stop("Begin Create Layout");

            Synth        = new SpeechSynthesizer();
            Synth.Volume = 100;
            Synth.Rate   = -5;
        }
예제 #29
0
        void Controller_LayoutChanged(object sender, EventArgs e)
        {
            CurrentLayout = Controller.SelectedLayout;
            if (CurrentLayout == null)
            {
                Application.Exit(); return;
            }

            //Speed up to reduce flickering
            Image ptrImage = BackgroundImage;

            BackgroundImage = null;

            CodeProfiler.Start("MainForm::LayoutChanged");
            UserControl ptrControl = (UserControl)CurrentLayout;

            ptrControl.Dock   = DockStyle.Fill;
            ptrControl.Parent = this;

            BackgroundImage = ptrImage;
            CodeProfiler.Stop("MainForm::LayoutChanged");
        }
예제 #30
0
		public void StoppingWithoutHavingStartedThrowsException()
		{
			var profiler = new CodeProfiler();
			Assert.Throws<CodeProfiler.SectionNeverStarted>(
				() => profiler.Stop(ProfilingMode.Rendering, Section));
		}
예제 #31
0
        private void LoadSelectedLesson()
        {
            CodeProfiler.Start("LoadLesson");
            Debug.WriteLine("Loading lesson: " + SelectedLesson);
            KillImageLoader();

            string lessonPath = LessonBasePath + SelectedLesson;

            string[] files = Directory.GetFiles(lessonPath);
            Array.Sort(files);

            //Clean up old cards. Dispose Audio object.
            foreach (FlashCardItem ptrItem in Cards)
            {
                ptrItem.Dispose();
            }
            Cards.Clear();
            FlashCardItem newItem;

            //Load and sort cards.
            CodeProfiler.Start("Generate Items");
            string CardName;
            string CardText;
            string CardImageType;

            foreach (string ptrFile in files)
            {
                //Card Format
                //[CardIndex]#<Card Name>.<Image type>
                CardImageType = Path.GetExtension(ptrFile).ToLower();
                if (!IsImageTypeSupported(CardImageType))
                {
                    continue;
                }

                CardName = CardText = Path.GetFileNameWithoutExtension(ptrFile);
                if (CardName.Contains("#"))
                {
                    CardText = CardName.Substring(CardName.IndexOf("#") + 1);
                }
                newItem = new FlashCardItem(CardName, CardText, ptrFile);
                Debug.WriteLine("> " + newItem.Text);
                Cards.Add(newItem);
            }
            CodeProfiler.Stop("Generate Items");

            //Load card contents.
            if (UseThread)
            {
                //Use threading to load images.
                CardsLoader = new Thread(LoadCardsData);
                CardsLoader.Start();
                CodeProfiler.Start("LoadCard1");
                Cards[0].Load(); //Make sure first image is loaded
                CodeProfiler.Stop("LoadCard1");
            }
            else
            {
                //Single thread operation (Slower) - Keep for debugging purpose
                foreach (FlashCardItem ptrItem in Cards)
                {
                    CodeProfiler.Start("Load Card " + ptrItem.Name);
                    ptrItem.Load();
                    CodeProfiler.Stop("Load Card " + ptrItem.Name);
                }
            }

            Cards.ResetIndex();
            CardsLoader.Join();
            OnLessonLoaded();
            Debug.WriteLine("Lesson loaded.");
            CodeProfiler.Stop("LoadLesson");
        }
예제 #32
0
		public void ProfilesTwiceIfEnoughTimeHasPassed()
		{
			var profiler = new CodeProfiler(1000);
			int count = 0;
			profiler.Updated += () => count++;
			RunOneFrameOfProfiling(profiler);
			Thread.Sleep(2);
			RunOneFrameOfProfiling(profiler);
			Assert.AreEqual(2, count);
		}
예제 #33
0
        public void GetNextCard()
        {
            try
            {
                //Stop hint timer
                #region [ Spelling Mode ]
                if (Controller.Mode == FlashCardMode.Spelling)
                {
                    hintTimer.Enabled = false;
                    Debug.WriteLine("Timer Suspended");
                }
                #endregion

                Controller.Busy = true;
                SelectedCard    = Controller.GetNextCard();
                if (SelectedCard != null)
                {
                    CodeProfiler.Start("GetNextCard-LoadCard");
                    lbCardCounter.Text = Controller.Cards.IndexOf(SelectedCard).ToString() +
                                         " / " + Controller.Cards.Count.ToString();

                    MainPicture.Image = SelectedCard.Image;

                    //In Spelling mode, spell each characters
                    #region [ Spelling Mode Only ]
                    if (Controller.Mode == FlashCardMode.Spelling)
                    {
                        CardLabel.Text = String.Empty;
                        Cursor         = Cursors.WaitCursor;
                        if (SelectedCard.Audio != null)
                        {
                            SelectedCard.Audio.PlaySync();
                        }
                        else
                        {
                            Synth.Speak(SelectedCard.Text);
                        }

                        foreach (char ptrChar in SelectedCard.Text)
                        {
                            Controller.PlayCharSoundSync(ptrChar);
                        }
                        hintTimer.Interval = Controller.SpellingModeHintIntervalInitial;
                        Cursor             = Cursors.Default;
                    }
                    #endregion

                    if (Controller.CaseSensitive)
                    {
                        CardLabel.Text = SelectedCard.Text;
                        ExpectedText   = CardLabel.Text;
                        CurrentIndex   = 0;
                    }
                    else
                    {
                        CardLabel.Text = SelectedCard.Text.ToUpper();
                        ExpectedText   = CardLabel.Text;
                        CurrentIndex   = 0;
                    }

                    //Create puzzle hint
                    #region [ Puzzle Mode Only ]
                    if (Controller.Mode == FlashCardMode.Puzzle)
                    {
                        PuzzleHint.Text = CardLabel.Text;
                        PuzzleHint.Shuffle();
                        for (int x = 0; x < PuzzleHint.Text.Length; x++)
                        {
                            PuzzleHint.HighlightChar(x);
                        }
                    }
                    #endregion

                    MainPicture.Refresh();
                    CardLabel.Refresh();
                    CodeProfiler.Stop("GetNextCard-LoadCard");

                    //Read selected card
                    if (SelectedCard.Audio != null)
                    {
                        SelectedCard.Audio.PlaySync();
                    }
                    else
                    {
                        Synth.Speak(SelectedCard.Text);
                    }

                    //Start hint timer
                    #region [ Spelling Mode Only ]
                    if (Controller.Mode == FlashCardMode.Spelling)
                    {
                        hintTimer.Enabled = Controller.SpellingModePlayHint;
                    }
                    Debug.WriteLine("Timer Enabled");
                    #endregion
                }
            }
            finally { Controller.Busy = false; }
        }
예제 #34
0
		public void DoesNotResetIfTooShortATimeHasPassed()
		{
			var profiler = new CodeProfiler(1, 1);
			Thread.Sleep(2);
			profiler.BeginFrame();
			Assert.AreEqual(0.0f, profiler.lastResetTime);
		}
예제 #35
0
 public static void CodeProfilerStart(string label)
 {
     CodeProfiler.Begin(label);
 }
예제 #36
0
		public void ResetsIfEnoughTimeHasPassed()
		{
			var profiler = new CodeProfiler(1, 0.0001f);
			Thread.Sleep(2);
			RunOneFrameOfProfiling(profiler);
			profiler.BeginFrame();
			Assert.IsTrue(profiler.lastResetTime > 0.0f);
		}
예제 #37
0
		public void EmptyProfilingSummary()
		{
			var profilingResults = new CodeProfilingResults(new List<CodeProfilerSection>());
			var profilingResultsFormatter = new CodeProfilingResultsFormatter(profilingResults);
			var profiler = new CodeProfiler();
			Assert.AreEqual(profilingResultsFormatter.Summary,
				profiler.GetProfilingResultsSummary(ProfilingMode.Rendering));
		}
예제 #38
0
 public static void CodeProfilerEnd(string label)
 {
     CodeProfiler.End(label);
 }
예제 #39
0
		private static void RunOneFrameOfProfiling(CodeProfiler profiler)
		{
			profiler.BeginFrame();
			profiler.Start(ProfilingMode.Rendering, Section);
			profiler.Stop(ProfilingMode.Rendering, Section);
			profiler.EndFrame();
		}
		public void NeverStartingReportsNothingProfiled()
		{
			var profiler = new CodeProfiler();
			Assert.AreEqual(NothingProfiled,
				profiler.GetProfilingResultsSummary(ProfilingMode.Rendering));
		}
예제 #41
0
		public void ProfilingWhenInactiveDoesNothing()
		{
			var profiler = new CodeProfiler { IsActive = false };
			profiler.BeginFrame();
			profiler.Start(ProfilingMode.Rendering, Section);
			profiler.Stop(ProfilingMode.Rendering, Section);
			profiler.EndFrame();
			Assert.AreEqual(0, profiler.Sections[(int)ProfilingMode.Rendering].Count);
		}
예제 #42
0
		public void OnlyProfilesOnceIfTooShortATimeHasPassed()
		{
			var profiler = new CodeProfiler(1);
			int count = 0;
			profiler.Updated += () => count++;
			RunOneFrameOfProfiling(profiler);
			RunOneFrameOfProfiling(profiler);
			Assert.AreEqual(1, count);
		}