2012-04-19 14:35:52 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2010 Stuart Carnie
|
2014-01-07 11:25:07 +08:00
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
2018-01-29 16:25:32 +08:00
|
|
|
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2022-07-09 01:23:11 +08:00
|
|
|
https://axis-project.github.io/
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
2015-03-24 20:23:51 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
#ifndef __SUPPORT_CCPROFILING_H__
|
|
|
|
#define __SUPPORT_CCPROFILING_H__
|
2015-03-24 20:23:51 +08:00
|
|
|
/// @cond DO_NOT_SHOW
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-08-21 07:06:34 +08:00
|
|
|
#include <string>
|
|
|
|
#include <chrono>
|
2014-04-30 08:37:36 +08:00
|
|
|
#include "base/ccConfig.h"
|
2014-04-27 01:11:22 +08:00
|
|
|
#include "base/CCRef.h"
|
2014-04-27 01:35:57 +08:00
|
|
|
#include "base/CCMap.h"
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_BEGIN
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2012-06-20 18:09:11 +08:00
|
|
|
/**
|
|
|
|
* @addtogroup global
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
class ProfilingTimer;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
/** Profiler
|
2012-04-19 14:35:52 +08:00
|
|
|
cocos2d builtin profiler.
|
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
To use it, enable set the AX_ENABLE_PROFILERS=1 in the ccConfig.h file
|
2012-04-19 14:35:52 +08:00
|
|
|
*/
|
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
class AX_DLL Profiler : public Ref
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-09-13 11:41:20 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2019-07-22 09:38:46 +08:00
|
|
|
~Profiler();
|
2013-09-13 11:41:20 +08:00
|
|
|
/** display the timers
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2019-07-22 09:38:46 +08:00
|
|
|
void displayTimers();
|
2013-09-13 11:41:20 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2019-07-22 09:38:46 +08:00
|
|
|
bool init();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
public:
|
2021-12-25 10:04:45 +08:00
|
|
|
/** returns the singleton
|
2013-09-13 11:41:20 +08:00
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2019-07-22 09:38:46 +08:00
|
|
|
static Profiler* getInstance();
|
2013-07-12 06:24:23 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
/** Creates and adds a new timer
|
2013-09-13 11:41:20 +08:00
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
ProfilingTimer* createAndAddTimerWithName(const char* timerName);
|
2021-12-25 10:04:45 +08:00
|
|
|
/** releases a timer
|
2013-09-13 11:41:20 +08:00
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2012-04-19 14:35:52 +08:00
|
|
|
void releaseTimer(const char* timerName);
|
2021-12-25 10:04:45 +08:00
|
|
|
/** releases all timers
|
2013-09-13 11:41:20 +08:00
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2012-04-19 14:35:52 +08:00
|
|
|
void releaseAllTimers();
|
|
|
|
|
2013-12-11 17:15:27 +08:00
|
|
|
Map<std::string, ProfilingTimer*> _activeTimers;
|
2012-04-19 14:35:52 +08:00
|
|
|
};
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
class ProfilingTimer : public Ref
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-09-13 11:41:20 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-08-21 07:06:34 +08:00
|
|
|
ProfilingTimer();
|
2013-09-13 11:41:20 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2019-07-22 09:38:46 +08:00
|
|
|
~ProfilingTimer();
|
2013-09-13 11:41:20 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-08-21 07:06:34 +08:00
|
|
|
bool initWithName(const char* timerName);
|
2013-09-13 11:41:20 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-12-13 06:38:12 +08:00
|
|
|
virtual std::string getDescription() const;
|
2013-09-13 11:41:20 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
const std::chrono::high_resolution_clock::time_point& getStartTime() { return _startTime; }
|
2013-08-21 07:06:34 +08:00
|
|
|
|
2013-09-13 11:41:20 +08:00
|
|
|
/** resets the timer properties
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2012-04-19 14:35:52 +08:00
|
|
|
void reset();
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
std::string _nameStr;
|
2013-08-21 07:06:34 +08:00
|
|
|
std::chrono::high_resolution_clock::time_point _startTime;
|
2021-09-02 13:39:28 +08:00
|
|
|
int32_t _averageTime1;
|
|
|
|
int32_t _averageTime2;
|
|
|
|
int32_t minTime;
|
|
|
|
int32_t maxTime;
|
|
|
|
int32_t totalTime;
|
|
|
|
int32_t numberOfCalls;
|
2012-04-19 14:35:52 +08:00
|
|
|
};
|
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
extern void AX_DLL ProfilingBeginTimingBlock(const char* timerName);
|
|
|
|
extern void AX_DLL ProfilingEndTimingBlock(const char* timerName);
|
|
|
|
extern void AX_DLL ProfilingResetTimingBlock(const char* timerName);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* cocos2d profiling categories
|
|
|
|
* used to enable / disable profilers with granularity
|
|
|
|
*/
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
extern bool kProfilerCategorySprite;
|
|
|
|
extern bool kProfilerCategoryBatchSprite;
|
|
|
|
extern bool kProfilerCategoryParticles;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2012-06-20 18:09:11 +08:00
|
|
|
// end of global group
|
|
|
|
/// @}
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_END
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2015-03-24 20:23:51 +08:00
|
|
|
/// @endcond
|
2021-12-25 10:04:45 +08:00
|
|
|
#endif // __SUPPORT_CCPROFILING_H__
|