@@ -2,11 +2,16 @@ var google = require('googleapis');
22var bigquery = google . bigquery ( 'v2' ) ;
33var webdriver = require ( 'protractor/node_modules/selenium-webdriver' ) ;
44
5- var HEADER_FIELDS = [
5+ var TABLE_FIELDS = [
66 {
77 "name" : 'runId' ,
88 "type" : 'STRING' ,
9- "description" : 'uuid for the benchmark run'
9+ "description" : 'git SHA and uuid for the benchmark run'
10+ } ,
11+ {
12+ "name" : 'benchmarkId' ,
13+ "type" : 'STRING' ,
14+ "description" : 'id of the benchmark'
1015 } ,
1116 {
1217 "name" : 'index' ,
@@ -26,22 +31,65 @@ var HEADER_FIELDS = [
2631 "name" : 'forceGc' ,
2732 "type" : 'BOOLEAN' ,
2833 "description" : 'whether gc was forced at end of action'
34+ } ,
35+ {
36+ "name" : 'stable' ,
37+ "type" : 'BOOLEAN' ,
38+ "description" : 'whether this entry was part of the stable sample'
39+ } ,
40+ {
41+ "name" : 'params' ,
42+ "type" : 'RECORD' ,
43+ "description" : 'parameters of the benchmark' ,
44+ "mode" : 'REPEATED' ,
45+ "fields" : [
46+ {
47+ "name" : 'name' ,
48+ "type" : 'STRING' ,
49+ "description" : 'param name'
50+ } ,
51+ {
52+ "name" : 'strvalue' ,
53+ "type" : 'STRING' ,
54+ "description" : 'param value for strings'
55+ } ,
56+ {
57+ "name" : 'numvalue' ,
58+ "type" : 'FLOAT' ,
59+ "description" : 'param value for numbers'
60+ }
61+ ]
62+ } ,
63+ {
64+ "name" : 'metrics' ,
65+ "type" : 'RECORD' ,
66+ "description" : 'metrics of the benchmark' ,
67+ "mode" : 'REPEATED' ,
68+ "fields" : [
69+ {
70+ "name" : 'name' ,
71+ "type" : 'STRING' ,
72+ "description" : 'metric name'
73+ } ,
74+ {
75+ "name" : 'value' ,
76+ "type" : 'FLOAT' ,
77+ "description" : 'metric value'
78+ }
79+ ]
2980 }
3081] ;
3182
3283class CloudReporter {
33- constructor ( runId , benchmarkConfig ) {
34- this . stableRowsTableConfig = createTableConfig ( benchmarkConfig , '_stable' ) ;
35- this . allRowsTableConfig = createTableConfig ( benchmarkConfig , '_all' )
84+ constructor ( benchmarkConfig ) {
85+ this . tableConfig = createTableConfig ( benchmarkConfig ) ;
3686 this . authConfig = benchmarkConfig . cloudReporter . auth ;
3787 this . benchmarkConfig = benchmarkConfig ;
38- this . runId = runId ;
39- this . allRows = [ ] ;
88+ this . allSample = [ ] ;
4089 var self = this ;
4190 browser . executeScript ( 'return navigator.userAgent' ) . then ( function ( userAgent ) {
4291 self . browserUserAgent = userAgent ;
4392 } ) ;
44-
4593 }
4694 begin ( ) {
4795 var self = this ;
@@ -52,66 +100,62 @@ class CloudReporter {
52100 } ) ;
53101 } ) ;
54102 flow . execute ( function ( ) {
55- return webdriver . promise . all ( [
56- getOrCreateTable ( self . authClient , self . allRowsTableConfig ) ,
57- getOrCreateTable ( self . authClient , self . stableRowsTableConfig )
58- ] ) ;
103+ return getOrCreateTable ( self . authClient , self . tableConfig ) ;
59104 } ) ;
60105 }
61106 add ( data ) {
62- this . allRows . push ( this . _convertToTableRow ( data ) ) ;
107+ this . allSample . push ( data ) ;
63108 }
64109 end ( stableSample ) {
65110 var self = this ;
66111 var flow = browser . driver . controlFlow ( ) ;
67- var stableRows = stableSample . map ( function ( data ) {
68- return self . _convertToTableRow ( data ) ;
112+ var allRows = this . allSample . map ( function ( data ) {
113+ return self . _convertToTableRow ( data , stableSample ) ;
69114 } ) ;
70115 flow . execute ( function ( ) {
71- return webdriver . promise . all ( [
72- insertRows ( self . authClient , self . stableRowsTableConfig , stableRows ) ,
73- insertRows ( self . authClient , self . allRowsTableConfig , self . allRows )
74- ] ) ;
116+ return insertRows ( self . authClient , self . tableConfig , allRows )
75117 } ) ;
76118 }
77- _convertToTableRow ( benchpressRow ) {
119+ _convertToTableRow ( benchpressRow , stableSample ) {
78120 var tableRow = {
79- runId : this . runId ,
121+ runId : this . benchmarkConfig . runId ,
122+ benchmarkId : this . benchmarkConfig . id ,
80123 index : benchpressRow . index ,
81124 creationTime : new Date ( ) ,
82125 browser : this . browserUserAgent ,
83- forceGc : benchpressRow . forceGc
126+ forceGc : benchpressRow . forceGc ,
127+ stable : stableSample . indexOf ( benchpressRow ) >= 0 ,
128+ params : this . benchmarkConfig . params . map ( function ( param ) {
129+ if ( typeof param . value === 'number' ) {
130+ return {
131+ name : param . name ,
132+ numvalue : param . value
133+ } ;
134+ } else {
135+ return {
136+ name : param . name ,
137+ strvalue : '' + param . value
138+ }
139+ }
140+ } ) ,
141+ metrics : this . benchmarkConfig . metrics . map ( function ( metricName , index ) {
142+ return {
143+ name : metricName ,
144+ value : benchpressRow . values [ index ]
145+ } ;
146+ } )
84147 } ;
85- this . benchmarkConfig . params . forEach ( function ( param ) {
86- tableRow [ 'p_' + param . name ] = param . value ;
87- } ) ;
88- this . benchmarkConfig . metrics . forEach ( function ( metric , index ) {
89- tableRow [ 'm_' + metric ] = benchpressRow . values [ index ] ;
90- } ) ;
91148 return tableRow ;
92149 }
93150}
94151
95- function createTableConfig ( benchmarkConfig , tableSuffix ) {
96- var tableId = ( benchmarkConfig . id + tableSuffix ) . replace ( / \. / g, '_' ) ;
152+ function createTableConfig ( benchmarkConfig ) {
97153 return {
98154 projectId : benchmarkConfig . cloudReporter . projectId ,
99155 datasetId : benchmarkConfig . cloudReporter . datasetId ,
100156 table : {
101- id : tableId ,
102- fields : HEADER_FIELDS
103- . concat ( benchmarkConfig . params . map ( function ( param ) {
104- return {
105- "name" : 'p_' + param . name ,
106- "type" : 'FLOAT'
107- } ;
108- } ) )
109- . concat ( benchmarkConfig . metrics . map ( function ( metricName ) {
110- return {
111- "name" : 'm_' + metricName ,
112- "type" : 'FLOAT'
113- } ;
114- } ) )
157+ id : benchmarkConfig . cloudReporter . tableId ,
158+ fields : TABLE_FIELDS
115159 }
116160 } ;
117161}
0 commit comments