Skip to content

Commit

Permalink
profile: Add a very dumb benchmark tool for profiling
Browse files Browse the repository at this point in the history
At most, this lets us measure before/after frame-times when tweaking small but
busy parts of the codebase.
  • Loading branch information
Cory Fields committed Nov 21, 2012
1 parent 0a5a3c0 commit 19082aa
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 2 deletions.
8 changes: 6 additions & 2 deletions xbmc/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2333,7 +2333,7 @@ void CApplication::Render()
flip = true;

//fps limiter, make sure each frame lasts at least singleFrameTime milliseconds
if (limitFrames || !flip)
if ((limitFrames || !flip) && !m_benchmarkTimer)
{
if (!limitFrames)
singleFrameTime = 40; //if not flipping, loop at 25 fps
Expand Down Expand Up @@ -5036,7 +5036,11 @@ bool CApplication::ExecuteXBMCAction(std::string actionStr)
void CApplication::Process()
{
MEASURE_FUNCTION;

if (m_benchmarkTimer && XbmcThreads::SystemClockMillis() >= m_benchmarkTimer)
{
Stop(0);
return;
}
// dispatch the messages generated by python or other threads to the current window
g_windowManager.DispatchThreadMessages();

Expand Down
5 changes: 5 additions & 0 deletions xbmc/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,11 @@ class CApplication : public CXBApplicationEx, public IPlayerCallback, public IMs
return m_bTestMode;
}

void SetBenchmarkTimer(unsigned int timer)
{
m_benchmarkTimer = timer;
}

bool IsPresentFrame();

void Minimize();
Expand Down
13 changes: 13 additions & 0 deletions xbmc/XBApplicationEx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ CXBApplicationEx::CXBApplicationEx()
m_AppFocused = true;
m_ExitCode = EXITCODE_QUIT;
m_renderGUI = false;
m_benchmarkTimer = 0;
}

CXBApplicationEx::~CXBApplicationEx()
Expand Down Expand Up @@ -91,6 +92,10 @@ INT CXBApplicationEx::Run()
const BYTE MAX_EXCEPTION_COUNT = 10;
#endif

m_firstFrameTime = XbmcThreads::SystemClockMillis();
if (m_benchmarkTimer)
m_benchmarkTimer += m_firstFrameTime;

// Run xbmc
while (!m_bStop)
{
Expand Down Expand Up @@ -209,9 +214,17 @@ INT CXBApplicationEx::Run()
}
}
#endif
m_totalFrames++;
} // while (!m_bStop)
unsigned int uptime = lastFrameTime - m_firstFrameTime;
Destroy();

CLog::Log(LOGNOTICE, "application stopped..." );

if (m_benchmarkTimer)
{
printf("Processed %llu Frames in %i msec.\n",m_totalFrames, uptime);
}

return m_ExitCode;
}
3 changes: 3 additions & 0 deletions xbmc/XBApplicationEx.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ class CXBApplicationEx : public IWindowManagerCallback
INT Run();
VOID Destroy();

unsigned long long m_totalFrames;
unsigned int m_benchmarkTimer;
unsigned int m_firstFrameTime;
private:
};

Expand Down
8 changes: 8 additions & 0 deletions xbmc/settings/AppParamParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ void CAppParamParser::DisplayHelp()
printf("Usage: xbmc [OPTION]... [FILE]...\n\n");
printf("Arguments:\n");
printf(" -d <n>\t\tdelay <n> seconds before starting\n");
printf(" --benchmark=n\t\tEnable meaningless benchmark mode. Run for <n> msec then display the number of frames rendered\n");
printf(" -fs\t\t\tRuns XBMC in full screen\n");
printf(" --standalone\t\tXBMC runs in a stand alone environment without a window \n");
printf("\t\t\tmanager and supporting applications. For example, that\n");
Expand Down Expand Up @@ -137,6 +138,13 @@ void CAppParamParser::ParseArg(const CStdString &arg)
m_testmode = true;
else if (arg.substr(0, 11) == "--settings=")
g_advancedSettings.AddSettingsFile(arg.substr(11));
else if (arg.substr(0, 12) == "--benchmark=")
{
unsigned int benchmark_time = atoi(arg.substr(12).c_str());
if (benchmark_time)
g_application.SetBenchmarkTimer(benchmark_time);
}

else if (arg.length() != 0 && arg[0] != '-')
{
if (m_testmode)
Expand Down

0 comments on commit 19082aa

Please sign in to comment.