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
|
2016-08-05 09:42:15 +08:00
|
|
|
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
To use it, enable set the CC_ENABLE_PROFILERS=1 in the ccConfig.h file
|
|
|
|
*/
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
class CC_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
|
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
~Profiler(void);
|
2013-09-13 11:41:20 +08:00
|
|
|
/** display the timers
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2012-04-19 14:35:52 +08:00
|
|
|
void displayTimers(void);
|
2013-09-13 11:41:20 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2012-04-19 14:35:52 +08:00
|
|
|
bool init(void);
|
|
|
|
|
|
|
|
public:
|
2013-09-13 11:41:20 +08:00
|
|
|
/** returns the singleton
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-07-12 06:24:23 +08:00
|
|
|
static Profiler* getInstance(void);
|
|
|
|
|
2013-09-13 11:41:20 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-07-12 06:24:23 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE static Profiler* sharedProfiler(void);
|
|
|
|
|
2013-09-13 11:41:20 +08:00
|
|
|
/** Creates and adds a new timer
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
ProfilingTimer* createAndAddTimerWithName(const char* timerName);
|
2013-09-13 11:41:20 +08:00
|
|
|
/** releases a timer
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2012-04-19 14:35:52 +08:00
|
|
|
void releaseTimer(const char* timerName);
|
2013-09-13 11:41:20 +08:00
|
|
|
/** releases all timers
|
|
|
|
* @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
|
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
~ProfilingTimer(void);
|
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;
|
2013-11-05 08:31:36 +08:00
|
|
|
long _averageTime1;
|
|
|
|
long _averageTime2;
|
|
|
|
long minTime;
|
|
|
|
long maxTime;
|
|
|
|
long totalTime;
|
|
|
|
long numberOfCalls;
|
2012-04-19 14:35:52 +08:00
|
|
|
};
|
|
|
|
|
2014-07-15 11:18:05 +08:00
|
|
|
extern void CC_DLL ProfilingBeginTimingBlock(const char *timerName);
|
|
|
|
extern void CC_DLL ProfilingEndTimingBlock(const char *timerName);
|
|
|
|
extern void CC_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
|
|
|
|
/// @}
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
NS_CC_END
|
|
|
|
|
2015-03-24 20:23:51 +08:00
|
|
|
/// @endcond
|
2012-04-19 14:35:52 +08:00
|
|
|
#endif // __SUPPORT_CCPROFILING_H__
|