您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

81 行
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 "profiler.h"
  12. #include "timer.h"
  13. /*
  14. * Profiler implementation class
  15. */
  16. static class ProfilerData
  17. {
  18. friend class Profiler;
  19. static int const HISTORY = 30;
  20. public:
  21. ProfilerData()
  22. {
  23. for (int i = 0; i < HISTORY; i++)
  24. history[i] = 0.0f;
  25. frame = 0;
  26. mean = max = 0.0f;
  27. }
  28. private:
  29. float history[HISTORY];
  30. Timer timer;
  31. int frame;
  32. float mean, max;
  33. }
  34. data[Profiler::STAT_COUNT];
  35. /*
  36. * Profiler public class
  37. */
  38. void Profiler::Start(int id)
  39. {
  40. data[id].timer.GetSeconds();
  41. }
  42. void Profiler::Stop(int id)
  43. {
  44. float delta_time = data[id].timer.GetSeconds();
  45. data[id].history[data->frame % ProfilerData::HISTORY] = delta_time;
  46. data[id].frame++;
  47. data[id].mean = 0.0f;
  48. data[id].max = 0.0f;
  49. for (int i = 0; i < ProfilerData::HISTORY; i++)
  50. {
  51. data[id].mean += data[id].history[i];
  52. if (data[id].history[i] > data[id].max)
  53. data[id].max = data[id].history[i];
  54. }
  55. data[id].mean /= ProfilerData::HISTORY;
  56. }
  57. float Profiler::GetMean(int id)
  58. {
  59. return data[id].mean;
  60. }
  61. float Profiler::GetMax(int id)
  62. {
  63. return data[id].max;
  64. }