void TelemetryImpl::StoreSlowSQL(const nsACString &sql, uint32_t delay, bool isDynamicSql, bool isTrackedDB, bool isAggregate) { AutoHashtable<SlowSQLEntryType> *slowSQLMap = NULL; if (NS_IsMainThread()) slowSQLMap = &(sTelemetry->mSlowSQLOnMainThread); else slowSQLMap = &(sTelemetry->mSlowSQLOnOtherThread); MutexAutoLock hashMutex(sTelemetry->mHashMutex); SlowSQLEntryType *entry = slowSQLMap->GetEntry(sql); if (!entry) { entry = slowSQLMap->PutEntry(sql); if (NS_UNLIKELY(!entry)) return; entry->mData.isDynamicSql = isDynamicSql; entry->mData.isTrackedDb = isTrackedDB; entry->mData.isAggregate = isAggregate; entry->mData.hitCount = 0; entry->mData.totalTime = 0; } entry->mData.hitCount++; entry->mData.totalTime += delay; }
void TelemetryImpl::RecordSlowStatement(const nsACString &statement, const nsACString &dbName, PRUint32 delay) { if (!sTelemetry) { // Make the service manager hold a long-lived reference to the service nsCOMPtr<nsITelemetry> telemetryService = do_GetService("@mozilla.org/base/telemetry;1"); if (!telemetryService || !sTelemetry) return; } if (!sTelemetry->mCanRecord || !sTelemetry->mTrackedDBs.GetEntry(dbName)) return; nsTHashtable<SlowSQLEntryType> *slowSQLMap = NULL; if (NS_IsMainThread()) slowSQLMap = &(sTelemetry->mSlowSQLOnMainThread); else slowSQLMap = &(sTelemetry->mSlowSQLOnOtherThread); MutexAutoLock hashMutex(sTelemetry->mHashMutex); SlowSQLEntryType *entry = slowSQLMap->GetEntry(statement); if (!entry) { entry = slowSQLMap->PutEntry(statement); if (NS_UNLIKELY(!entry)) return; entry->mData.hitCount = 0; entry->mData.totalTime = 0; } entry->mData.hitCount++; entry->mData.totalTime += delay; }
NS_IMETHODIMP TelemetryImpl::GetHistogramSnapshots(JSContext *cx, jsval *ret) { JSObject *root_obj = JS_NewObject(cx, NULL, NULL, NULL); if (!root_obj) return NS_ERROR_FAILURE; *ret = OBJECT_TO_JSVAL(root_obj); StatisticsRecorder::Histograms h; StatisticsRecorder::GetHistograms(&h); for (StatisticsRecorder::Histograms::iterator it = h.begin(); it != h.end();++it) { Histogram *h = *it; JSObject *hobj = JS_NewObject(cx, NULL, NULL, NULL); if (!(hobj && JS_DefineProperty(cx, root_obj, h->histogram_name().c_str(), OBJECT_TO_JSVAL(hobj), NULL, NULL, JSPROP_ENUMERATE) && ReflectHistogramSnapshot(cx, hobj, h))) { return NS_ERROR_FAILURE; } } MutexAutoLock hashMutex(mHashMutex); // Add info about slow SQL queries on the main thread if (!AddSlowSQLInfo(cx, root_obj, true)) return NS_ERROR_FAILURE; // Add info about slow SQL queries on other threads if (!AddSlowSQLInfo(cx, root_obj, false)) return NS_ERROR_FAILURE; return NS_OK; }
void TelemetryImpl::RecordSlowStatement(const nsACString &statement, const nsACString &dbName, PRUint32 delay) { MOZ_ASSERT(sTelemetry); if (!sTelemetry->mCanRecord || !sTelemetry->mTrackedDBs.GetEntry(dbName)) return; AutoHashtable<SlowSQLEntryType> *slowSQLMap = NULL; if (NS_IsMainThread()) slowSQLMap = &(sTelemetry->mSlowSQLOnMainThread); else slowSQLMap = &(sTelemetry->mSlowSQLOnOtherThread); MutexAutoLock hashMutex(sTelemetry->mHashMutex); SlowSQLEntryType *entry = slowSQLMap->GetEntry(statement); if (!entry) { entry = slowSQLMap->PutEntry(statement); if (NS_UNLIKELY(!entry)) return; entry->mData.hitCount = 0; entry->mData.totalTime = 0; } entry->mData.hitCount++; entry->mData.totalTime += delay; }
bool TelemetryImpl::GetSQLStats(JSContext *cx, jsval *ret, bool includePrivateSql) { JSObject *root_obj = JS_NewObject(cx, NULL, NULL, NULL); if (!root_obj) return false; *ret = OBJECT_TO_JSVAL(root_obj); MutexAutoLock hashMutex(mHashMutex); // Add info about slow SQL queries on the main thread if (!AddSQLInfo(cx, root_obj, true, includePrivateSql)) return false; // Add info about slow SQL queries on other threads if (!AddSQLInfo(cx, root_obj, false, includePrivateSql)) return false; return true; }
NS_IMETHODIMP TelemetryImpl::GetSlowSQL(JSContext *cx, jsval *ret) { JSObject *root_obj = JS_NewObject(cx, NULL, NULL, NULL); if (!root_obj) return NS_ERROR_FAILURE; *ret = OBJECT_TO_JSVAL(root_obj); MutexAutoLock hashMutex(mHashMutex); // Add info about slow SQL queries on the main thread if (!AddSQLInfo(cx, root_obj, true)) return NS_ERROR_FAILURE; // Add info about slow SQL queries on other threads if (!AddSQLInfo(cx, root_obj, false)) return NS_ERROR_FAILURE; return NS_OK; }