1
0

CCProfiling.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /****************************************************************************
  2. Copyright (c) 2010 Stuart Carnie
  3. Copyright (c) 2010-2012 cocos2d-x.org
  4. Copyright (c) 2013-2017 Chukong Technologies Inc.
  5. http://www.cocos2d-x.org
  6. Permission is hereby granted, free of charge, to any person obtaining a copy
  7. of this software and associated documentation files (the "Software"), to deal
  8. in the Software without restriction, including without limitation the rights
  9. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. copies of the Software, and to permit persons to whom the Software is
  11. furnished to do so, subject to the following conditions:
  12. The above copyright notice and this permission notice shall be included in
  13. all copies or substantial portions of the Software.
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. THE SOFTWARE.
  21. ****************************************************************************/
  22. #ifndef __SUPPORT_CCPROFILING_H__
  23. #define __SUPPORT_CCPROFILING_H__
  24. /// @cond DO_NOT_SHOW
  25. #include <string>
  26. #include <chrono>
  27. #include "base/ccConfig.h"
  28. #include "base/CCRef.h"
  29. #include "base/CCMap.h"
  30. NS_CC_BEGIN
  31. /**
  32. * @addtogroup global
  33. * @{
  34. */
  35. class ProfilingTimer;
  36. /** Profiler
  37. cocos2d builtin profiler.
  38. To use it, enable set the CC_ENABLE_PROFILERS=1 in the ccConfig.h file
  39. */
  40. class CC_DLL Profiler : public Ref
  41. {
  42. public:
  43. /**
  44. * @js NA
  45. * @lua NA
  46. */
  47. ~Profiler(void);
  48. /** display the timers
  49. * @js NA
  50. * @lua NA
  51. */
  52. void displayTimers(void);
  53. /**
  54. * @js NA
  55. * @lua NA
  56. */
  57. bool init(void);
  58. public:
  59. /** returns the singleton
  60. * @js NA
  61. * @lua NA
  62. */
  63. static Profiler* getInstance(void);
  64. /**
  65. * @js NA
  66. * @lua NA
  67. */
  68. CC_DEPRECATED_ATTRIBUTE static Profiler* sharedProfiler(void);
  69. /** Creates and adds a new timer
  70. * @js NA
  71. * @lua NA
  72. */
  73. ProfilingTimer* createAndAddTimerWithName(const char* timerName);
  74. /** releases a timer
  75. * @js NA
  76. * @lua NA
  77. */
  78. void releaseTimer(const char* timerName);
  79. /** releases all timers
  80. * @js NA
  81. * @lua NA
  82. */
  83. void releaseAllTimers();
  84. Map<std::string, ProfilingTimer*> _activeTimers;
  85. };
  86. class ProfilingTimer : public Ref
  87. {
  88. public:
  89. /**
  90. * @js NA
  91. * @lua NA
  92. */
  93. ProfilingTimer();
  94. /**
  95. * @js NA
  96. * @lua NA
  97. */
  98. ~ProfilingTimer(void);
  99. /**
  100. * @js NA
  101. * @lua NA
  102. */
  103. bool initWithName(const char* timerName);
  104. /**
  105. * @js NA
  106. * @lua NA
  107. */
  108. virtual std::string getDescription() const;
  109. /**
  110. * @js NA
  111. * @lua NA
  112. */
  113. const std::chrono::high_resolution_clock::time_point& getStartTime() { return _startTime; }
  114. /** resets the timer properties
  115. * @js NA
  116. * @lua NA
  117. */
  118. void reset();
  119. std::string _nameStr;
  120. std::chrono::high_resolution_clock::time_point _startTime;
  121. long _averageTime1;
  122. long _averageTime2;
  123. long minTime;
  124. long maxTime;
  125. long totalTime;
  126. long numberOfCalls;
  127. };
  128. extern void CC_DLL ProfilingBeginTimingBlock(const char *timerName);
  129. extern void CC_DLL ProfilingEndTimingBlock(const char *timerName);
  130. extern void CC_DLL ProfilingResetTimingBlock(const char *timerName);
  131. /*
  132. * cocos2d profiling categories
  133. * used to enable / disable profilers with granularity
  134. */
  135. extern bool kProfilerCategorySprite;
  136. extern bool kProfilerCategoryBatchSprite;
  137. extern bool kProfilerCategoryParticles;
  138. // end of global group
  139. /// @}
  140. NS_CC_END
  141. /// @endcond
  142. #endif // __SUPPORT_CCPROFILING_H__