Chromium Code Reviews| Index: tracing/tracing/value/diagnostics/composition.html |
| diff --git a/tracing/tracing/value/diagnostics/composition.html b/tracing/tracing/value/diagnostics/composition.html |
| index 5561efaf365e28fcc1b5886e72ed25eb00b929d4..7b087e212399ebb0fdd74a5ed00679b0dae0817e 100644 |
| --- a/tracing/tracing/value/diagnostics/composition.html |
| +++ b/tracing/tracing/value/diagnostics/composition.html |
| @@ -16,6 +16,58 @@ tr.exportTo('tr.v.d', function() { |
| tr.v.d.RelatedValueMap.call(this); |
| } |
| + /** |
| + * Build a Composition and its NumericValues from |events|. Group events using |
| + * |categoryForEvent|. Add the NumericValues to |values|. NumericValues' names |
| + * are prefixed with |namePrefix|. Numerics are built by |numericBuilder|. The |
| + * Numeric sample for each Event is derived from |opt_sampleForEvent|, which |
| + * defaults to event.cpuSelfTime. The caller must add the result Composition |
| + * to their Value's diagnostics. |
| + * |
| + * Composition encapsulates a generic relationship between NumericValues that |
|
charliea (OOO until 10-5)
2016/07/13 14:30:06
Generally, the jsdoc describing what a type is goe
|
| + * can hold for groups of other things besides Events, such as memory |
|
charliea (OOO until 10-5)
2016/07/13 14:30:06
I don't really have much context about Composition
|
| + * allocations. Compositions over groups of Events is expected to be the most |
| + * common way of building Compositions, though it is not the only way. |
| + * |
| + * @param {!tr.v.ValueSet} values |
| + * @param {string} namePrefix |
|
nednguyen
2016/07/13 02:17:32
I still think this namePrefix is redundant. If peo
benjhayden
2016/07/13 04:41:28
The category isn't only used for the composing Val
nednguyen
2016/07/13 11:34:02
Hmhh, this makes sense but now I think about it, h
benjhayden
2016/07/13 18:03:04
Sorry, I'm doing mega-CLs this week. :-)
This is a
|
| + * @param {!tr.model.EventSet} events |
| + * @param {!tr.v.NumericBuilder} numericBuilder |
| + * @param {!function(!tr.model.Event):string} categoryForEvent |
| + * @param {!function(!tr.model.Event):number=} opt_sampleForEvent |
| + * @param {*=} opt_this |
| + * @return {!Composition} |
| + */ |
| + Composition.buildFromEvents = function( |
|
nednguyen
2016/07/13 02:17:32
s/buildFromEvents/buildFromEventCategories ? I don
|
| + values, namePrefix, events, numericBuilder, categoryForEvent, |
| + opt_sampleForEvent, opt_this) { |
| + var eventCallback = opt_sampleForEvent; |
| + if (eventCallback === undefined) { |
| + eventCallback = function(event) { |
|
charliea (OOO until 10-5)
2016/07/13 14:30:06
nit: can be (event) => event.cpuSelfTime
|
| + return event.cpuSelfTime; |
| + }; |
| + } |
| + |
| + var composition = new Composition(); |
| + for (var event of events) { |
| + var sample = eventCallback.call(opt_this, event); |
| + if (sample === undefined) |
| + continue; |
| + |
| + var eventCategory = categoryForEvent.call(opt_this, event); |
| + var value = composition.get(eventCategory); |
| + if (value === undefined) { |
| + value = new tr.v.NumericValue( |
| + namePrefix + eventCategory, numericBuilder.build()); |
| + values.addValue(value); |
| + composition.set(eventCategory, value); |
| + } |
| + |
| + value.numeric.add(sample, new tr.v.d.RelatedEventSet([event])); |
| + } |
| + return composition; |
| + }; |
| + |
| Composition.prototype = { |
| __proto__: tr.v.d.RelatedValueMap.prototype, |