Bug 1157282 - Record telemetry histograms for base set when Telemetry.canRecordExtended is false. r=gfritzsche

This commit is contained in:
Alessio Placitelli 2015-04-27 08:08:00 -04:00
parent fbaf1d4482
commit f0bfbf9e70

View File

@ -783,7 +783,7 @@ class KeyedHistogram {
public:
KeyedHistogram(const nsACString &name, const nsACString &expiration,
uint32_t histogramType, uint32_t min, uint32_t max,
uint32_t bucketCount);
uint32_t bucketCount, uint32_t dataset);
nsresult GetHistogram(const nsCString& name, Histogram** histogram, bool subsession);
Histogram* GetHistogram(const nsCString& name, bool subsession);
uint32_t GetHistogramType() const { return mHistogramType; }
@ -821,6 +821,7 @@ private:
const uint32_t mMin;
const uint32_t mMax;
const uint32_t mBucketCount;
const uint32_t mDataset;
};
// Hardcoded probes
@ -874,22 +875,41 @@ IsValidHistogramName(const nsACString& name)
}
bool
IsInDataset(const TelemetryHistogram& h, uint32_t dataset)
IsInDataset(uint32_t dataset, uint32_t containingDataset)
{
if (h.dataset == dataset) {
if (dataset == containingDataset) {
return true;
}
// The "optin on release channel" dataset is a superset of the
// "optout on release channel one".
if (dataset == nsITelemetry::DATASET_RELEASE_CHANNEL_OPTIN
&& h.dataset == nsITelemetry::DATASET_RELEASE_CHANNEL_OPTOUT) {
if (containingDataset == nsITelemetry::DATASET_RELEASE_CHANNEL_OPTIN
&& dataset == nsITelemetry::DATASET_RELEASE_CHANNEL_OPTOUT) {
return true;
}
return false;
}
bool
CanRecordDataset(uint32_t dataset)
{
// If we are extended telemetry is enabled, we are allowed to record regardless of
// the dataset.
if (TelemetryImpl::CanRecordExtended()) {
return true;
}
// If base telemetry data is enabled and we're trying to record base telemetry, allow it.
if (TelemetryImpl::CanRecordBase() &&
IsInDataset(dataset, nsITelemetry::DATASET_RELEASE_CHANNEL_OPTOUT)) {
return true;
}
// We're not recording extended telemetry or this is not the base dataset. Bail out.
return false;
}
nsresult
CheckHistogramArguments(uint32_t histogramType, uint32_t min, uint32_t max,
uint32_t bucketCount, bool haveOptArgs)
@ -1079,8 +1099,13 @@ GetSubsessionHistogram(Histogram& existing)
#endif
nsresult
HistogramAdd(Histogram& histogram, int32_t value)
HistogramAdd(Histogram& histogram, int32_t value, uint32_t dataset)
{
// Check if we are allowed to record the data.
if (!CanRecordDataset(dataset)) {
return NS_OK;
}
histogram.Add(value);
#if !defined(MOZ_WIDGET_GONK) && !defined(MOZ_WIDGET_ANDROID)
if (Histogram* subsession = GetSubsessionHistogram(histogram)) {
@ -1091,6 +1116,26 @@ HistogramAdd(Histogram& histogram, int32_t value)
return NS_OK;
}
nsresult
HistogramAdd(Histogram& histogram, int32_t value)
{
uint32_t dataset = nsITelemetry::DATASET_RELEASE_CHANNEL_OPTIN;
// We only really care about the dataset of the histogram if we are not recording
// extended telemetry. Otherwise, we always record histogram data.
if (!TelemetryImpl::CanRecordExtended()) {
Telemetry::ID id;
nsresult rv = TelemetryImpl::GetHistogramEnumId(histogram.histogram_name().c_str(), &id);
if (NS_FAILED(rv)) {
// If we can't look up the dataset, it might be because the histogram was added
// at runtime. Since we're not recording extended telemetry, bail out.
return NS_OK;
}
dataset = gHistograms[id].dataset;
}
return HistogramAdd(histogram, value, dataset);
}
bool
FillRanges(JSContext *cx, JS::Handle<JSObject*> array, Histogram *h)
{
@ -1210,7 +1255,7 @@ JSHistogram_Add(JSContext *cx, unsigned argc, JS::Value *vp)
}
}
if (TelemetryImpl::CanRecordExtended()) {
if (TelemetryImpl::CanRecordBase()) {
HistogramAdd(*h, value);
}
@ -1866,7 +1911,7 @@ mFailedLockCount(0)
const nsDependentCString id(h.id());
const nsDependentCString expiration(h.expiration());
mKeyedHistograms.Put(id, new KeyedHistogram(id, expiration, h.histogramType,
h.min, h.max, h.bucketCount));
h.min, h.max, h.bucketCount, h.dataset));
}
}
@ -1913,7 +1958,8 @@ TelemetryImpl::NewKeyedHistogram(const nsACString &name, const nsACString &expir
}
KeyedHistogram* keyed = new KeyedHistogram(name, expiration, histogramType,
min, max, bucketCount);
min, max, bucketCount,
nsITelemetry::DATASET_RELEASE_CHANNEL_OPTIN);
if (MOZ_UNLIKELY(!mKeyedHistograms.Put(name, keyed, fallible))) {
delete keyed;
return NS_ERROR_OUT_OF_MEMORY;
@ -3076,7 +3122,7 @@ GetRegisteredHistogramIds(bool keyed, uint32_t dataset, uint32_t *aCount,
for (size_t i = 0; i < ArrayLength(gHistograms); ++i) {
const TelemetryHistogram& h = gHistograms[i];
if (IsExpired(h.expiration()) || h.keyed != keyed ||
!IsInDataset(h, dataset)) {
!IsInDataset(h.dataset, dataset)) {
continue;
}
@ -3622,22 +3668,22 @@ namespace Telemetry {
void
Accumulate(ID aHistogram, uint32_t aSample)
{
if (!TelemetryImpl::CanRecordExtended()) {
if (!TelemetryImpl::CanRecordBase()) {
return;
}
Histogram *h;
nsresult rv = GetHistogramByEnumId(aHistogram, &h);
if (NS_SUCCEEDED(rv))
HistogramAdd(*h, aSample);
if (NS_SUCCEEDED(rv)) {
HistogramAdd(*h, aSample, gHistograms[aHistogram].dataset);
}
}
void
Accumulate(ID aID, const nsCString& aKey, uint32_t aSample)
{
if (!TelemetryImpl::CanRecordExtended()) {
if (!TelemetryImpl::CanRecordBase()) {
return;
}
const TelemetryHistogram& th = gHistograms[aID];
KeyedHistogram* keyed = TelemetryImpl::GetKeyedHistogramById(nsDependentCString(th.id()));
MOZ_ASSERT(keyed);
@ -3647,7 +3693,7 @@ Accumulate(ID aID, const nsCString& aKey, uint32_t aSample)
void
Accumulate(const char* name, uint32_t sample)
{
if (!TelemetryImpl::CanRecordExtended()) {
if (!TelemetryImpl::CanRecordBase()) {
return;
}
ID id;
@ -3659,7 +3705,7 @@ Accumulate(const char* name, uint32_t sample)
Histogram *h;
rv = GetHistogramByEnumId(id, &h);
if (NS_SUCCEEDED(rv)) {
HistogramAdd(*h, sample);
HistogramAdd(*h, sample, gHistograms[id].dataset);
}
}
@ -4066,7 +4112,7 @@ XRE_TelemetryAccumulate(int aID, uint32_t aSample)
KeyedHistogram::KeyedHistogram(const nsACString &name, const nsACString &expiration,
uint32_t histogramType, uint32_t min, uint32_t max,
uint32_t bucketCount)
uint32_t bucketCount, uint32_t dataset)
: mHistogramMap()
#if !defined(MOZ_WIDGET_GONK) && !defined(MOZ_WIDGET_ANDROID)
, mSubsessionMap()
@ -4077,6 +4123,7 @@ KeyedHistogram::KeyedHistogram(const nsACString &name, const nsACString &expirat
, mMin(min)
, mMax(max)
, mBucketCount(bucketCount)
, mDataset(dataset)
{
}
@ -4140,14 +4187,7 @@ nsresult
KeyedHistogram::GetDataset(uint32_t* dataset) const
{
MOZ_ASSERT(dataset);
Telemetry::ID id;
nsresult rv = TelemetryImpl::GetHistogramEnumId(mName.get(), &id);
if (NS_FAILED(rv)) {
return rv;
}
*dataset = gHistograms[id].dataset;
*dataset = mDataset;
return NS_OK;
}
@ -4162,7 +4202,7 @@ KeyedHistogram::ClearHistogramEnumerator(KeyedHistogramEntry* entry, void*)
nsresult
KeyedHistogram::Add(const nsCString& key, uint32_t sample)
{
if (!TelemetryImpl::CanRecordExtended()) {
if (!CanRecordDataset(mDataset)) {
return NS_OK;
}