You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

82 rivejä
1.5 KiB

  1. //
  2. // Lol Engine
  3. //
  4. // Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net>
  5. // This program is free software; you can redistribute it and/or
  6. // modify it under the terms of the Do What The Fuck You Want To
  7. // Public License, Version 2, as published by Sam Hocevar. See
  8. // http://sam.zoy.org/projects/COPYING.WTFPL for more details.
  9. //
  10. #if defined HAVE_CONFIG_H
  11. # include "config.h"
  12. #endif
  13. #include <cstdlib>
  14. #include <cstdio>
  15. #include <stdint.h>
  16. #include "core.h"
  17. /*
  18. * Profiler implementation class
  19. */
  20. static class ProfilerData
  21. {
  22. friend class Profiler;
  23. static int const HISTORY = 32;
  24. public:
  25. ProfilerData()
  26. {
  27. for (int i = 0; i < HISTORY; i++)
  28. history[i] = 0.0f;
  29. avg = max = 0.0f;
  30. }
  31. private:
  32. float history[HISTORY];
  33. Timer timer;
  34. float avg, max;
  35. }
  36. data[Profiler::STAT_COUNT];
  37. /*
  38. * Profiler public class
  39. */
  40. void Profiler::Start(int id)
  41. {
  42. data[id].timer.GetMs();
  43. }
  44. void Profiler::Stop(int id)
  45. {
  46. float deltams = data[id].timer.GetMs();
  47. data[id].history[Ticker::GetFrameNum() % ProfilerData::HISTORY] = deltams;
  48. data[id].avg = 0.0f;
  49. data[id].max = 0.0f;
  50. for (int i = 0; i < ProfilerData::HISTORY; i++)
  51. {
  52. data[id].avg += data[id].history[i];
  53. if (data[id].history[i] > data[id].max)
  54. data[id].max = data[id].history[i];
  55. }
  56. data[id].avg /= ProfilerData::HISTORY;
  57. }
  58. float Profiler::GetAvg(int id)
  59. {
  60. return data[id].avg;
  61. }
  62. float Profiler::GetMax(int id)
  63. {
  64. return data[id].max;
  65. }