1
1
import fs from 'fs'
2
2
import path from 'path'
3
+ import _ from 'lodash'
3
4
import flamegrill , { CookResult , CookResults , ScenarioConfig , Scenarios } from 'flamegrill'
4
5
5
6
import { generateUrl } from '@fluentui/digest'
6
7
8
+ type ExtendedCookResult = CookResult & {
9
+ extended : {
10
+ kind : string
11
+ story : string
12
+ iterations : number
13
+ tpi ?: number
14
+ fabricTpi ?: number
15
+ filename ?: number
16
+ }
17
+ }
18
+ type ExtendedCookResults = Record < string , ExtendedCookResult >
19
+
7
20
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
8
21
// TODO:
9
22
//
@@ -84,13 +97,18 @@ export default async function getPerfRegressions() {
84
97
const scenarioConfig : ScenarioConfig = { outDir, tempDir }
85
98
const scenarioResults = await flamegrill . cook ( scenarios , scenarioConfig )
86
99
87
- const comment = createReport ( stories , scenarioResults )
100
+ const extendedCookResults = extendCookResults ( stories , scenarioResults )
101
+ fs . writeFileSync (
102
+ path . join ( outDir , 'perfCounts.json' ) ,
103
+ JSON . stringify ( extendedCookResults , null , 2 ) ,
104
+ )
105
+
106
+ const comment = createReport ( stories , extendedCookResults )
88
107
89
108
// TODO: determine status according to perf numbers
90
109
const status = 'success'
91
110
92
111
console . log ( `Perf evaluation status: ${ status } ` )
93
- console . log ( `Writing comment to file:\n${ comment } ` )
94
112
95
113
// Write results to file
96
114
fs . writeFileSync ( path . join ( outDir , 'perfCounts.html' ) , comment )
@@ -101,13 +119,35 @@ export default async function getPerfRegressions() {
101
119
console . log ( `##vso[task.setvariable variable=PerfCommentStatus;]${ status } ` )
102
120
}
103
121
122
+ function extendCookResults ( stories , testResults : CookResults ) : ExtendedCookResults {
123
+ return _ . mapValues ( testResults , ( testResult , resultKey ) => {
124
+ const kind = getKindKey ( resultKey )
125
+ const story = getStoryKey ( resultKey )
126
+ const iterations = getIterations ( stories , kind , story )
127
+ const tpi = getTpiResult ( testResults , stories , kind , story ) // || 'n/a'
128
+ const fabricTpi = getTpiResult ( testResults , stories , kind , 'Fabric' ) // || ''
129
+
130
+ return {
131
+ ...testResult ,
132
+ extended : {
133
+ kind,
134
+ story,
135
+ iterations,
136
+ tpi,
137
+ fabricTpi,
138
+ filename : stories [ kind ] [ story ] . filename ,
139
+ } ,
140
+ }
141
+ } )
142
+ }
143
+
104
144
/**
105
145
* Create test summary based on test results.
106
146
*
107
147
* @param {CookResults } testResults
108
148
* @returns {string }
109
149
*/
110
- function createReport ( stories , testResults : CookResults ) : string {
150
+ function createReport ( stories , testResults : ExtendedCookResults ) : string {
111
151
const report = ''
112
152
113
153
// TODO: We can't do CI, measure baseline or do regression analysis until master & PR files are deployed and publicly accessible.
@@ -131,7 +171,7 @@ function createReport(stories, testResults: CookResults): string {
131
171
* @param {boolean } showAll Show only significant results by default.
132
172
* @returns {string }
133
173
*/
134
- function createScenarioTable ( stories , testResults : CookResults , showAll : boolean ) : string {
174
+ function createScenarioTable ( stories , testResults : ExtendedCookResults , showAll : boolean ) : string {
135
175
const resultsToDisplay = Object . keys ( testResults )
136
176
. filter (
137
177
key =>
@@ -191,18 +231,27 @@ function createScenarioTable(stories, testResults: CookResults, showAll: boolean
191
231
resultsToDisplay
192
232
. map ( resultKey => {
193
233
const testResult = testResults [ resultKey ]
194
- const kind = getKindKey ( resultKey )
195
- const story = getStoryKey ( resultKey )
196
- const iterations = getIterations ( stories , kind , story )
197
- const tpi = getTpiResult ( testResults , stories , kind , story ) || 'n/a'
198
- const fabricTpi = getTpiResult ( testResults , stories , kind , 'Fabric' ) || ''
234
+ const tpi = testResult . extended . tpi
235
+ ? linkifyResult (
236
+ testResult ,
237
+ testResult . extended . tpi . toLocaleString ( 'en' , { maximumSignificantDigits : 2 } ) ,
238
+ false ,
239
+ )
240
+ : 'n/a'
241
+ const fabricTpi = testResult . extended . fabricTpi
242
+ ? linkifyResult (
243
+ testResult ,
244
+ testResult . extended . fabricTpi . toLocaleString ( 'en' , { maximumSignificantDigits : 2 } ) ,
245
+ false ,
246
+ )
247
+ : ''
199
248
200
249
return `<tr>
201
- <td>${ kind } </td>
202
- <td>${ story } </td>
250
+ <td>${ testResult . extended . kind } </td>
251
+ <td>${ testResult . extended . story } </td>
203
252
<td>${ fabricTpi } </td>
204
253
<td>${ tpi } </td>
205
- <td>${ iterations } </td>
254
+ <td>${ testResult . extended . iterations } </td>
206
255
<td>${ getTicksResult ( testResult , false ) } </td>
207
256
</tr>`
208
257
} )
@@ -223,23 +272,19 @@ function getStoryKey(resultKey: string): string {
223
272
return story
224
273
}
225
274
226
- function getTpiResult ( testResults , stories , kind , story ) : string | undefined {
275
+ function getTpiResult ( testResults , stories , kind , story ) : number | undefined {
227
276
let tpi = undefined
228
277
if ( stories [ kind ] [ story ] ) {
229
278
const resultKey = `${ kind } .${ story } `
230
279
const testResult = testResults [ resultKey ]
231
280
const ticks = getTicks ( testResult )
232
281
const iterations = getIterations ( stories , kind , story )
233
- tpi =
234
- ticks &&
235
- iterations &&
236
- ( ticks / iterations ) . toLocaleString ( 'en' , { maximumSignificantDigits : 2 } )
237
- tpi = linkifyResult ( testResult , tpi , false )
282
+ tpi = ticks && iterations && Math . round ( ( ticks / iterations ) * 100 ) / 100
238
283
}
239
284
return tpi
240
285
}
241
286
242
- function getIterations ( stories , kind , story ) {
287
+ function getIterations ( stories , kind , story ) : number {
243
288
// Give highest priority to most localized definition of iterations. Story => kind => default.
244
289
return (
245
290
stories [ kind ] [ story ] . iterations ||
0 commit comments