Permalink
Browse files

profile: Add a very dumb benchmark tool for profiling

At most, this lets us measure before/after frame-times when tweaking small but
busy parts of the codebase.
  • Loading branch information...
1 parent 0a5a3c0 commit 19082aa22143dfee74695405d17b93d6b379100b Cory Fields committed Nov 21, 2012
Showing with 35 additions and 2 deletions.
  1. +6 −2 xbmc/Application.cpp
  2. +5 −0 xbmc/Application.h
  3. +13 −0 xbmc/XBApplicationEx.cpp
  4. +3 −0 xbmc/XBApplicationEx.h
  5. +8 −0 xbmc/settings/AppParamParser.cpp
View
@@ -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
@@ -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();
View
@@ -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();
View
@@ -42,6 +42,7 @@ CXBApplicationEx::CXBApplicationEx()
m_AppFocused = true;
m_ExitCode = EXITCODE_QUIT;
m_renderGUI = false;
+ m_benchmarkTimer = 0;
}
CXBApplicationEx::~CXBApplicationEx()
@@ -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)
{
@@ -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;
}
View
@@ -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:
};
@@ -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");
@@ -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)

0 comments on commit 19082aa

Please sign in to comment.