Phedenskog has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/398422 )

Change subject: Collect uncompressed size of all asset types.
......................................................................

Collect uncompressed size of all asset types.

Let us collect both compressed and uncompressed size and keep track of
them both in Graphite (size matters).

Bug: T182949
Change-Id: I21b1ce1c8e645a8886029de467c7e1436c255728
---
M lib/collectMetrics.js
M test/collectMetricsTest.js
2 files changed, 82 insertions(+), 30 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/performance/WebPageTest 
refs/changes/22/398422/1

diff --git a/lib/collectMetrics.js b/lib/collectMetrics.js
index 2a404e7..d041fcd 100644
--- a/lib/collectMetrics.js
+++ b/lib/collectMetrics.js
@@ -42,8 +42,10 @@
                                // the browser/location can then look like 
Dulles_MotoG_Motorola_G_Chrome
                                // but since there are no standard of naming it 
should be ok to just use what we got
                                let browser = wptJson.data.median[ view 
].browser_name ?
-                               wptJson.data.median[ view 
].browser_name.replace( / /g, '_' ) :
-                               wptJson.data.location.replace( 
/[^A-Za-z_0-9]/g, '_' ).replace( /__+/g, '_' );
+                                       wptJson.data.median[ view 
].browser_name.replace( / /g, '_' ) :
+                                       wptJson.data.location
+                                                       .replace( 
/[^A-Za-z_0-9]/g, '_' )
+                                                       .replace( /__+/g, '_' );
 
                                if ( emulateMobile ) {
                                        browser += '-emulateMobile';
@@ -52,17 +54,19 @@
                                // the actual location is the first part of the 
location string
                                // separated by either a : or _
                                const location = wptJson.data.location.split( 
/:|_/ )[ 0 ];
-                               const keyStart = namespace + '.' + location + 
'.' + browser + '.' + view + '.';
+                               const keyStart =
+                                       namespace + '.' + location + '.' + 
browser + '.' + view + '.';
 
                                metricsToCollect.forEach( function( metric ) {
                                        // We don't have all metrics for all 
browsers, for example LastInteractive
                                        if ( wptJson.data.median[ view ][ 
metric ] ) {
-                                               metricsToSend.timings[ keyStart 
+ metric ] = wptJson.data.median[ view ][ metric ];
+                                               metricsToSend.timings[ keyStart 
+ metric ] =
+                                                       wptJson.data.median[ 
view ][ metric ];
                                        }
                                } );
 
                                metricsToSend.misc[ keyStart + 'domElements' ] =
-                               wptJson.data.median[ view ].domElements;
+                                       wptJson.data.median[ view ].domElements;
 
                                // you need to turn on timeline collecting and 
use Chrome for this to work
                                if ( argv.timeline ) {
@@ -70,41 +74,46 @@
                                                const cpuTimes = cpuTime.sum( 
wptJson.data.median[ view ].cpuTimes );
                                                Object.keys( cpuTimes 
).forEach( function( time ) {
                                                        metricsToSend.cpuTimes[ 
keyStart + 'cpuTimes.' + time ] =
-                                                       cpuTimes[ time ];
+                                                               cpuTimes[ time 
];
                                                } );
                                        }
                                        if ( wptJson.data.median[ view 
].cpuTimesDoc ) {
-                                               const cpuTimesDoc = 
cpuTime.sum( wptJson.data.median[ view ].cpuTimesDoc );
+                                               const cpuTimesDoc = cpuTime.sum(
+                                                       wptJson.data.median[ 
view ].cpuTimesDoc
+                                               );
                                                Object.keys( cpuTimesDoc 
).forEach( function( cpuTimeDoc ) {
                                                        metricsToSend.cpuTimes[ 
keyStart + 'cpuTimesDoc.' + cpuTimeDoc ] =
-                                                       cpuTimesDoc[ cpuTimeDoc 
];
+                                                               cpuTimesDoc[ 
cpuTimeDoc ];
                                                } );
                                        }
                                }
 
                                if ( wptJson.data.median[ view ].userTimes ) {
-                                       Object.keys( wptJson.data.median[ view 
].userTimes ).forEach( function( userTiming ) {
+                                       Object.keys( wptJson.data.median[ view 
].userTimes ).forEach( function(
+                                               userTiming
+                                       ) {
                                                metricsToSend.timings[ keyStart 
+ userTiming ] =
-                                               wptJson.data.median[ view 
].userTimes[ userTiming ];
+                                                       wptJson.data.median[ 
view ].userTimes[ userTiming ];
                                        } );
                                } else {
                                        console.error( 'Missing user timing 
metrics for view ' + view );
                                }
 
                                // collect sizes & assets
-                               Object.keys( wptJson.data.median[ view 
].breakdown ).forEach( function( assetType ) {
-                                       metricsToSend.requests[ keyStart +
-                                               assetType + '.requests' ] = 
wptJson.data.median[ view ].breakdown[ assetType ]
-                                               .requests;
-                                       metricsToSend.sizes[ keyStart +
-                                               assetType + '.bytes' ] =
+                               Object.keys( wptJson.data.median[ view 
].breakdown ).forEach( function(
+                                       assetType
+                               ) {
+                                       metricsToSend.requests[ keyStart + 
assetType + '.requests' ] =
+                                               wptJson.data.median[ view 
].breakdown[ assetType ].requests;
+                                       metricsToSend.sizes[ keyStart + 
assetType + '.bytes' ] =
                                                wptJson.data.median[ view 
].breakdown[ assetType ].bytes;
+                                       metricsToSend.sizes[ keyStart + 
assetType + '.bytesUncompressed' ] =
+                                               wptJson.data.median[ view 
].breakdown[ assetType ].bytesUncompressed;
 
                                        // Collect the total size, we need it 
for Opera Mini and UC Mini where the size
                                        // is not reported per type
                                        metricsToSend.sizes[ keyStart + 
'total.bytes' ] =
-                                       wptJson.data.median[ view ].bytesIn;
-
+                                               wptJson.data.median[ view 
].bytesIn;
                                } );
                        } else {
                                // When we get a result error 99998 from 
WebPageTest, the repeat view is left out
diff --git a/test/collectMetricsTest.js b/test/collectMetricsTest.js
index 42f0e64..73a30d9 100644
--- a/test/collectMetricsTest.js
+++ b/test/collectMetricsTest.js
@@ -6,18 +6,30 @@
 const desktopJson = JSON.parse( util.readFile( 
'test/files/desktop_result.json' ) );
 
 describe( 'Test colllect metrics', function() {
-
        it( 'We should be able to parse a JSON from WebPageTest collecting data 
from desktop', function() {
                const metrics = cm.collect( desktopJson, cli.getMinimistArgv( 
[] ) );
                Object.keys( metrics ).forEach( function( type ) {
                        Object.keys( metrics[ type ] ).forEach( function( key ) 
{
-                               assert.strictEqual( metrics[ type ][ key 
].toString().indexOf( 'undefined' ), -1,
-                                       'We have an undefined value in ' + key 
);
+                               assert.strictEqual(
+                                       metrics[ type ][ key 
].toString().indexOf( 'undefined' ),
+                                       -1,
+                                       'We have an undefined value in ' + key
+                               );
                        } );
                } );
 
                // verify that we collect all the metrics that we want
-               [ 'SpeedIndex', 'render', 'TTFB', 'fullyLoaded', 
'lastVisualChange', 'domElements', 'visualComplete95', 'visualComplete99', 
'LastInteractive' ].forEach( function( definedMetric ) {
+               [
+                       'SpeedIndex',
+                       'render',
+                       'TTFB',
+                       'fullyLoaded',
+                       'lastVisualChange',
+                       'domElements',
+                       'visualComplete95',
+                       'visualComplete99',
+                       'LastInteractive'
+               ].forEach( function( definedMetric ) {
                        let metricIncluded = false;
                        Object.keys( metrics ).forEach( function( type ) {
                                Object.keys( metrics[ type ] ).forEach( 
function( key ) {
@@ -26,20 +38,34 @@
                                        }
                                } );
                        } );
-                       assert.strictEqual( metricIncluded, true, 'We are 
missing metric ' + definedMetric );
+                       assert.strictEqual(
+                               metricIncluded,
+                               true,
+                               'We are missing metric ' + definedMetric
+                       );
                } );
 
+               // Each request type should hold this info
+               const requestInfo = { requests: 1, bytes: 1, bytesUncompressed: 
1 };
                // verify that we collect all the metrics that we want
-               [ 'html', 'js', 'css', 'font', 'flash', 'other' ].forEach( 
function( definedMetric ) {
+               [ 'html', 'js', 'css', 'font', 'flash', 'other' ].forEach( 
function(
+                       definedMetric
+               ) {
                        let metricIncluded = false;
                        Object.keys( metrics ).forEach( function( type ) {
                                Object.keys( metrics[ type ] ).forEach( 
function( key ) {
                                        if ( key.indexOf( definedMetric ) > -1 
) {
-                                               metricIncluded = true;
+                                               if ( requestInfo[ key.substr( 
key.lastIndexOf( '.' ) + 1 ) ] ) {
+                                                       metricIncluded = true;
+                                               }
                                        }
                                } );
                        } );
-                       assert.strictEqual( metricIncluded, true, 'We are 
missing asset type ' + definedMetric );
+                       assert.strictEqual(
+                               metricIncluded,
+                               true,
+                               'We are missing asset type ' + definedMetric
+                       );
                } );
        } );
 
@@ -49,13 +75,26 @@
                        Object.keys( metrics[ type ] ).forEach( function( key ) 
{
                                // verify that we aren't fetching any undefined 
values =
                                // values missing in the WPT file
-                               assert.strictEqual( metrics[ type ][ key 
].toString().indexOf( 'undefined' ), -1,
-                                       'We have an undefined value in ' + key 
);
+                               assert.strictEqual(
+                                       metrics[ type ][ key 
].toString().indexOf( 'undefined' ),
+                                       -1,
+                                       'We have an undefined value in ' + key
+                               );
                        } );
                } );
 
                // verify that we collect all the metrics that we want
-               [ 'SpeedIndex', 'render', 'TTFB', 'fullyLoaded', 
'lastVisualChange', 'domElements', 'visualComplete95', 'visualComplete99', 
'LastInteractive' ].forEach( function( definedMetric ) {
+               [
+                       'SpeedIndex',
+                       'render',
+                       'TTFB',
+                       'fullyLoaded',
+                       'lastVisualChange',
+                       'domElements',
+                       'visualComplete95',
+                       'visualComplete99',
+                       'LastInteractive'
+               ].forEach( function( definedMetric ) {
                        let metricIncluded = false;
                        Object.keys( metrics ).forEach( function( type ) {
                                Object.keys( metrics[ type ] ).forEach( 
function( key ) {
@@ -64,7 +103,11 @@
                                        }
                                } );
                        } );
-                       assert.strictEqual( metricIncluded, true, 'We are 
missing metric ' + definedMetric );
+                       assert.strictEqual(
+                               metricIncluded,
+                               true,
+                               'We are missing metric ' + definedMetric
+                       );
                } );
        } );
 } );

-- 
To view, visit https://gerrit.wikimedia.org/r/398422
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I21b1ce1c8e645a8886029de467c7e1436c255728
Gerrit-PatchSet: 1
Gerrit-Project: performance/WebPageTest
Gerrit-Branch: master
Gerrit-Owner: Phedenskog <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to