mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-02 15:15:23 +00:00
Bug 701863 - Add a way to clone histograms; r=taras
Add nsITelemetry::histogramFrom.
This commit is contained in:
parent
2aa7a4a087
commit
3603a076fe
@ -105,6 +105,25 @@ const TelemetryHistogram gHistograms[] = {
|
||||
#undef HISTOGRAM
|
||||
};
|
||||
|
||||
bool
|
||||
TelemetryHistogramType(Histogram *h, PRUint32 *result)
|
||||
{
|
||||
switch (h->histogram_type()) {
|
||||
case Histogram::HISTOGRAM:
|
||||
*result = nsITelemetry::HISTOGRAM_EXPONENTIAL;
|
||||
break;
|
||||
case Histogram::LINEAR_HISTOGRAM:
|
||||
*result = nsITelemetry::HISTOGRAM_LINEAR;
|
||||
break;
|
||||
case Histogram::BOOLEAN_HISTOGRAM:
|
||||
*result = nsITelemetry::HISTOGRAM_BOOLEAN;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
nsresult
|
||||
HistogramGet(const char *name, PRUint32 min, PRUint32 max, PRUint32 bucketCount,
|
||||
PRUint32 histogramType, Histogram **result)
|
||||
@ -316,6 +335,33 @@ TelemetryImpl::GetHistogramByName(const nsACString &name, Histogram **ret)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
TelemetryImpl::HistogramFrom(const nsACString &name, const nsACString &existing_name,
|
||||
JSContext *cx, jsval *ret)
|
||||
{
|
||||
Histogram *existing;
|
||||
nsresult rv = GetHistogramByName(existing_name, &existing);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
PRUint32 histogramType;
|
||||
bool success = TelemetryHistogramType(existing, &histogramType);
|
||||
if (!success)
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
||||
Histogram *clone;
|
||||
rv = NewUserHistogram(name, existing->declared_min(),
|
||||
existing->declared_max(), existing->bucket_count(),
|
||||
histogramType, &clone);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
Histogram::SampleSet ss;
|
||||
existing->SnapshotSample(&ss);
|
||||
clone->AddSampleSet(ss);
|
||||
return WrapAndReturnHistogram(clone, cx, ret);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
TelemetryImpl::GetHistogramSnapshots(JSContext *cx, jsval *ret)
|
||||
{
|
||||
|
@ -81,6 +81,17 @@ interface nsITelemetry : nsISupports
|
||||
[implicit_jscontext]
|
||||
jsval newHistogram(in ACString name, in PRUint32 min, in PRUint32 max, in PRUint32 bucket_count, in unsigned long histogram_type);
|
||||
|
||||
/**
|
||||
* Create a histogram using the current state of an existing histogram. The
|
||||
* existing histogram must be registered in TelemetryHistograms.h.
|
||||
*
|
||||
* @param name Unique histogram name
|
||||
* @param existing_name Existing histogram name
|
||||
* The returned object has the same functions as a histogram returned from newHistogram.
|
||||
*/
|
||||
[implicit_jscontext]
|
||||
jsval histogramFrom(in ACString name, in ACString existing_name);
|
||||
|
||||
/**
|
||||
* Same as newHistogram above, but for histograms registered in TelemetryHistograms.h.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user