public void StartingTwiceWithoutStoppingThrowsException() { var profiler = new CodeProfiler(); profiler.Start(ProfilingMode.Rendering, Section); Assert.Throws<CodeProfilerSection.AlreadyStarted>( () => profiler.Start(ProfilingMode.Rendering, Section)); }
public void StartingTwoSections() { var profiler = new CodeProfiler(); profiler.Start(ProfilingMode.Rendering, Section1); profiler.Start(ProfilingMode.Rendering, Section2); Assert.IsTrue( profiler.GetProfilingResultsSummary(ProfilingMode.Rendering).StartsWith(TwoSections)); }
public void StartingTwiceWithoutStoppingThrowsException() { var profiler = new CodeProfiler(); profiler.Start(ProfilingMode.Rendering, Section); Assert.Throws <CodeProfilerSection.AlreadyStarted>( () => profiler.Start(ProfilingMode.Rendering, Section)); }
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; }
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); }
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"); }
private static void RunOneFrameOfProfiling(CodeProfiler profiler) { profiler.BeginFrame(); profiler.Start(ProfilingMode.Rendering, Section); profiler.Stop(ProfilingMode.Rendering, Section); profiler.EndFrame(); }
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."); }
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); }
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); }
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); }
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; }
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"); }
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"); }
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; } }