Bug 701863 - Add a way to clone histograms; r=taras

Add nsITelemetry::histogramFrom.
This commit is contained in:
Nathan Froyd 2011-11-14 14:28:18 -05:00
Родитель 2aa7a4a087
Коммит 3603a076fe
2 изменённых файлов: 57 добавлений и 0 удалений

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

@ -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.
*