Bug 1134279 - Make TelemetryPing and TelemetrySession code use the "FHR enabled" & "Telemetry enabled" prefs properly. r=vladan

This commit is contained in:
Alessio Placitelli 2015-03-25 16:42:14 +01:00
Родитель 7dc325e399
Коммит 50b33bc2af
3 изменённых файлов: 95 добавлений и 32 удалений

Просмотреть файл

@ -648,7 +648,8 @@ class TelemetryImpl final
public:
void InitMemoryReporter();
static bool CanRecord();
static bool CanRecordBase();
static bool CanRecordExtended();
static already_AddRefed<nsITelemetry> CreateTelemetryInstance();
static void ShutdownTelemetry();
static void RecordSlowStatement(const nsACString &sql, const nsACString &dbName,
@ -731,7 +732,8 @@ private:
typedef nsBaseHashtableET<nsDepCharHashKey, Telemetry::ID> CharPtrEntryType;
typedef AutoHashtable<CharPtrEntryType> HistogramMapType;
HistogramMapType mHistogramMap;
bool mCanRecord;
bool mCanRecordBase;
bool mCanRecordExtended;
static TelemetryImpl *sTelemetry;
AutoHashtable<SlowSQLEntryType> mPrivateSQL;
AutoHashtable<SlowSQLEntryType> mSanitizedSQL;
@ -1210,7 +1212,7 @@ JSHistogram_Add(JSContext *cx, unsigned argc, JS::Value *vp)
}
}
if (TelemetryImpl::CanRecord()) {
if (TelemetryImpl::CanRecordExtended()) {
HistogramAdd(*h, value);
}
@ -1751,7 +1753,7 @@ TelemetryImpl::AsyncFetchTelemetryData(nsIFetchTelemetryDataCallback *aCallback)
// We make this check so that GetShutdownTimeFileName() doesn't get
// called; calling that function without telemetry enabled violates
// assumptions that the write-the-shutdown-timestamp machinery makes.
if (!Telemetry::CanRecord()) {
if (!Telemetry::CanRecordExtended()) {
mCachedTelemetryData = true;
aCallback->Complete();
return NS_OK;
@ -1805,8 +1807,10 @@ TelemetryImpl::AsyncFetchTelemetryData(nsIFetchTelemetryDataCallback *aCallback)
TelemetryImpl::TelemetryImpl():
mHistogramMap(Telemetry::HistogramCount),
mCanRecord(XRE_GetProcessType() == GeckoProcessType_Default ||
XRE_GetProcessType() == GeckoProcessType_Content),
mCanRecordBase(XRE_GetProcessType() == GeckoProcessType_Default ||
XRE_GetProcessType() == GeckoProcessType_Content),
mCanRecordExtended(XRE_GetProcessType() == GeckoProcessType_Default ||
XRE_GetProcessType() == GeckoProcessType_Content),
mHashMutex("Telemetry::mHashMutex"),
mHangReportsMutex("Telemetry::mHangReportsMutex"),
mThreadHangStatsMutex("Telemetry::mThreadHangStatsMutex"),
@ -3132,24 +3136,56 @@ TelemetryImpl::GetKeyedHistogramById(const nsACString &name)
}
NS_IMETHODIMP
TelemetryImpl::GetCanRecord(bool *ret) {
*ret = mCanRecord;
TelemetryImpl::GetCanRecordBase(bool *ret) {
*ret = mCanRecordBase;
return NS_OK;
}
NS_IMETHODIMP
TelemetryImpl::SetCanRecord(bool canRecord) {
mCanRecord = !!canRecord;
TelemetryImpl::SetCanRecordBase(bool canRecord) {
mCanRecordBase = canRecord;
return NS_OK;
}
/**
* Indicates if Telemetry can record base data (FHR data). This is true if the
* FHR data reporting service or self-support are enabled.
*
* In the unlikely event that adding a new base probe is needed, please check the data
* collection wiki at https://wiki.mozilla.org/Firefox/Data_Collection and talk to the
* Telemetry team.
*/
bool
TelemetryImpl::CanRecord() {
return !sTelemetry || sTelemetry->mCanRecord;
TelemetryImpl::CanRecordBase() {
return !sTelemetry || sTelemetry->mCanRecordBase;
}
NS_IMETHODIMP
TelemetryImpl::GetCanSend(bool *ret) {
TelemetryImpl::GetCanRecordExtended(bool *ret) {
*ret = mCanRecordExtended;
return NS_OK;
}
NS_IMETHODIMP
TelemetryImpl::SetCanRecordExtended(bool canRecord) {
mCanRecordExtended = canRecord;
return NS_OK;
}
/**
* Indicates if Telemetry is allowed to record extended data. Returns false if the user
* hasn't opted into "extended Telemetry" on the Release channel, when the user has
* explicitly opted out of Telemetry on Nightly/Aurora/Beta or if manually set to false
* during tests.
* If the returned value is false, gathering of extended telemetry statistics is disabled.
*/
bool
TelemetryImpl::CanRecordExtended() {
return !sTelemetry || sTelemetry->mCanRecordExtended;
}
NS_IMETHODIMP
TelemetryImpl::GetIsOfficialTelemetry(bool *ret) {
#if defined(MOZILLA_OFFICIAL) && defined(MOZ_TELEMETRY_REPORTING)
*ret = true;
#else
@ -3344,7 +3380,7 @@ TelemetryImpl::RecordSlowStatement(const nsACString &sql,
const nsACString &dbName,
uint32_t delay)
{
if (!sTelemetry || !sTelemetry->mCanRecord)
if (!sTelemetry || !sTelemetry->mCanRecordExtended)
return;
bool isFirefoxDB = sTelemetry->mTrackedDBs.Contains(dbName);
@ -3379,7 +3415,7 @@ TelemetryImpl::RecordChromeHang(uint32_t aDuration,
int32_t aFirefoxUptime,
HangAnnotationsPtr aAnnotations)
{
if (!sTelemetry || !sTelemetry->mCanRecord)
if (!sTelemetry || !sTelemetry->mCanRecordExtended)
return;
HangAnnotationsPtr annotations;
@ -3399,7 +3435,7 @@ TelemetryImpl::RecordChromeHang(uint32_t aDuration,
void
TelemetryImpl::RecordThreadHangStats(Telemetry::ThreadHangStats& aStats)
{
if (!sTelemetry || !sTelemetry->mCanRecord)
if (!sTelemetry || !sTelemetry->mCanRecordExtended)
return;
MutexAutoLock autoLock(sTelemetry->mThreadHangStatsMutex);
@ -3519,7 +3555,7 @@ RecordShutdownStartTimeStamp() {
recorded = true;
#endif
if (!Telemetry::CanRecord())
if (!Telemetry::CanRecordExtended())
return;
gRecordedShutdownStartTime = TimeStamp::Now();
@ -3568,7 +3604,7 @@ namespace Telemetry {
void
Accumulate(ID aHistogram, uint32_t aSample)
{
if (!TelemetryImpl::CanRecord()) {
if (!TelemetryImpl::CanRecordExtended()) {
return;
}
Histogram *h;
@ -3580,7 +3616,7 @@ Accumulate(ID aHistogram, uint32_t aSample)
void
Accumulate(ID aID, const nsCString& aKey, uint32_t aSample)
{
if (!TelemetryImpl::CanRecord()) {
if (!TelemetryImpl::CanRecordExtended()) {
return;
}
@ -3593,7 +3629,7 @@ Accumulate(ID aID, const nsCString& aKey, uint32_t aSample)
void
Accumulate(const char* name, uint32_t sample)
{
if (!TelemetryImpl::CanRecord()) {
if (!TelemetryImpl::CanRecordExtended()) {
return;
}
ID id;
@ -3617,9 +3653,15 @@ AccumulateTimeDelta(ID aHistogram, TimeStamp start, TimeStamp end)
}
bool
CanRecord()
CanRecordBase()
{
return TelemetryImpl::CanRecord();
return TelemetryImpl::CanRecordBase();
}
bool
CanRecordExtended()
{
return TelemetryImpl::CanRecordExtended();
}
base::Histogram*
@ -4102,7 +4144,7 @@ KeyedHistogram::ClearHistogramEnumerator(KeyedHistogramEntry* entry, void*)
nsresult
KeyedHistogram::Add(const nsCString& key, uint32_t sample)
{
if (!TelemetryImpl::CanRecord()) {
if (!TelemetryImpl::CanRecordExtended()) {
return NS_OK;
}

Просмотреть файл

@ -174,11 +174,15 @@ private:
};
/**
* Indicates whether Telemetry recording is turned on. This is intended
* to guard calls to Accumulate when the statistic being recorded is
* expensive to compute.
* Indicates whether Telemetry base data recording is turned on. Added for future uses.
*/
bool CanRecord();
bool CanRecordBase();
/**
* Indicates whether Telemetry extended data recording is turned on. This is intended
* to guard calls to Accumulate when the statistic being recorded is expensive to compute.
*/
bool CanRecordExtended();
/**
* Records slow SQL statements for Telemetry reporting.

Просмотреть файл

@ -12,7 +12,7 @@ interface nsIFetchTelemetryDataCallback : nsISupports
void complete();
};
[scriptable, uuid(1cd31579-2a81-4b99-900b-e89eea2e461c)]
[scriptable, uuid(68e82b42-cad2-411f-857b-b64ea9377929)]
interface nsITelemetry : nsISupports
{
/**
@ -251,14 +251,31 @@ interface nsITelemetry : nsISupports
jsval getKeyedHistogramById(in ACString id);
/**
* Set this to false to disable gathering of telemetry statistics.
* A flag indicating if Telemetry can record base data (FHR data). This is true if the
* FHR data reporting service or self-support are enabled.
*
* In the unlikely event that adding a new base probe is needed, please check the data
* collection wiki at https://wiki.mozilla.org/Firefox/Data_Collection and talk to the
* Telemetry team.
*/
attribute boolean canRecord;
attribute boolean canRecordBase;
/**
* A flag indicating whether Telemetry can submit official results.
* A flag indicating if Telemetry is allowed to record extended data. Returns false if
* the user hasn't opted into "extended Telemetry" on the Release channel, when the
* user has explicitly opted out of Telemetry on Nightly/Aurora/Beta or if manually
* set to false during tests.
*
* Set this to false in tests to disable gathering of extended telemetry statistics.
*/
readonly attribute boolean canSend;
attribute boolean canRecordExtended;
/**
* A flag indicating whether Telemetry can submit official results (for base or extended
* data). This is true on official builds with built in support for Mozilla Telemetry
* reporting.
*/
readonly attribute boolean isOfficialTelemetry;
/** Addon telemetry hooks */