Bug 987248 - Prevent divide-by-zero in seer. r=mcmanus

This commit is contained in:
Nicholas Hurley 2014-04-07 12:45:45 -07:00
parent 54fc5425e3
commit a1f8a49d94
2 changed files with 66 additions and 1 deletions

View File

@ -125,6 +125,10 @@ struct SeerTelemetryAccumulators {
Telemetry::AutoCounter<Telemetry::SEER_TOTAL_PRECONNECTS> mTotalPreconnects; Telemetry::AutoCounter<Telemetry::SEER_TOTAL_PRECONNECTS> mTotalPreconnects;
Telemetry::AutoCounter<Telemetry::SEER_TOTAL_PRERESOLVES> mTotalPreresolves; Telemetry::AutoCounter<Telemetry::SEER_TOTAL_PRERESOLVES> mTotalPreresolves;
Telemetry::AutoCounter<Telemetry::SEER_PREDICTIONS_CALCULATED> mPredictionsCalculated; Telemetry::AutoCounter<Telemetry::SEER_PREDICTIONS_CALCULATED> mPredictionsCalculated;
Telemetry::AutoCounter<Telemetry::SEER_LOAD_COUNT_IS_ZERO> mLoadCountZeroes;
Telemetry::AutoCounter<Telemetry::SEER_LOAD_COUNT_OVERFLOWS> mLoadCountOverflows;
Telemetry::AutoCounter<Telemetry::SEER_STARTUP_COUNT_IS_ZERO> mStartupCountZeroes;
Telemetry::AutoCounter<Telemetry::SEER_STARTUP_COUNT_OVERFLOWS> mStartupCountOverflows;
}; };
// Listener for the speculative DNS requests we'll fire off, which just ignores // Listener for the speculative DNS requests we'll fire off, which just ignores
@ -654,6 +658,13 @@ Seer::EnsureInitStorage()
getter_AddRefs(stmt)); getter_AddRefs(stmt));
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
int32_t newStartupCount = mStartupCount + 1;
if (newStartupCount <= 0) {
SEER_LOG(("Seer::EnsureInitStorage startup count overflow\n"));
newStartupCount = mStartupCount;
++mAccumulators->mStartupCountOverflows;
}
rv = stmt->BindInt32ByName(NS_LITERAL_CSTRING("startup_count"), rv = stmt->BindInt32ByName(NS_LITERAL_CSTRING("startup_count"),
mStartupCount + 1); mStartupCount + 1);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
@ -1296,10 +1307,18 @@ Seer::UpdateTopLevel(QueryType queryType, const TopLevelInfo &info, PRTime now)
} }
mozStorageStatementScoper scope(stmt); mozStorageStatementScoper scope(stmt);
int32_t newLoadCount = info.loadCount + 1;
if (newLoadCount <= 0) {
SEER_LOG(("Seer::UpdateTopLevel type %d id %d load count overflow\n",
queryType, info.id));
newLoadCount = info.loadCount;
++mAccumulators->mLoadCountOverflows;
}
// First, let's update the page in the database, since loading a page // First, let's update the page in the database, since loading a page
// implicitly learns about the page. // implicitly learns about the page.
nsresult rv = stmt->BindInt32ByName(NS_LITERAL_CSTRING("load_count"), nsresult rv = stmt->BindInt32ByName(NS_LITERAL_CSTRING("load_count"),
info.loadCount + 1); newLoadCount);
RETURN_IF_FAILED(rv); RETURN_IF_FAILED(rv);
rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("now"), now); rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("now"), now);
@ -1322,6 +1341,12 @@ Seer::TryPredict(QueryType queryType, const TopLevelInfo &info, PRTime now,
{ {
MOZ_ASSERT(!NS_IsMainThread(), "TryPredict called on main thread."); MOZ_ASSERT(!NS_IsMainThread(), "TryPredict called on main thread.");
if (!info.loadCount) {
SEER_LOG(("Seer::TryPredict info.loadCount is zero!\n"));
++mAccumulators->mLoadCountZeroes;
return false;
}
int globalDegradation = CalculateGlobalDegradation(now, info.lastLoad); int globalDegradation = CalculateGlobalDegradation(now, info.lastLoad);
// Now let's look up the subresources we know about for this page // Now let's look up the subresources we know about for this page
@ -1402,6 +1427,12 @@ Seer::WouldRedirect(const TopLevelInfo &info, PRTime now, UriInfo &newUri)
{ {
MOZ_ASSERT(!NS_IsMainThread(), "WouldRedirect called on main thread."); MOZ_ASSERT(!NS_IsMainThread(), "WouldRedirect called on main thread.");
if (!info.loadCount) {
SEER_LOG(("Seer::WouldRedirect info.loadCount is zero!\n"));
++mAccumulators->mLoadCountZeroes;
return false;
}
nsCOMPtr<mozIStorageStatement> stmt = mStatements.GetCachedStatement( nsCOMPtr<mozIStorageStatement> stmt = mStatements.GetCachedStatement(
NS_LITERAL_CSTRING("SELECT uri, origin, hits, last_hit " NS_LITERAL_CSTRING("SELECT uri, origin, hits, last_hit "
"FROM moz_redirects WHERE pid = :id;")); "FROM moz_redirects WHERE pid = :id;"));
@ -1532,6 +1563,12 @@ Seer::PredictForStartup(SeerVerifierHandle &verifier,
{ {
MOZ_ASSERT(!NS_IsMainThread(), "PredictForStartup called on main thread"); MOZ_ASSERT(!NS_IsMainThread(), "PredictForStartup called on main thread");
if (!mStartupCount) {
SEER_LOG(("Seer::PredictForStartup mStartupCount is zero!\n"));
++mAccumulators->mStartupCountZeroes;
return;
}
if (NS_FAILED(EnsureInitStorage())) { if (NS_FAILED(EnsureInitStorage())) {
return; return;
} }

View File

@ -2241,6 +2241,34 @@
"kind": "boolean", "kind": "boolean",
"description": "Whether or not we actually try the cleanup method when we think about it" "description": "Whether or not we actually try the cleanup method when we think about it"
}, },
"SEER_LOAD_COUNT_IS_ZERO": {
"expires_in_version": "never",
"kind": "linear",
"high": "100",
"n_buckets": 50,
"description": "Number of times load count is zero"
},
"SEER_LOAD_COUNT_OVERFLOWS": {
"expires_in_version": "never",
"kind": "linear",
"high": "100",
"n_buckets": 50,
"description": "Number of times load count overflowed"
},
"SEER_STARTUP_COUNT_IS_ZERO": {
"expires_in_version": "never",
"kind": "linear",
"high": "100",
"n_buckets": 50,
"description": "Number of times startup count is zero"
},
"SEER_STARTUP_COUNT_OVERFLOWS": {
"expires_in_version": "never",
"kind": "linear",
"high": "100",
"n_buckets": 50,
"description": "Number of times startup count overflowed"
},
"FIND_PLUGINS": { "FIND_PLUGINS": {
"expires_in_version": "never", "expires_in_version": "never",
"kind": "exponential", "kind": "exponential",