Avoid allocating large memory for m_gpu_times in no graphics

This commit is contained in:
Benau 2018-09-13 01:33:29 +08:00
parent 7d561de3fb
commit 60157a33c4
3 changed files with 20 additions and 9 deletions

View File

@ -248,6 +248,7 @@
#include "utils/leak_check.hpp"
#include "utils/log.hpp"
#include "utils/mini_glm.hpp"
#include "utils/profiler.hpp"
#include "utils/translation.hpp"
static void cleanSuperTuxKart();
@ -1879,6 +1880,9 @@ int main(int argc, char *argv[] )
ServerConfig::m_wan_server = false;
ServerConfig::m_validating_player = false;
}
if (!ProfileWorld::isNoGraphics())
profiler.init();
initRest();
input_manager = new InputManager ();

View File

@ -88,15 +88,7 @@ Profiler::Profiler()
m_max_frames = 20 * 120;
m_current_frame = 0;
m_has_wrapped_around = false;
const int MAX_THREADS = 10;
m_all_threads_data.resize(MAX_THREADS);
m_thread_mapping.resize(MAX_THREADS);
// Add this thread to the thread mapping
m_thread_mapping[0] = pthread_self();
m_threads_used = 1;
m_gpu_times.resize(Q_LAST*m_max_frames);
} // Profile
//-----------------------------------------------------------------------------
@ -104,6 +96,21 @@ Profiler::~Profiler()
{
} // ~Profiler
//-----------------------------------------------------------------------------
/** It is split from the constructor so that it can be avoided allocating
* unnecessary memory when the profiler is never used (for example in no
* graphics). */
void Profiler::init()
{
const int MAX_THREADS = 10;
m_all_threads_data.resize(MAX_THREADS);
m_thread_mapping.resize(MAX_THREADS);
// Add this thread to the thread mapping
m_thread_mapping[0] = pthread_self();
m_gpu_times.resize(Q_LAST * m_max_frames);
} // init
//-----------------------------------------------------------------------------
/** Returns a unique index for a thread. If the calling thread is not yet in
* the mapping, it will assign a new unique id to this thread. This function

View File

@ -279,7 +279,7 @@ private:
public:
Profiler();
virtual ~Profiler();
void init();
void pushCPUMarker(const char* name="N/A",
const video::SColor& color=video::SColor());
void popCPUMarker();