Bug 1096785 - Add Telemetry::Accumulate() for keyed histograms. r=froydnj

This commit is contained in:
Georg Fritzsche 2014-11-11 11:45:40 +07:00
parent 71f98009f0
commit 37f99f6747
2 changed files with 52 additions and 0 deletions

View File

@ -622,6 +622,7 @@ public:
uint32_t histogramType, uint32_t min, uint32_t max,
uint32_t bucketCount);
nsresult GetHistogram(const nsCString& name, Histogram** histogram);
Histogram* GetHistogram(const nsCString& name);
uint32_t GetHistogramType() const { return mHistogramType; }
nsresult GetJSKeys(JSContext* cx, JS::CallArgs& args);
nsresult GetJSSnapshot(JSContext* cx, JS::Handle<JSObject*> obj);
@ -699,6 +700,16 @@ KeyedHistogram::GetHistogram(const nsCString& key, Histogram** histogram)
return NS_OK;
}
Histogram*
KeyedHistogram::GetHistogram(const nsCString& key)
{
Histogram* h = nullptr;
if (NS_FAILED(GetHistogram(key, &h))) {
return nullptr;
}
return h;
}
/* static */
PLDHashOperator
KeyedHistogram::ClearHistogramEnumerator(KeyedHistogramEntry* entry, void*)
@ -820,6 +831,8 @@ public:
};
typedef nsBaseHashtableET<nsCStringHashKey, StmtStats> SlowSQLEntryType;
static KeyedHistogram* GetKeyedHistogramById(const nsACString &id);
private:
TelemetryImpl();
~TelemetryImpl();
@ -2932,6 +2945,19 @@ TelemetryImpl::GetKeyedHistogramById(const nsACString &name, JSContext *cx,
return WrapAndReturnKeyedHistogram(keyed, cx, ret);
}
/* static */
KeyedHistogram*
TelemetryImpl::GetKeyedHistogramById(const nsACString &name)
{
if (!sTelemetry) {
return nullptr;
}
KeyedHistogram* keyed = nullptr;
sTelemetry->mKeyedHistograms.Get(name, &keyed);
return keyed;
}
NS_IMETHODIMP
TelemetryImpl::GetCanRecord(bool *ret) {
*ret = mCanRecord;
@ -3373,6 +3399,23 @@ Accumulate(ID aHistogram, uint32_t aSample)
h->Add(aSample);
}
void
Accumulate(ID aID, const nsCString& aKey, uint32_t aSample)
{
if (!TelemetryImpl::CanRecord()) {
return;
}
const TelemetryHistogram& th = gHistograms[aID];
KeyedHistogram* keyed = TelemetryImpl::GetKeyedHistogramById(nsDependentCString(th.id()));
MOZ_ASSERT(keyed);
Histogram* histogram = keyed->GetHistogram(aKey);
if (histogram) {
histogram->Add(aSample);
}
}
void
Accumulate(const char* name, uint32_t sample)
{

View File

@ -42,6 +42,15 @@ void Init();
*/
void Accumulate(ID id, uint32_t sample);
/**
* Adds sample to a keyed histogram defined in TelemetryHistograms.h
*
* @param id - keyed histogram id
* @param key - the string key
* @param sample - (optional) value to record, defaults to 1.
*/
void Accumulate(ID id, const nsCString& key, uint32_t sample = 1);
/**
* Adds a sample to a histogram defined in TelemetryHistograms.h.
* This function is here to support telemetry measurements from Java,