Permalink
Browse files

Added simple profiling code

  • Loading branch information...
TheJosh committed Feb 5, 2014
1 parent 4485aed commit aaaca0c242cf767ca00decbb469a91acdd7e9351
Showing with 52 additions and 7 deletions.
  1. +3 −0 src/game.cpp
  2. +4 −0 src/gamestate.cpp
  3. +0 −5 src/rage.h
  4. +8 −1 src/util/cmdline.cpp
  5. +20 −0 src/util/debug.cpp
  6. +17 −1 src/util/debug.h
View
@@ -95,7 +95,10 @@ void gameLoop(GameState *st, Render *render)
}
}
PROFILE_START(render);
st->render->render();
PROFILE_END(render);
st->audio->play();
}
View
@@ -394,18 +394,22 @@ void GameState::update(int delta)
this->entities_add.clear();
// Update entities
PROFILE_START(entities);
for (list<Entity*>::iterator it = this->entities.begin(); it != this->entities.end(); it++) {
Entity *e = (*it);
if (! e->del) {
e->update(delta);
}
}
PROFILE_END(entities);
// Remove stuff
this->entities.remove_if(EntityEraserDead);
// Update physics
PROFILE_START(physics);
this->physics->stepTime(delta);
PROFILE_END(physics);
// Particles
this->update_particles(delta);
View
@@ -121,11 +121,6 @@ class WeaponFlamethrower;
class WavefrontObj;
class Zone;
#include "util/util.h"
#include "util/debug.h"
View
@@ -42,6 +42,7 @@ void CommandLineArgs::process()
{"debug-lineno", 0, 0, '3'},
{"debug-file", 1, 0, '4'},
{"no-mouse-grab", 0, 0, '5'},
{"profile", 1, 0, '6'},
#endif
{NULL, 0, NULL, 0}
};
@@ -74,8 +75,9 @@ void CommandLineArgs::process()
" \t--debug SECTION Enable debug mode for a given section\n"
" \t--debug-list Show a list of available debug sections\n"
" \t--debug-lineno Show file and line no in debugging output\n"
" \t--debug-file Save debug logs in a file instead of stdout\n"
" \t--debug-file FILE Save debug logs in a file instead of stdout\n"
" \t--no-mouse-grab Disable mouse grab\n"
" \t--profile FILE Save profile log\n"
#endif
;
exit(0);
@@ -188,6 +190,11 @@ void CommandLineArgs::process()
case '5':
this->mouseGrab = false;
break;
case '6':
profile_enable(optarg);
cout << "Saving profile log to file '" << optarg << "'.\n";
break;
#endif
default: break;
View
@@ -15,6 +15,7 @@ using namespace std;
static list<string> enabled_sects;
static bool lineno;
static FILE* out = stdout;
static FILE* profile = NULL;
void write_debug(const char * sect, const char * file, int line, const char * fmt, ...)
@@ -64,3 +65,22 @@ void debug_save()
fclose(out);
}
void profile_enable(const char * filename)
{
profile = fopen(filename, "w");
atexit(profile_save);
fprintf(profile, "Event\tStartTime\tEndTime\tElapsed\n");
}
void profile_write(const char * sect, int start, int end)
{
if (profile != NULL) {
fprintf(profile, "%s\t%i\t%i\t%i\n", sect, start, end, end-start);
}
}
void profile_save()
{
fclose(profile);
}
View
@@ -18,7 +18,6 @@ using namespace std;
#define DEBUG(_sect, _fmt, ...) /* nothing! */
#endif
void write_debug(const char * sect, const char * file, int line, const char * fmt, ...);
void debug_enable(const char * sect);
@@ -30,3 +29,20 @@ void debug_lineno(bool enabled);
void debug_tofile(const char * filename);
void debug_save();
// Profiling
#ifdef DEBUG_OPTIONS
#define PROFILE_START(sect) int _p_##sect = SDL_GetTicks();
#define PROFILE_END(sect) profile_write(#sect, _p_##sect, SDL_GetTicks());
#else
#define PROFILE_START(sect) /* nothing! */
#define PROFILE_END(sect) /* nothing! */
#endif
void profile_enable(const char * filename);
void profile_write(const char * sect, int start, int end);
void profile_save();

0 comments on commit aaaca0c

Please sign in to comment.