Improve profiler a bit

This commit is contained in:
Marianne Gagnon 2014-01-24 18:38:47 -05:00
parent c7b2f82e8f
commit 878d0dcf05
5 changed files with 27 additions and 4 deletions

View File

@ -45,6 +45,7 @@ m_frame_count(0)
{ {
m_curr_time = 0; m_curr_time = 0;
m_prev_time = 0; m_prev_time = 0;
m_throttle_fps = true;
} // MainLoop } // MainLoop
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -78,12 +79,14 @@ float MainLoop::getLimitedDt()
// When in menus, reduce FPS much, it's not necessary to push to the maximum for plain menus // When in menus, reduce FPS much, it's not necessary to push to the maximum for plain menus
const int max_fps = (StateManager::get()->throttleFPS() ? 35 : UserConfigParams::m_max_fps); const int max_fps = (StateManager::get()->throttleFPS() ? 35 : UserConfigParams::m_max_fps);
const int current_fps = (int)(1000.0f/dt); const int current_fps = (int)(1000.0f/dt);
if( current_fps > max_fps && !ProfileWorld::isProfileMode()) if (m_throttle_fps && current_fps > max_fps && !ProfileWorld::isProfileMode())
{ {
int wait_time = 1000/max_fps - 1000/current_fps; int wait_time = 1000/max_fps - 1000/current_fps;
if(wait_time < 1) wait_time = 1; if(wait_time < 1) wait_time = 1;
PROFILER_PUSH_CPU_MARKER("Throttle framerate", 0, 0, 0);
StkTime::sleep(wait_time); StkTime::sleep(wait_time);
PROFILER_POP_CPU_MARKER();
} }
else break; else break;
} }
@ -122,7 +125,9 @@ void MainLoop::run()
if (World::getWorld()) // race is active if world exists if (World::getWorld()) // race is active if world exists
{ {
PROFILER_PUSH_CPU_MARKER("Update race", 255, 0, 255);
updateRace(dt); updateRace(dt);
PROFILER_POP_CPU_MARKER();
} // if race is active } // if race is active
// We need to check again because update_race may have requested // We need to check again because update_race may have requested

View File

@ -29,6 +29,7 @@ class MainLoop
{ {
private: private:
bool m_abort; bool m_abort;
bool m_throttle_fps;
int m_frame_count; int m_frame_count;
Uint32 m_curr_time; Uint32 m_curr_time;
@ -40,6 +41,7 @@ public:
~MainLoop(); ~MainLoop();
void run(); void run();
void abort(); void abort();
void setThrottleFPS(bool throttle) { m_throttle_fps = throttle; }
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
/** Returns true if STK is to be stoppe. */ /** Returns true if STK is to be stoppe. */
bool isAborted() const { return m_abort; } bool isAborted() const { return m_abort; }

View File

@ -36,6 +36,7 @@
#include "physics/stk_dynamics_world.hpp" #include "physics/stk_dynamics_world.hpp"
#include "physics/triangle_mesh.hpp" #include "physics/triangle_mesh.hpp"
#include "tracks/track.hpp" #include "tracks/track.hpp"
#include "utils/profiler.hpp"
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
/** Initialise physics. /** Initialise physics.
@ -135,6 +136,8 @@ void Physics::removeKart(const AbstractKart *kart)
*/ */
void Physics::update(float dt) void Physics::update(float dt)
{ {
PROFILER_PUSH_CPU_MARKER("Physics", 0, 0, 0);
m_physics_loop_active = true; m_physics_loop_active = true;
// Bullet can report the same collision more than once (up to 4 // Bullet can report the same collision more than once (up to 4
// contact points per collision). Additionally, more than one internal // contact points per collision). Additionally, more than one internal
@ -275,6 +278,8 @@ void Physics::update(float dt)
for(unsigned int i=0; i<m_karts_to_delete.size(); i++) for(unsigned int i=0; i<m_karts_to_delete.size(); i++)
removeKart(m_karts_to_delete[i]); removeKart(m_karts_to_delete[i]);
m_karts_to_delete.clear(); m_karts_to_delete.clear();
PROFILER_POP_CPU_MARKER("Physics", 0, 0, 0);
} // update } // update
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View File

@ -26,6 +26,7 @@
#include "physics/irr_debug_drawer.hpp" #include "physics/irr_debug_drawer.hpp"
#include "physics/physics.hpp" #include "physics/physics.hpp"
#include "race/history.hpp" #include "race/history.hpp"
#include "main_loop.hpp"
#include "replay/replay_recorder.hpp" #include "replay/replay_recorder.hpp"
#include "utils/log.hpp" #include "utils/log.hpp"
#include <IGUIEnvironment.h> #include <IGUIEnvironment.h>
@ -69,7 +70,8 @@ enum DebugMenuCommand
DEBUG_POWERUP_SWITCH, DEBUG_POWERUP_SWITCH,
DEBUG_POWERUP_ZIPPER, DEBUG_POWERUP_ZIPPER,
DEBUG_POWERUP_NITRO, DEBUG_POWERUP_NITRO,
DEBUG_TOGGLE_GUI DEBUG_TOGGLE_GUI,
DEBUG_THROTTLE_FPS
}; };
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -133,6 +135,7 @@ bool onEvent(const SEvent &event)
sub->addItem(L"Nitro", DEBUG_POWERUP_NITRO ); sub->addItem(L"Nitro", DEBUG_POWERUP_NITRO );
mnu->addItem(L"Profiler",DEBUG_PROFILER); mnu->addItem(L"Profiler",DEBUG_PROFILER);
mnu->addItem(L"Do not limit FPS", DEBUG_THROTTLE_FPS);
mnu->addItem(L"FPS",DEBUG_FPS); mnu->addItem(L"FPS",DEBUG_FPS);
mnu->addItem(L"Save replay", DEBUG_SAVE_REPLAY); mnu->addItem(L"Save replay", DEBUG_SAVE_REPLAY);
mnu->addItem(L"Save history", DEBUG_SAVE_HISTORY); mnu->addItem(L"Save history", DEBUG_SAVE_HISTORY);
@ -251,6 +254,10 @@ bool onEvent(const SEvent &event)
UserConfigParams::m_profiler_enabled = UserConfigParams::m_profiler_enabled =
!UserConfigParams::m_profiler_enabled; !UserConfigParams::m_profiler_enabled;
} }
else if (cmdID == DEBUG_THROTTLE_FPS)
{
main_loop->setThrottleFPS(false);
}
else if (cmdID == DEBUG_FPS) else if (cmdID == DEBUG_FPS)
{ {
UserConfigParams::m_display_fps = UserConfigParams::m_display_fps =

View File

@ -225,7 +225,8 @@ void Profiler::draw()
} }
} }
const double factor = profiler_width / (end - start); const double duration = end - start;
const double factor = profiler_width / duration;
// Get the mouse pos // Get the mouse pos
core::vector2di mouse_pos = GUIEngine::EventHandler::get()->getMousePos(); core::vector2di mouse_pos = GUIEngine::EventHandler::get()->getMousePos();
@ -281,7 +282,10 @@ void Profiler::draw()
{ {
Marker& m = hovered_markers.top(); Marker& m = hovered_markers.top();
std::ostringstream oss; std::ostringstream oss;
oss << m.name << " [" << (m.end-m.start) << " ms]" << std::endl; oss.precision(4);
oss << m.name << " [" << (m.end - m.start) << " ms / ";
oss.precision(3);
oss << (m.end - m.start)*100.0 / duration << "%]" << std::endl;
text += oss.str().c_str(); text += oss.str().c_str();
hovered_markers.pop(); hovered_markers.pop();
} }