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 lines
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://www.wtfpl.net/ for more details.
  9. //
  10. #include <lol/engine-internal.h>
  11. #include <cstdlib>
  12. #include <stdint.h>
  13. namespace lol
  14. {
  15. /*
  16. * Profiler implementation class
  17. */
  18. static class ProfilerData
  19. {
  20. friend class Profiler;
  21. static int const HISTORY = 32;
  22. public:
  23. ProfilerData()
  24. {
  25. for (int i = 0; i < HISTORY; i++)
  26. history[i] = 0.0f;
  27. avg = max = 0.0f;
  28. }
  29. private:
  30. float history[HISTORY];
  31. Timer timer;
  32. float avg, max;
  33. }
  34. data[Profiler::STAT_COUNT];
  35. /*
  36. * Profiler public class
  37. */
  38. void Profiler::Start(int id)
  39. {
  40. data[id].timer.Get();
  41. }
  42. void Profiler::Stop(int id)
  43. {
  44. float seconds = data[id].timer.Get();
  45. data[id].history[Ticker::GetFrameNum() % ProfilerData::HISTORY] = seconds;
  46. data[id].avg = 0.0f;
  47. data[id].max = 0.0f;
  48. for (int i = 0; i < ProfilerData::HISTORY; i++)
  49. {
  50. data[id].avg += data[id].history[i];
  51. if (data[id].history[i] > data[id].max)
  52. data[id].max = data[id].history[i];
  53. }
  54. data[id].avg /= ProfilerData::HISTORY;
  55. }
  56. float Profiler::GetAvg(int id)
  57. {
  58. return data[id].avg;
  59. }
  60. float Profiler::GetMax(int id)
  61. {
  62. return data[id].max;
  63. }
  64. } /* namespace lol */