| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <!-- | 2 <!-- |
| 3 Copyright 2016 The Chromium Authors. All rights reserved. | 3 Copyright 2016 The Chromium Authors. All rights reserved. |
| 4 Use of this source code is governed by a BSD-style license that can be | 4 Use of this source code is governed by a BSD-style license that can be |
| 5 found in the LICENSE file. | 5 found in the LICENSE file. |
| 6 --> | 6 --> |
| 7 | 7 |
| 8 <link rel="import" href="/tracing/core/test_utils.html"> | 8 <link rel="import" href="/tracing/core/test_utils.html"> |
| 9 <link rel="import" href="/tracing/extras/importer/trace_event_importer.html"> | 9 <link rel="import" href="/tracing/extras/importer/trace_event_importer.html"> |
| 10 <link rel="import" href="/tracing/metrics/tracing_metric.html"> | 10 <link rel="import" href="/tracing/metrics/tracing_metric.html"> |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 }); | 22 }); |
| 23 } | 23 } |
| 24 | 24 |
| 25 function getEventStringSize(events, indices) { | 25 function getEventStringSize(events, indices) { |
| 26 return indices.reduce(function(sum, index) { | 26 return indices.reduce(function(sum, index) { |
| 27 return sum + JSON.stringify(events[index]).length; | 27 return sum + JSON.stringify(events[index]).length; |
| 28 }, 0); | 28 }, 0); |
| 29 } | 29 } |
| 30 | 30 |
| 31 function checkDurationValue(allValues, metricName, expected) { | 31 function checkDurationValue(allValues, metricName, expected) { |
| 32 var values = allValues.getValuesWithName(metricName); | 32 var values = allValues.getValuesWithName(metricName + '_avg'); |
| 33 assert.lengthOf(values, 1); | 33 assert.lengthOf(values, 1); |
| 34 assert.closeTo(1000 * values[0].numeric.value, expected, 0.1); | 34 assert.closeTo(1000 * values[0].numeric.value, expected, 0.1); |
| 35 } | 35 } |
| 36 | 36 |
| 37 test('hasEventSizesInBytes', function() { | 37 test('hasEventSizesInBytes', function() { |
| 38 var allValues = new tr.v.ValueSet(); | 38 var allValues = new tr.v.ValueSet(); |
| 39 var events = [ | 39 var events = [ |
| 40 {name: 'a', args: {}, pid: 52, ts: 524, cat: 'foo', tid: 53, ph: 'B'}, | 40 {name: 'a', args: {}, pid: 52, ts: 524, cat: 'foo', tid: 53, ph: 'B'}, |
| 41 {name: 'a', args: {}, pid: 52, ts: 560, cat: 'foo', tid: 53, ph: 'B'} | 41 {name: 'a', args: {}, pid: 52, ts: 560, cat: 'foo', tid: 53, ph: 'B'} |
| 42 ]; | 42 ]; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 55 test('totalTraceSize', function() { | 55 test('totalTraceSize', function() { |
| 56 var allValues = new tr.v.ValueSet(); | 56 var allValues = new tr.v.ValueSet(); |
| 57 var events = [ | 57 var events = [ |
| 58 {name: 'a', args: {}, pid: 52, ts: 524, cat: 'foo', tid: 53, ph: 'B'}, | 58 {name: 'a', args: {}, pid: 52, ts: 524, cat: 'foo', tid: 53, ph: 'B'}, |
| 59 {name: 'a', args: {}, pid: 52, ts: 560, cat: 'foo', tid: 53, ph: 'B'} | 59 {name: 'a', args: {}, pid: 52, ts: 560, cat: 'foo', tid: 53, ph: 'B'} |
| 60 ]; | 60 ]; |
| 61 var model = makeModel(JSON.stringify(events), true); | 61 var model = makeModel(JSON.stringify(events), true); |
| 62 tr.metrics.tracingMetric(allValues, model); | 62 tr.metrics.tracingMetric(allValues, model); |
| 63 | 63 |
| 64 var eventStringSize = getEventStringSize(events, [0, 1]); | 64 var eventStringSize = getEventStringSize(events, [0, 1]); |
| 65 var values = allValues.getValuesWithName('Total trace size in bytes'); | 65 var values = allValues.getValuesWithName('Total trace size in bytes_avg'); |
| 66 assert.strictEqual(values.length, 1); | 66 assert.lengthOf(values, 1); |
| 67 assert.strictEqual(values[0].numeric.value, eventStringSize); | 67 assert.strictEqual(values[0].numeric.value, eventStringSize); |
| 68 }); | 68 }); |
| 69 | 69 |
| 70 test('maxValuePerSec', function() { | 70 test('maxValuePerSec', function() { |
| 71 var ONE_SEC_IN_US = 1000000; | 71 var ONE_SEC_IN_US = 1000000; |
| 72 var events = [ | 72 var events = [ |
| 73 {name: 'a', pid: 52, ts: 1, cat: 'foo', ph: 'B'}, | 73 {name: 'a', pid: 52, ts: 1, cat: 'foo', ph: 'B'}, |
| 74 {name: 'a', pid: 52, ts: ONE_SEC_IN_US + 1, cat: 'foo', ph: 'B'}, | 74 {name: 'a', pid: 52, ts: ONE_SEC_IN_US + 1, cat: 'foo', ph: 'B'}, |
| 75 {name: 'a', pid: 52, ts: 2 * ONE_SEC_IN_US + 1, cat: 'foo', ph: 'B'}, | 75 {name: 'a', pid: 52, ts: 2 * ONE_SEC_IN_US + 1, cat: 'foo', ph: 'B'}, |
| 76 {name: 'a', pid: 52, ts: 2 * ONE_SEC_IN_US + 3, cat: 'foo', ph: 'B'}, | 76 {name: 'a', pid: 52, ts: 2 * ONE_SEC_IN_US + 3, cat: 'foo', ph: 'B'}, |
| 77 {name: 'a', pid: 52, ts: ONE_SEC_IN_US + 2, cat: 'foo', ph: 'B'}, | 77 {name: 'a', pid: 52, ts: ONE_SEC_IN_US + 2, cat: 'foo', ph: 'B'}, |
| 78 {name: 'a', pid: 52, ts: 2 * ONE_SEC_IN_US + 2, cat: 'foo', ph: 'B'} | 78 {name: 'a', pid: 52, ts: 2 * ONE_SEC_IN_US + 2, cat: 'foo', ph: 'B'} |
| 79 ]; | 79 ]; |
| 80 var model = makeModel(JSON.stringify(events), true); | 80 var model = makeModel(JSON.stringify(events), true); |
| 81 var allValues = new tr.v.ValueSet(); | 81 var allValues = new tr.v.ValueSet(); |
| 82 tr.metrics.tracingMetric(allValues, model); | 82 tr.metrics.tracingMetric(allValues, model); |
| 83 | 83 |
| 84 var maxEventCountPerSec = 3; | 84 var maxEventCountPerSec = 3; |
| 85 var values = allValues.getValuesWithName('Max number of events per second'); | 85 var values = allValues.getValuesWithName( |
| 86 assert.strictEqual(values.length, 1); | 86 'Max number of events per second_avg'); |
| 87 assert.lengthOf(values, 1); |
| 87 assert.strictEqual(values[0].numeric.value, maxEventCountPerSec); | 88 assert.strictEqual(values[0].numeric.value, maxEventCountPerSec); |
| 88 | 89 |
| 89 var maxEventBytesPerSec = getEventStringSize(events, [2, 3, 5]); | 90 var maxEventBytesPerSec = getEventStringSize(events, [2, 3, 5]); |
| 90 var values = allValues.getValuesWithName( | 91 var values = allValues.getValuesWithName( |
| 91 'Max event size in bytes per second'); | 92 'Max event size in bytes per second_avg'); |
| 92 assert.strictEqual(values.length, 1); | 93 assert.lengthOf(values, 1); |
| 93 assert.strictEqual(values[0].numeric.value, maxEventBytesPerSec); | 94 assert.strictEqual(values[0].numeric.value, maxEventBytesPerSec); |
| 94 }); | 95 }); |
| 95 | 96 |
| 96 test('diagnostics', function() { | 97 test('diagnostics', function() { |
| 97 var allValues = new tr.v.ValueSet(); | 98 var allValues = new tr.v.ValueSet(); |
| 98 var events = [ | 99 var events = [ |
| 99 {name: 'a', args: {}, pid: 52, ts: 524, cat: 'foo', tid: 53, ph: 'B'}, | 100 {name: 'a', args: {}, pid: 52, ts: 524, cat: 'foo', tid: 53, ph: 'B'}, |
| 100 {name: 'a', args: {}, pid: 52, ts: 535, cat: 'foo', tid: 53, ph: 'B'}, | 101 {name: 'a', args: {}, pid: 52, ts: 535, cat: 'foo', tid: 53, ph: 'B'}, |
| 101 {name: 'bb', args: {}, pid: 52, ts: 546, cat: 'bar', tid: 53, ph: 'E'}, | 102 {name: 'bb', args: {}, pid: 52, ts: 546, cat: 'bar', tid: 53, ph: 'E'}, |
| 102 {name: 'a', args: {}, pid: 52, ts: 560, cat: 'foo', tid: 53, ph: 'B'}, | 103 {name: 'a', args: {}, pid: 52, ts: 560, cat: 'foo', tid: 53, ph: 'B'}, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 ]; | 138 ]; |
| 138 | 139 |
| 139 var model = makeModel(JSON.stringify(events), true); | 140 var model = makeModel(JSON.stringify(events), true); |
| 140 tr.model.MemoryDumpTestUtils.addGlobalMemoryDump(model, {ts: 550}); | 141 tr.model.MemoryDumpTestUtils.addGlobalMemoryDump(model, {ts: 550}); |
| 141 tr.metrics.tracingMetric(allValues, model); | 142 tr.metrics.tracingMetric(allValues, model); |
| 142 | 143 |
| 143 var memoryCategorySize = events.filter( | 144 var memoryCategorySize = events.filter( |
| 144 slice => slice['cat'] === MEMORY_INFRA_TRACING_CATEGORY).reduce( | 145 slice => slice['cat'] === MEMORY_INFRA_TRACING_CATEGORY).reduce( |
| 145 (acc, slice) => acc + JSON.stringify(slice).length, 0); | 146 (acc, slice) => acc + JSON.stringify(slice).length, 0); |
| 146 var totalSizeValue = allValues.getValuesWithName( | 147 var totalSizeValue = allValues.getValuesWithName( |
| 147 'Total trace size of memory-infra dumps in bytes'); | 148 'Total trace size of memory-infra dumps in bytes_avg'); |
| 148 assert.lengthOf(totalSizeValue, 1); | 149 assert.lengthOf(totalSizeValue, 1); |
| 149 assert.strictEqual(totalSizeValue[0].numeric.value, memoryCategorySize); | 150 assert.strictEqual(totalSizeValue[0].numeric.value, memoryCategorySize); |
| 150 var sizePerDumpValue = allValues.getValuesWithName( | 151 var sizePerDumpValue = allValues.getValuesWithName( |
| 151 'Average trace size of memory-infra dumps in bytes'); | 152 'Average trace size of memory-infra dumps in bytes_avg'); |
| 152 assert.lengthOf(sizePerDumpValue, 1); | 153 assert.lengthOf(sizePerDumpValue, 1); |
| 153 assert.strictEqual(sizePerDumpValue[0].numeric.value, memoryCategorySize); | 154 assert.strictEqual(sizePerDumpValue[0].numeric.value, memoryCategorySize); |
| 154 | 155 |
| 155 checkDurationValue(allValues, | 156 checkDurationValue(allValues, |
| 156 'Average CPU overhead of mdp1 per OnMemoryDump call', 6.5); | 157 'Average CPU overhead of mdp1 per OnMemoryDump call', 6.5); |
| 157 checkDurationValue(allValues, | 158 checkDurationValue(allValues, |
| 158 'Average CPU overhead of mdp2 per OnMemoryDump call', 16); | 159 'Average CPU overhead of mdp2 per OnMemoryDump call', 16); |
| 159 checkDurationValue(allValues, | 160 checkDurationValue(allValues, |
| 160 'Average CPU overhead of mdp3 per OnMemoryDump call', 6); | 161 'Average CPU overhead of mdp3 per OnMemoryDump call', 6); |
| 161 checkDurationValue(allValues, | 162 checkDurationValue(allValues, |
| 162 'Average CPU overhead of mdp4 per OnMemoryDump call', 8); | 163 'Average CPU overhead of mdp4 per OnMemoryDump call', 8); |
| 163 checkDurationValue(allValues, | 164 checkDurationValue(allValues, |
| 164 'Average CPU overhead on non-memory-infra threads per memory-infra ' + | 165 'Average CPU overhead on non-memory-infra threads per memory-infra ' + |
| 165 'dump', | 166 'dump', |
| 166 47); | 167 47); |
| 167 checkDurationValue(allValues, | 168 checkDurationValue(allValues, |
| 168 'Average CPU overhead on all threads per memory-infra dump', 91); | 169 'Average CPU overhead on all threads per memory-infra dump', 91); |
| 169 }); | 170 }); |
| 170 | 171 |
| 171 }); | 172 }); |
| 172 </script> | 173 </script> |
| OLD | NEW |