2015-09-04 01:01:36 -04:00
|
|
|
import {bind, Binding, Injector, OpaqueToken} from 'angular2/src/core/di';
|
2015-10-02 19:47:54 -04:00
|
|
|
import {ListWrapper, StringMapWrapper} from 'angular2/src/core/facade/collection';
|
2015-08-20 17:28:25 -04:00
|
|
|
import {Promise, PromiseWrapper} from 'angular2/src/core/facade/async';
|
2015-05-27 17:57:54 -04:00
|
|
|
|
|
|
|
import {Metric} from '../metric';
|
|
|
|
|
|
|
|
export class MultiMetric extends Metric {
|
2015-08-28 14:29:19 -04:00
|
|
|
static createBindings(childTokens): Binding[] {
|
2015-05-27 17:57:54 -04:00
|
|
|
return [
|
|
|
|
bind(_CHILDREN)
|
2015-06-26 18:59:18 -04:00
|
|
|
.toFactory(
|
|
|
|
(injector: Injector) => ListWrapper.map(childTokens, (token) => injector.get(token)),
|
|
|
|
[Injector]),
|
|
|
|
bind(MultiMetric).toFactory(children => new MultiMetric(children), [_CHILDREN])
|
2015-05-27 17:57:54 -04:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2015-08-28 14:29:19 -04:00
|
|
|
constructor(private _metrics: Metric[]) { super(); }
|
2015-05-27 17:57:54 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Starts measuring
|
|
|
|
*/
|
|
|
|
beginMeasure(): Promise<any> {
|
|
|
|
return PromiseWrapper.all(ListWrapper.map(this._metrics, (metric) => metric.beginMeasure()));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ends measuring and reports the data
|
|
|
|
* since the begin call.
|
|
|
|
* @param restart: Whether to restart right after this.
|
|
|
|
*/
|
2015-10-02 19:47:54 -04:00
|
|
|
endMeasure(restart: boolean): Promise<{[key: string]: any}> {
|
2015-05-27 17:57:54 -04:00
|
|
|
return PromiseWrapper.all(
|
|
|
|
ListWrapper.map(this._metrics, (metric) => metric.endMeasure(restart)))
|
|
|
|
.then((values) => { return mergeStringMaps(values); });
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Describes the metrics provided by this metric implementation.
|
|
|
|
* (e.g. units, ...)
|
|
|
|
*/
|
2015-10-02 19:47:54 -04:00
|
|
|
describe(): {[key: string]: any} {
|
2015-05-27 17:57:54 -04:00
|
|
|
return mergeStringMaps(this._metrics.map((metric) => metric.describe()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function mergeStringMaps(maps): Object {
|
|
|
|
var result = {};
|
|
|
|
ListWrapper.forEach(maps, (map) => {
|
|
|
|
StringMapWrapper.forEach(map, (value, prop) => { result[prop] = value; });
|
|
|
|
});
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-08-28 14:29:19 -04:00
|
|
|
var _CHILDREN = new OpaqueToken('MultiMetric.children');
|