Skip to content

Commit

Permalink
Add housekeeping task for hardware profiler (smolt).
Browse files Browse the repository at this point in the history
This adds a housekeeping task to allow the hardware profiler to be run
periodically through the housekeeper, rather than a single check
performed during frontend startup. This also adds a schema update to
reorganize a few settings related to it.
  • Loading branch information
wagnerrp committed Jun 2, 2013
1 parent 3671c22 commit 1454557
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 6 deletions.
57 changes: 52 additions & 5 deletions mythtv/libs/libmythbase/hardwareprofile.cpp
Expand Up @@ -19,19 +19,44 @@ const QString SMOLT_TOKEN =
QString("smolt_token-smolt.mythtv.org");

HardwareProfile::HardwareProfile() :
m_enabled(false),
m_uuid(QString()), m_publicuuid(QString()),
m_lastUpdate(QDateTime()), m_hardwareProfile(QString())
{
m_enabled = (gCoreContext->GetNumSetting("HardwareProfileEnabled", 0) == 1);
m_uuid = gCoreContext->GetSetting("HardwareProfileUUID");
m_publicuuid = gCoreContext->GetSetting("HardwareProfilePublicUUID");
QString lastupdate = gCoreContext->GetSetting("HardwareProfileLastUpdated");
m_lastUpdate = MythDate::fromString(lastupdate);

if (m_enabled)
{
MSqlQuery query(MSqlQuery::InitCon());

query.prepare("SELECT lastrun FROM housekeeping"
" WHERE tag = 'HardwareProfiler'"
" AND hostname = :HOST");
query.bindValue(":HOST", gCoreContext->GetHostName());
if (query.exec() && query.next())
m_lastUpdate = MythDate::as_utc(query.value(0).toDateTime());
}
}

HardwareProfile::~HardwareProfile()
{
}

void HardwareProfile::Enable(void)
{
if (m_uuid.isEmpty())
return;

gCoreContext->SaveSettingOnHost("HardwareProfileEnabled", "1", "");
}

void HardwareProfile::Disable(void)
{
gCoreContext->SaveSettingOnHost("HardwareProfileEnabled", "0", "");
}

void HardwareProfile::GenerateUUIDs(void)
{
QString fileprefix = GetConfDir() + "/HardwareProfile";
Expand Down Expand Up @@ -169,11 +194,14 @@ bool HardwareProfile::NeedsUpdate(void) const
return false;
}

bool HardwareProfile::SubmitProfile(void)
bool HardwareProfile::SubmitProfile(bool updateTime)
{
if (m_uuid.isEmpty())
return false;

if (!m_enabled)
Enable();

if (!m_hardwareProfile.isEmpty())
LOG(VB_GENERAL, LOG_INFO,
QString("Submitting the following hardware profile: %1")
Expand All @@ -191,8 +219,13 @@ bool HardwareProfile::SubmitProfile(void)
GenerateUUIDs();
gCoreContext->SaveSetting("HardwareProfileUUID", GetPrivateUUID());
gCoreContext->SaveSetting("HardwareProfilePublicUUID", GetPublicUUID());
gCoreContext->SaveSetting("HardwareProfileLastUpdated",
MythDate::current_iso_string());

if (updateTime)
{
HardwareProfileTask task;
task.UpdateLastRun(MythDate::current());
}

return true;
}
else
Expand Down Expand Up @@ -252,3 +285,17 @@ QString HardwareProfile::GetHardwareProfile() const
system.Wait();
return system.ReadAll();
}

bool HardwareProfileTask::DoCheckRun(QDateTime now)
{
if (GetLastRun().secsTo(now) > 2592000 && // 60*60*24*30
(gCoreContext->GetNumSetting("HardwareProfileEnabled", 0) == 1))
return true;
return false;
}

bool HardwareProfileTask::DoRun(void)
{
HardwareProfile hp;
return hp.SubmitProfile(false);
}
2 changes: 1 addition & 1 deletion mythtv/libs/libmythbase/mythversion.h
Expand Up @@ -61,7 +61,7 @@
* mythtv/bindings/php/MythBackend.php
#endif

#define MYTH_DATABASE_VERSION "1311"
#define MYTH_DATABASE_VERSION "1312"


MBASE_PUBLIC const char *GetMythSourceVersion();
Expand Down
27 changes: 27 additions & 0 deletions mythtv/libs/libmythtv/dbcheck.cpp
Expand Up @@ -2368,6 +2368,33 @@ NULL
return false;
}

if (dbver == "1311")
{
const char *updates[] = {
// Create a global enable/disable instead of one per-host
// Any hosts previously running it mean all hosts do now
"INSERT INTO `settings` (`value`, `hostname`, `data`),"
" SELECT 'HardwareProfileEnaled',"
" NULL,"
" IF((SELECT COUNT(1)"
" FROM `settings`"
" WHERE `value` = 'HardwareProfileLastUpdated' > 0),"
" 1, 0);",
// Create 'lastrun' times using existing data in settings
"INSERT INTO `housekeeper` (`tag`, `hostname`, `lastrun`)"
" SELECT 'HardwareProfiler',"
" `hostname`,"
" `data`"
" FROM `settings`"
" WHERE `value` = 'HardwareProfileLastUpdated';",
// Clear out old settings
"DELETE FROM `settings` WHERE `value` = 'HardwareProfileLastUpdated';",
NULL
};
if (!performActualUpdate(&updates[0], "1312", dbver))
return false;
}

return true;
}

Expand Down

0 comments on commit 1454557

Please sign in to comment.