Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

80 строки
1.3 KiB

  1. //
  2. // Deus Hax (working title)
  3. // Copyright (c) 2010 Sam Hocevar <sam@hocevar.net>
  4. //
  5. #if defined HAVE_CONFIG_H
  6. # include "config.h"
  7. #endif
  8. #include <cstdlib>
  9. #include <cstdio>
  10. #include <stdint.h>
  11. #include "core.h"
  12. /*
  13. * Profiler implementation class
  14. */
  15. static class ProfilerData
  16. {
  17. friend class Profiler;
  18. static int const HISTORY = 30;
  19. public:
  20. ProfilerData()
  21. {
  22. for (int i = 0; i < HISTORY; i++)
  23. history[i] = 0.0f;
  24. frame = 0;
  25. mean = max = 0.0f;
  26. }
  27. private:
  28. float history[HISTORY];
  29. Timer timer;
  30. int frame;
  31. float mean, max;
  32. }
  33. data[Profiler::STAT_COUNT];
  34. /*
  35. * Profiler public class
  36. */
  37. void Profiler::Start(int id)
  38. {
  39. data[id].timer.GetMs();
  40. }
  41. void Profiler::Stop(int id)
  42. {
  43. float deltams = data[id].timer.GetMs();
  44. data[id].history[data->frame % ProfilerData::HISTORY] = deltams;
  45. data[id].frame++;
  46. data[id].mean = 0.0f;
  47. data[id].max = 0.0f;
  48. for (int i = 0; i < ProfilerData::HISTORY; i++)
  49. {
  50. data[id].mean += 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].mean /= ProfilerData::HISTORY;
  55. }
  56. float Profiler::GetMean(int id)
  57. {
  58. return data[id].mean;
  59. }
  60. float Profiler::GetMax(int id)
  61. {
  62. return data[id].max;
  63. }