| 
									
										
										
										
											2016-06-23 09:47:54 -07:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @license | 
					
						
							|  |  |  |  * Copyright Google Inc. All Rights Reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Use of this source code is governed by an MIT-style license that can be | 
					
						
							|  |  |  |  * found in the LICENSE file at https://angular.io/license
 | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2015-06-01 17:33:51 -07:00
										 |  |  | export {verifyNoBrowserErrors} from './e2e_util'; | 
					
						
							| 
									
										
										
										
											2015-05-30 08:17:27 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-30 09:29:39 -07:00
										 |  |  | const yargs = require('yargs'); | 
					
						
							|  |  |  | const nodeUuid = require('node-uuid'); | 
					
						
							|  |  |  | import * as fs from 'fs-extra'; | 
					
						
							| 
									
										
										
										
											2015-05-30 08:17:27 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-30 09:29:39 -07:00
										 |  |  | import {SeleniumWebDriverAdapter, Options, JsonFileReporter, Validator, RegressionSlopeValidator, ConsoleReporter, SizeValidator, MultiReporter, MultiMetric, Runner, Provider} from '@angular/benchpress'; | 
					
						
							|  |  |  | import {readCommandLine as readE2eCommandLine, openBrowser} from './e2e_util'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | let cmdArgs: {'sample-size': number, 'force-gc': boolean, 'dryrun': boolean, 'bundles': boolean}; | 
					
						
							|  |  |  | let runner: Runner; | 
					
						
							| 
									
										
										
										
											2015-05-30 08:17:27 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-30 09:29:39 -07:00
										 |  |  | export function readCommandLine() { | 
					
						
							|  |  |  |   cmdArgs = <any>readE2eCommandLine({ | 
					
						
							|  |  |  |     'sample-size': {describe: 'Used for perf: sample size.', default: 20}, | 
					
						
							|  |  |  |     'force-gc': {describe: 'Used for perf: force gc.', default: false, type: 'boolean'}, | 
					
						
							|  |  |  |     'dryrun': {describe: 'If true, only run performance benchmarks once.', default: false}, | 
					
						
							|  |  |  |     'bundles': {describe: 'Whether to use the angular bundles or not.', default: false} | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |   }); | 
					
						
							| 
									
										
										
										
											2016-08-30 09:29:39 -07:00
										 |  |  |   runner = createBenchpressRunner(); | 
					
						
							| 
									
										
										
										
											2015-05-30 08:17:27 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-30 09:29:39 -07:00
										 |  |  | export function runBenchmark(config: { | 
					
						
							|  |  |  |   id: string, | 
					
						
							|  |  |  |   url: string, | 
					
						
							|  |  |  |   params: {name: string, value: any}[], | 
					
						
							|  |  |  |   ignoreBrowserSynchronization?: boolean, | 
					
						
							|  |  |  |   microMetrics?: {[key: string]: string}, | 
					
						
							|  |  |  |   work?: () => void, | 
					
						
							|  |  |  |   prepare?: () => void, | 
					
						
							| 
									
										
										
										
											2016-12-28 15:26:49 -08:00
										 |  |  |   setup?: () => void | 
					
						
							| 
									
										
										
										
											2016-08-30 09:29:39 -07:00
										 |  |  | }): Promise<any> { | 
					
						
							|  |  |  |   openBrowser(config); | 
					
						
							| 
									
										
										
										
											2016-12-28 15:26:49 -08:00
										 |  |  |   if (config.setup) { | 
					
						
							|  |  |  |     config.setup(); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2016-11-12 14:08:58 +01:00
										 |  |  |   const description: {[key: string]: any} = {'bundles': cmdArgs.bundles}; | 
					
						
							| 
									
										
										
										
											2016-08-30 09:29:39 -07:00
										 |  |  |   config.params.forEach((param) => { description[param.name] = param.value; }); | 
					
						
							|  |  |  |   return runner.sample({ | 
					
						
							|  |  |  |     id: config.id, | 
					
						
							|  |  |  |     execute: config.work, | 
					
						
							|  |  |  |     prepare: config.prepare, | 
					
						
							|  |  |  |     microMetrics: config.microMetrics, | 
					
						
							|  |  |  |     providers: [{provide: Options.SAMPLE_DESCRIPTION, useValue: description}] | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |   }); | 
					
						
							| 
									
										
										
										
											2015-05-30 08:17:27 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-30 09:29:39 -07:00
										 |  |  | function createBenchpressRunner(): Runner { | 
					
						
							|  |  |  |   let runId = nodeUuid.v1(); | 
					
						
							|  |  |  |   if (process.env.GIT_SHA) { | 
					
						
							|  |  |  |     runId = process.env.GIT_SHA + ' ' + runId; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   const resultsFolder = './dist/benchmark_results'; | 
					
						
							|  |  |  |   fs.ensureDirSync(resultsFolder); | 
					
						
							| 
									
										
										
										
											2016-11-12 14:08:58 +01:00
										 |  |  |   const providers: Provider[] = [ | 
					
						
							| 
									
										
										
										
											2016-08-30 09:29:39 -07:00
										 |  |  |     SeleniumWebDriverAdapter.PROTRACTOR_PROVIDERS, | 
					
						
							|  |  |  |     {provide: Options.FORCE_GC, useValue: cmdArgs['force-gc']}, | 
					
						
							|  |  |  |     {provide: Options.DEFAULT_DESCRIPTION, useValue: {'runId': runId}}, JsonFileReporter.PROVIDERS, | 
					
						
							|  |  |  |     {provide: JsonFileReporter.PATH, useValue: resultsFolder} | 
					
						
							|  |  |  |   ]; | 
					
						
							|  |  |  |   if (!cmdArgs['dryrun']) { | 
					
						
							|  |  |  |     providers.push({provide: Validator, useExisting: RegressionSlopeValidator}); | 
					
						
							|  |  |  |     providers.push( | 
					
						
							|  |  |  |         {provide: RegressionSlopeValidator.SAMPLE_SIZE, useValue: cmdArgs['sample-size']}); | 
					
						
							|  |  |  |     providers.push(MultiReporter.provideWith([ConsoleReporter, JsonFileReporter])); | 
					
						
							| 
									
										
										
										
											2015-05-30 08:17:27 -07:00
										 |  |  |   } else { | 
					
						
							| 
									
										
										
										
											2016-08-30 09:29:39 -07:00
										 |  |  |     providers.push({provide: Validator, useExisting: SizeValidator}); | 
					
						
							|  |  |  |     providers.push({provide: SizeValidator.SAMPLE_SIZE, useValue: 1}); | 
					
						
							|  |  |  |     providers.push(MultiReporter.provideWith([])); | 
					
						
							|  |  |  |     providers.push(MultiMetric.provideWith([])); | 
					
						
							| 
									
										
										
										
											2015-05-30 08:17:27 -07:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2016-08-30 09:29:39 -07:00
										 |  |  |   return new Runner(providers); | 
					
						
							| 
									
										
										
										
											2015-05-30 08:17:27 -07:00
										 |  |  | } |