ProfileWindow.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using System.Text.RegularExpressions;
  6. using OpenTK;
  7. using OpenTK.Graphics;
  8. using OpenTK.Graphics.OpenGL;
  9. using OpenTK.Input;
  10. using Ryujinx.Common;
  11. using Ryujinx.Profiler.UI.SharpFontHelpers;
  12. namespace Ryujinx.Profiler.UI
  13. {
  14. public partial class ProfileWindow : GameWindow
  15. {
  16. // List all buttons for index in button array
  17. private enum ButtonIndex
  18. {
  19. TagTitle = 0,
  20. InstantTitle = 1,
  21. AverageTitle = 2,
  22. TotalTitle = 3,
  23. FilterBar = 4,
  24. ShowHideInactive = 5,
  25. Pause = 6,
  26. ChangeDisplay = 7,
  27. // Don't automatically draw after here
  28. ToggleFlags = 8,
  29. Step = 9,
  30. // Update this when new buttons are added.
  31. // These are indexes to the enum list
  32. Autodraw = 8,
  33. Count = 10,
  34. }
  35. // Font service
  36. private FontService _fontService;
  37. // UI variables
  38. private ProfileButton[] _buttons;
  39. private bool _initComplete = false;
  40. private bool _visible = true;
  41. private bool _visibleChanged = true;
  42. private bool _viewportUpdated = true;
  43. private bool _redrawPending = true;
  44. private bool _displayGraph = true;
  45. private bool _displayFlags = true;
  46. private bool _showInactive = true;
  47. private bool _paused = false;
  48. private bool _doStep = false;
  49. // Layout
  50. private const int LineHeight = 16;
  51. private const int TitleHeight = 24;
  52. private const int TitleFontHeight = 16;
  53. private const int LinePadding = 2;
  54. private const int ColumnSpacing = 15;
  55. private const int FilterHeight = 24;
  56. private const int BottomBarHeight = FilterHeight + LineHeight;
  57. // Sorting
  58. private List<KeyValuePair<ProfileConfig, TimingInfo>> _unsortedProfileData;
  59. private IComparer<KeyValuePair<ProfileConfig, TimingInfo>> _sortAction = new ProfileSorters.TagAscending();
  60. // Flag data
  61. private long[] _timingFlagsAverages;
  62. private long[] _timingFlagsLast;
  63. // Filtering
  64. private string _filterText = "";
  65. private bool _regexEnabled = false;
  66. // Scrolling
  67. private float _scrollPos = 0;
  68. private float _minScroll = 0;
  69. private float _maxScroll = 0;
  70. // Profile data storage
  71. private List<KeyValuePair<ProfileConfig, TimingInfo>> _sortedProfileData;
  72. private long _captureTime;
  73. // Input
  74. private bool _backspaceDown = false;
  75. private bool _prevBackspaceDown = false;
  76. private double _backspaceDownTime = 0;
  77. // F35 used as no key
  78. private Key _graphControlKey = Key.F35;
  79. // Event management
  80. private double _updateTimer;
  81. private double _processEventTimer;
  82. private bool _profileUpdated = false;
  83. private readonly object _profileDataLock = new object();
  84. public ProfileWindow()
  85. // Graphics mode enables 2xAA
  86. : base(1280, 720, new GraphicsMode(new ColorFormat(8, 8, 8, 8), 1, 1, 2))
  87. {
  88. Title = "Profiler";
  89. Location = new Point(DisplayDevice.Default.Width - 1280,
  90. (DisplayDevice.Default.Height - 720) - 50);
  91. if (Profile.UpdateRate <= 0)
  92. {
  93. // Perform step regardless of flag type
  94. Profile.RegisterFlagReceiver((t) =>
  95. {
  96. if (!_paused)
  97. {
  98. _doStep = true;
  99. }
  100. });
  101. }
  102. // Large number to force an update on first update
  103. _updateTimer = 0xFFFF;
  104. Init();
  105. // Release context for render thread
  106. Context.MakeCurrent(null);
  107. }
  108. public void ToggleVisible()
  109. {
  110. _visible = !_visible;
  111. _visibleChanged = true;
  112. }
  113. private void SetSort(IComparer<KeyValuePair<ProfileConfig, TimingInfo>> filter)
  114. {
  115. _sortAction = filter;
  116. _profileUpdated = true;
  117. }
  118. #region OnLoad
  119. /// <summary>
  120. /// Setup OpenGL and load resources
  121. /// </summary>
  122. public void Init()
  123. {
  124. GL.ClearColor(Color.Black);
  125. _fontService = new FontService();
  126. _fontService.InitializeTextures();
  127. _fontService.UpdateScreenHeight(Height);
  128. _buttons = new ProfileButton[(int)ButtonIndex.Count];
  129. _buttons[(int)ButtonIndex.TagTitle] = new ProfileButton(_fontService, () => SetSort(new ProfileSorters.TagAscending()));
  130. _buttons[(int)ButtonIndex.InstantTitle] = new ProfileButton(_fontService, () => SetSort(new ProfileSorters.InstantAscending()));
  131. _buttons[(int)ButtonIndex.AverageTitle] = new ProfileButton(_fontService, () => SetSort(new ProfileSorters.AverageAscending()));
  132. _buttons[(int)ButtonIndex.TotalTitle] = new ProfileButton(_fontService, () => SetSort(new ProfileSorters.TotalAscending()));
  133. _buttons[(int)ButtonIndex.Step] = new ProfileButton(_fontService, () => _doStep = true);
  134. _buttons[(int)ButtonIndex.FilterBar] = new ProfileButton(_fontService, () =>
  135. {
  136. _profileUpdated = true;
  137. _regexEnabled = !_regexEnabled;
  138. });
  139. _buttons[(int)ButtonIndex.ShowHideInactive] = new ProfileButton(_fontService, () =>
  140. {
  141. _profileUpdated = true;
  142. _showInactive = !_showInactive;
  143. });
  144. _buttons[(int)ButtonIndex.Pause] = new ProfileButton(_fontService, () =>
  145. {
  146. _profileUpdated = true;
  147. _paused = !_paused;
  148. });
  149. _buttons[(int)ButtonIndex.ToggleFlags] = new ProfileButton(_fontService, () =>
  150. {
  151. _displayFlags = !_displayFlags;
  152. _redrawPending = true;
  153. });
  154. _buttons[(int)ButtonIndex.ChangeDisplay] = new ProfileButton(_fontService, () =>
  155. {
  156. _displayGraph = !_displayGraph;
  157. _redrawPending = true;
  158. });
  159. Visible = _visible;
  160. }
  161. #endregion
  162. #region OnResize
  163. /// <summary>
  164. /// Respond to resize events
  165. /// </summary>
  166. /// <param name="e">Contains information on the new GameWindow size.</param>
  167. /// <remarks>There is no need to call the base implementation.</remarks>
  168. protected override void OnResize(EventArgs e)
  169. {
  170. _viewportUpdated = true;
  171. }
  172. #endregion
  173. #region OnClose
  174. /// <summary>
  175. /// Intercept close event and hide instead
  176. /// </summary>
  177. protected override void OnClosing(CancelEventArgs e)
  178. {
  179. // Hide window
  180. _visible = false;
  181. _visibleChanged = true;
  182. // Cancel close
  183. e.Cancel = true;
  184. base.OnClosing(e);
  185. }
  186. #endregion
  187. #region OnUpdateFrame
  188. /// <summary>
  189. /// Profile Update Loop
  190. /// </summary>
  191. /// <param name="e">Contains timing information.</param>
  192. /// <remarks>There is no need to call the base implementation.</remarks>
  193. public void Update(FrameEventArgs e)
  194. {
  195. if (_visibleChanged)
  196. {
  197. Visible = _visible;
  198. _visibleChanged = false;
  199. }
  200. // Backspace handling
  201. if (_backspaceDown)
  202. {
  203. if (!_prevBackspaceDown)
  204. {
  205. _backspaceDownTime = 0;
  206. FilterBackspace();
  207. }
  208. else
  209. {
  210. _backspaceDownTime += e.Time;
  211. if (_backspaceDownTime > 0.3)
  212. {
  213. _backspaceDownTime -= 0.05;
  214. FilterBackspace();
  215. }
  216. }
  217. }
  218. _prevBackspaceDown = _backspaceDown;
  219. // Get timing data if enough time has passed
  220. _updateTimer += e.Time;
  221. if (_doStep || ((Profile.UpdateRate > 0) && (!_paused && (_updateTimer > Profile.UpdateRate))))
  222. {
  223. _updateTimer = 0;
  224. _captureTime = PerformanceCounter.ElapsedTicks;
  225. _timingFlags = Profile.GetTimingFlags();
  226. _doStep = false;
  227. _profileUpdated = true;
  228. _unsortedProfileData = Profile.GetProfilingData();
  229. (_timingFlagsAverages, _timingFlagsLast) = Profile.GetTimingAveragesAndLast();
  230. }
  231. // Filtering
  232. if (_profileUpdated)
  233. {
  234. lock (_profileDataLock)
  235. {
  236. _sortedProfileData = _showInactive ? _unsortedProfileData : _unsortedProfileData.FindAll(kvp => kvp.Value.IsActive);
  237. if (_sortAction != null)
  238. {
  239. _sortedProfileData.Sort(_sortAction);
  240. }
  241. if (_regexEnabled)
  242. {
  243. try
  244. {
  245. Regex filterRegex = new Regex(_filterText, RegexOptions.IgnoreCase);
  246. if (_filterText != "")
  247. {
  248. _sortedProfileData = _sortedProfileData.Where((pair => filterRegex.IsMatch(pair.Key.Search))).ToList();
  249. }
  250. }
  251. catch (ArgumentException argException)
  252. {
  253. // Skip filtering for invalid regex
  254. }
  255. }
  256. else
  257. {
  258. // Regular filtering
  259. _sortedProfileData = _sortedProfileData.Where((pair => pair.Key.Search.ToLower().Contains(_filterText.ToLower()))).ToList();
  260. }
  261. }
  262. _profileUpdated = false;
  263. _redrawPending = true;
  264. _initComplete = true;
  265. }
  266. // Check for events 20 times a second
  267. _processEventTimer += e.Time;
  268. if (_processEventTimer > 0.05)
  269. {
  270. ProcessEvents();
  271. if (_graphControlKey != Key.F35)
  272. {
  273. switch (_graphControlKey)
  274. {
  275. case Key.Left:
  276. _graphPosition += (long) (GraphMoveSpeed * e.Time);
  277. break;
  278. case Key.Right:
  279. _graphPosition = Math.Max(_graphPosition - (long) (GraphMoveSpeed * e.Time), 0);
  280. break;
  281. case Key.Up:
  282. _graphZoom = MathF.Min(_graphZoom + (float) (GraphZoomSpeed * e.Time), 100.0f);
  283. break;
  284. case Key.Down:
  285. _graphZoom = MathF.Max(_graphZoom - (float) (GraphZoomSpeed * e.Time), 1f);
  286. break;
  287. }
  288. _redrawPending = true;
  289. }
  290. _processEventTimer = 0;
  291. }
  292. }
  293. #endregion
  294. #region OnRenderFrame
  295. /// <summary>
  296. /// Profile Render Loop
  297. /// </summary>
  298. /// <remarks>There is no need to call the base implementation.</remarks>
  299. public void Draw()
  300. {
  301. if (!_visible || !_initComplete)
  302. {
  303. return;
  304. }
  305. // Update viewport
  306. if (_viewportUpdated)
  307. {
  308. GL.Viewport(0, 0, Width, Height);
  309. GL.MatrixMode(MatrixMode.Projection);
  310. GL.LoadIdentity();
  311. GL.Ortho(0, Width, 0, Height, 0.0, 4.0);
  312. _fontService.UpdateScreenHeight(Height);
  313. _viewportUpdated = false;
  314. _redrawPending = true;
  315. }
  316. if (!_redrawPending)
  317. {
  318. return;
  319. }
  320. // Frame setup
  321. GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
  322. GL.ClearColor(Color.Black);
  323. _fontService.fontColor = Color.White;
  324. int verticalIndex = 0;
  325. float width;
  326. float maxWidth = 0;
  327. float yOffset = _scrollPos - TitleHeight;
  328. float xOffset = 10;
  329. float timingDataLeft;
  330. float timingWidth;
  331. // Background lines to make reading easier
  332. #region Background Lines
  333. GL.Enable(EnableCap.ScissorTest);
  334. GL.Scissor(0, BottomBarHeight, Width, Height - TitleHeight - BottomBarHeight);
  335. GL.Begin(PrimitiveType.Triangles);
  336. GL.Color3(0.2f, 0.2f, 0.2f);
  337. for (int i = 0; i < _sortedProfileData.Count; i += 2)
  338. {
  339. float top = GetLineY(yOffset, LineHeight, LinePadding, false, i - 1);
  340. float bottom = GetLineY(yOffset, LineHeight, LinePadding, false, i);
  341. // Skip rendering out of bounds bars
  342. if (top < 0 || bottom > Height)
  343. continue;
  344. GL.Vertex2(0, bottom);
  345. GL.Vertex2(0, top);
  346. GL.Vertex2(Width, top);
  347. GL.Vertex2(Width, top);
  348. GL.Vertex2(Width, bottom);
  349. GL.Vertex2(0, bottom);
  350. }
  351. GL.End();
  352. _maxScroll = (LineHeight + LinePadding) * (_sortedProfileData.Count - 1);
  353. #endregion
  354. lock (_profileDataLock)
  355. {
  356. // Display category
  357. #region Category
  358. verticalIndex = 0;
  359. foreach (var entry in _sortedProfileData)
  360. {
  361. if (entry.Key.Category == null)
  362. {
  363. verticalIndex++;
  364. continue;
  365. }
  366. float y = GetLineY(yOffset, LineHeight, LinePadding, true, verticalIndex++);
  367. width = _fontService.DrawText(entry.Key.Category, xOffset, y, LineHeight);
  368. if (width > maxWidth)
  369. {
  370. maxWidth = width;
  371. }
  372. }
  373. GL.Disable(EnableCap.ScissorTest);
  374. width = _fontService.DrawText("Category", xOffset, Height - TitleFontHeight, TitleFontHeight);
  375. if (width > maxWidth)
  376. maxWidth = width;
  377. xOffset += maxWidth + ColumnSpacing;
  378. #endregion
  379. // Display session group
  380. #region Session Group
  381. maxWidth = 0;
  382. verticalIndex = 0;
  383. GL.Enable(EnableCap.ScissorTest);
  384. foreach (var entry in _sortedProfileData)
  385. {
  386. if (entry.Key.SessionGroup == null)
  387. {
  388. verticalIndex++;
  389. continue;
  390. }
  391. float y = GetLineY(yOffset, LineHeight, LinePadding, true, verticalIndex++);
  392. width = _fontService.DrawText(entry.Key.SessionGroup, xOffset, y, LineHeight);
  393. if (width > maxWidth)
  394. {
  395. maxWidth = width;
  396. }
  397. }
  398. GL.Disable(EnableCap.ScissorTest);
  399. width = _fontService.DrawText("Group", xOffset, Height - TitleFontHeight, TitleFontHeight);
  400. if (width > maxWidth)
  401. maxWidth = width;
  402. xOffset += maxWidth + ColumnSpacing;
  403. #endregion
  404. // Display session item
  405. #region Session Item
  406. maxWidth = 0;
  407. verticalIndex = 0;
  408. GL.Enable(EnableCap.ScissorTest);
  409. foreach (var entry in _sortedProfileData)
  410. {
  411. if (entry.Key.SessionItem == null)
  412. {
  413. verticalIndex++;
  414. continue;
  415. }
  416. float y = GetLineY(yOffset, LineHeight, LinePadding, true, verticalIndex++);
  417. width = _fontService.DrawText(entry.Key.SessionItem, xOffset, y, LineHeight);
  418. if (width > maxWidth)
  419. {
  420. maxWidth = width;
  421. }
  422. }
  423. GL.Disable(EnableCap.ScissorTest);
  424. width = _fontService.DrawText("Item", xOffset, Height - TitleFontHeight, TitleFontHeight);
  425. if (width > maxWidth)
  426. maxWidth = width;
  427. xOffset += maxWidth + ColumnSpacing;
  428. _buttons[(int)ButtonIndex.TagTitle].UpdateSize(0, Height - TitleFontHeight, 0, (int)xOffset, TitleFontHeight);
  429. #endregion
  430. // Timing data
  431. timingWidth = Width - xOffset - 370;
  432. timingDataLeft = xOffset;
  433. GL.Scissor((int)xOffset, BottomBarHeight, (int)timingWidth, Height - TitleHeight - BottomBarHeight);
  434. if (_displayGraph)
  435. {
  436. DrawGraph(xOffset, yOffset, timingWidth);
  437. }
  438. else
  439. {
  440. DrawBars(xOffset, yOffset, timingWidth);
  441. }
  442. GL.Scissor(0, BottomBarHeight, Width, Height - TitleHeight - BottomBarHeight);
  443. if (!_displayGraph)
  444. {
  445. _fontService.DrawText("Blue: Instant, Green: Avg, Red: Total", xOffset, Height - TitleFontHeight, TitleFontHeight);
  446. }
  447. xOffset = Width - 360;
  448. // Display timestamps
  449. #region Timestamps
  450. verticalIndex = 0;
  451. long totalInstant = 0;
  452. long totalAverage = 0;
  453. long totalTime = 0;
  454. long totalCount = 0;
  455. GL.Enable(EnableCap.ScissorTest);
  456. foreach (var entry in _sortedProfileData)
  457. {
  458. float y = GetLineY(yOffset, LineHeight, LinePadding, true, verticalIndex++);
  459. _fontService.DrawText($"{GetTimeString(entry.Value.Instant)} ({entry.Value.InstantCount})", xOffset, y, LineHeight);
  460. _fontService.DrawText(GetTimeString(entry.Value.AverageTime), 150 + xOffset, y, LineHeight);
  461. _fontService.DrawText(GetTimeString(entry.Value.TotalTime), 260 + xOffset, y, LineHeight);
  462. totalInstant += entry.Value.Instant;
  463. totalAverage += entry.Value.AverageTime;
  464. totalTime += entry.Value.TotalTime;
  465. totalCount += entry.Value.InstantCount;
  466. }
  467. GL.Disable(EnableCap.ScissorTest);
  468. float yHeight = Height - TitleFontHeight;
  469. _fontService.DrawText("Instant (Count)", xOffset, yHeight, TitleFontHeight);
  470. _buttons[(int)ButtonIndex.InstantTitle].UpdateSize((int)xOffset, (int)yHeight, 0, 130, TitleFontHeight);
  471. _fontService.DrawText("Average", 150 + xOffset, yHeight, TitleFontHeight);
  472. _buttons[(int)ButtonIndex.AverageTitle].UpdateSize((int)(150 + xOffset), (int)yHeight, 0, 130, TitleFontHeight);
  473. _fontService.DrawText("Total (ms)", 260 + xOffset, yHeight, TitleFontHeight);
  474. _buttons[(int)ButtonIndex.TotalTitle].UpdateSize((int)(260 + xOffset), (int)yHeight, 0, Width, TitleFontHeight);
  475. // Totals
  476. yHeight = FilterHeight + 3;
  477. int textHeight = LineHeight - 2;
  478. _fontService.fontColor = new Color(100, 100, 255, 255);
  479. float tempWidth = _fontService.DrawText($"Host {GetTimeString(_timingFlagsLast[(int)TimingFlagType.SystemFrame])} " +
  480. $"({GetTimeString(_timingFlagsAverages[(int)TimingFlagType.SystemFrame])})", 5, yHeight, textHeight);
  481. _fontService.fontColor = Color.Red;
  482. _fontService.DrawText($"Game {GetTimeString(_timingFlagsLast[(int)TimingFlagType.FrameSwap])} " +
  483. $"({GetTimeString(_timingFlagsAverages[(int)TimingFlagType.FrameSwap])})", 15 + tempWidth, yHeight, textHeight);
  484. _fontService.fontColor = Color.White;
  485. _fontService.DrawText($"{GetTimeString(totalInstant)} ({totalCount})", xOffset, yHeight, textHeight);
  486. _fontService.DrawText(GetTimeString(totalAverage), 150 + xOffset, yHeight, textHeight);
  487. _fontService.DrawText(GetTimeString(totalTime), 260 + xOffset, yHeight, textHeight);
  488. #endregion
  489. }
  490. #region Bottom bar
  491. // Show/Hide Inactive
  492. float widthShowHideButton = _buttons[(int)ButtonIndex.ShowHideInactive].UpdateSize($"{(_showInactive ? "Hide" : "Show")} Inactive", 5, 5, 4, 16);
  493. // Play/Pause
  494. float widthPlayPauseButton = _buttons[(int)ButtonIndex.Pause].UpdateSize(_paused ? "Play" : "Pause", 15 + (int)widthShowHideButton, 5, 4, 16) + widthShowHideButton;
  495. // Step
  496. float widthStepButton = widthPlayPauseButton;
  497. if (_paused)
  498. {
  499. widthStepButton += _buttons[(int)ButtonIndex.Step].UpdateSize("Step", (int)(25 + widthPlayPauseButton), 5, 4, 16) + 10;
  500. _buttons[(int)ButtonIndex.Step].Draw();
  501. }
  502. // Change display
  503. float widthChangeDisplay = _buttons[(int)ButtonIndex.ChangeDisplay].UpdateSize($"View: {(_displayGraph ? "Graph" : "Bars")}", 25 + (int)widthStepButton, 5, 4, 16) + widthStepButton;
  504. width = widthChangeDisplay;
  505. if (_displayGraph)
  506. {
  507. width += _buttons[(int) ButtonIndex.ToggleFlags].UpdateSize($"{(_displayFlags ? "Hide" : "Show")} Flags", 35 + (int)widthChangeDisplay, 5, 4, 16) + 10;
  508. _buttons[(int)ButtonIndex.ToggleFlags].Draw();
  509. }
  510. // Filter bar
  511. _fontService.DrawText($"{(_regexEnabled ? "Regex " : "Filter")}: {_filterText}", 35 + width, 7, 16);
  512. _buttons[(int)ButtonIndex.FilterBar].UpdateSize((int)(45 + width), 0, 0, Width, FilterHeight);
  513. #endregion
  514. // Draw buttons
  515. for (int i = 0; i < (int)ButtonIndex.Autodraw; i++)
  516. {
  517. _buttons[i].Draw();
  518. }
  519. // Dividing lines
  520. #region Dividing lines
  521. GL.Color3(Color.White);
  522. GL.Begin(PrimitiveType.Lines);
  523. // Top divider
  524. GL.Vertex2(0, Height -TitleHeight);
  525. GL.Vertex2(Width, Height - TitleHeight);
  526. // Bottom divider
  527. GL.Vertex2(0, FilterHeight);
  528. GL.Vertex2(Width, FilterHeight);
  529. GL.Vertex2(0, BottomBarHeight);
  530. GL.Vertex2(Width, BottomBarHeight);
  531. // Bottom vertical dividers
  532. GL.Vertex2(widthShowHideButton + 10, 0);
  533. GL.Vertex2(widthShowHideButton + 10, FilterHeight);
  534. GL.Vertex2(widthPlayPauseButton + 20, 0);
  535. GL.Vertex2(widthPlayPauseButton + 20, FilterHeight);
  536. if (_paused)
  537. {
  538. GL.Vertex2(widthStepButton + 20, 0);
  539. GL.Vertex2(widthStepButton + 20, FilterHeight);
  540. }
  541. if (_displayGraph)
  542. {
  543. GL.Vertex2(widthChangeDisplay + 30, 0);
  544. GL.Vertex2(widthChangeDisplay + 30, FilterHeight);
  545. }
  546. GL.Vertex2(width + 30, 0);
  547. GL.Vertex2(width + 30, FilterHeight);
  548. // Column dividers
  549. float timingDataTop = Height - TitleHeight;
  550. GL.Vertex2(timingDataLeft, FilterHeight);
  551. GL.Vertex2(timingDataLeft, timingDataTop);
  552. GL.Vertex2(timingWidth + timingDataLeft, FilterHeight);
  553. GL.Vertex2(timingWidth + timingDataLeft, timingDataTop);
  554. GL.End();
  555. #endregion
  556. _redrawPending = false;
  557. SwapBuffers();
  558. }
  559. #endregion
  560. private string GetTimeString(long timestamp)
  561. {
  562. float time = (float)timestamp / PerformanceCounter.TicksPerMillisecond;
  563. return (time < 1) ? $"{time * 1000:F3}us" : $"{time:F3}ms";
  564. }
  565. private void FilterBackspace()
  566. {
  567. if (_filterText.Length <= 1)
  568. {
  569. _filterText = "";
  570. }
  571. else
  572. {
  573. _filterText = _filterText.Remove(_filterText.Length - 1, 1);
  574. }
  575. }
  576. private float GetLineY(float offset, float lineHeight, float padding, bool centre, int line)
  577. {
  578. return Height + offset - lineHeight - padding - ((lineHeight + padding) * line) + ((centre) ? padding : 0);
  579. }
  580. protected override void OnKeyPress(KeyPressEventArgs e)
  581. {
  582. _filterText += e.KeyChar;
  583. _profileUpdated = true;
  584. }
  585. protected override void OnKeyDown(KeyboardKeyEventArgs e)
  586. {
  587. switch (e.Key)
  588. {
  589. case Key.BackSpace:
  590. _profileUpdated = _backspaceDown = true;
  591. return;
  592. case Key.Left:
  593. case Key.Right:
  594. case Key.Up:
  595. case Key.Down:
  596. _graphControlKey = e.Key;
  597. return;
  598. }
  599. base.OnKeyUp(e);
  600. }
  601. protected override void OnKeyUp(KeyboardKeyEventArgs e)
  602. {
  603. // Can't go into switch as value isn't constant
  604. if (e.Key == Profile.Controls.Buttons.ToggleProfiler)
  605. {
  606. ToggleVisible();
  607. return;
  608. }
  609. switch (e.Key)
  610. {
  611. case Key.BackSpace:
  612. _backspaceDown = false;
  613. return;
  614. case Key.Left:
  615. case Key.Right:
  616. case Key.Up:
  617. case Key.Down:
  618. _graphControlKey = Key.F35;
  619. return;
  620. }
  621. base.OnKeyUp(e);
  622. }
  623. protected override void OnMouseUp(MouseButtonEventArgs e)
  624. {
  625. foreach (ProfileButton button in _buttons)
  626. {
  627. if (button.ProcessClick(e.X, Height - e.Y))
  628. return;
  629. }
  630. }
  631. protected override void OnMouseWheel(MouseWheelEventArgs e)
  632. {
  633. _scrollPos += e.Delta * -30;
  634. if (_scrollPos < _minScroll)
  635. _scrollPos = _minScroll;
  636. if (_scrollPos > _maxScroll)
  637. _scrollPos = _maxScroll;
  638. _redrawPending = true;
  639. }
  640. }
  641. }