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.

profiler.cpp 1.5 KiB

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