1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 'use strict'; 6 7 base.require('tracing.analysis.util'); 8 base.require('ui'); 9 base.exportTo('tracing.analysis', function() { 10 11 function analyzeSingleCounterSampleHit(results, counterSampleHit) { 12 var ctr = counterSampleHit.counter; 13 var sampleIndex = counterSampleHit.sampleIndex; 14 15 var values = []; 16 for (var i = 0; i < ctr.numSeries; ++i) 17 values.push(ctr.getSeries(i).getSample(sampleIndex).value); 18 19 var table = results.appendTable('analysis-counter-table', 2); 20 results.appendTableHeader(table, 'Selected counter:'); 21 results.appendSummaryRow(table, 'Title', ctr.name); 22 results.appendSummaryRowTime( 23 table, 'Timestamp', ctr.timestamps[sampleIndex]); 24 25 for (var i = 0; i < ctr.numSeries; i++) 26 results.appendSummaryRow(table, ctr.getSeries(i).name, values[i]); 27 } 28 29 function analyzeMultipleCounterSampleHits(results, counterSampleHits) { 30 var hitsByCounter = {}; 31 for (var i = 0; i < counterSampleHits.length; i++) { 32 var ctr = counterSampleHits[i].counter; 33 if (!hitsByCounter[ctr.guid]) 34 hitsByCounter[ctr.guid] = []; 35 hitsByCounter[ctr.guid].push(counterSampleHits[i]); 36 } 37 38 var table = results.appendTable('analysis-counter-table', 2); 39 results.appendTableHeader(table, 'Counters:'); 40 for (var id in hitsByCounter) { 41 var hits = hitsByCounter[id]; 42 var ctr = hits[0].counter; 43 44 var sampleIndices = []; 45 for (var i = 0; i < hits.length; i++) 46 sampleIndices.push(hits[i].sampleIndex); 47 48 var stats = ctr.getSampleStatistics(sampleIndices); 49 for (var i = 0; i < stats.length; i++) { 50 var samples = []; 51 for (var k = 0; k < sampleIndices.length; ++k) 52 samples.push(ctr.getSeries(i).getSample(sampleIndices[k]).value); 53 54 results.appendDataRow( 55 table, 56 ctr.name + ': series(' + ctr.getSeries(i).name + ')', 57 samples, 58 samples.length, 59 stats[i]); 60 } 61 } 62 } 63 64 return { 65 analyzeSingleCounterSampleHit: analyzeSingleCounterSampleHit, 66 analyzeMultipleCounterSampleHits: analyzeMultipleCounterSampleHits 67 }; 68 }); 69