@@ -5,6 +5,7 @@ import { bind, OpaqueToken } from 'angular2/di';
55
66import { WebDriverExtension } from '../web_driver_extension' ;
77import { Metric } from '../metric' ;
8+ import { Options } from '../sample_options' ;
89
910/**
1011 * A metric that reads out the performance log
@@ -19,24 +20,36 @@ export class PerflogMetric extends Metric {
1920 _remainingEvents :List ;
2021 _measureCount :int ;
2122 _setTimeout :Function ;
23+ _microIterations :int ;
2224
23- constructor ( driverExtension :WebDriverExtension , setTimeout :Function ) {
25+ /**
26+ * @param driverExtension
27+ * @param setTimeout
28+ * @param microIterations Number of iterations that run inside the browser by user code.
29+ * Used for micro benchmarks.
30+ **/
31+ constructor ( driverExtension :WebDriverExtension , setTimeout :Function , microIterations :int ) {
2432 super ( ) ;
2533 this . _driverExtension = driverExtension ;
2634 this . _remainingEvents = [ ] ;
2735 this . _measureCount = 0 ;
2836 this . _setTimeout = setTimeout ;
37+ this . _microIterations = microIterations ;
2938 }
3039
3140 describe ( ) :StringMap {
32- return {
41+ var res = {
3342 'script' : 'script execution time in ms' ,
3443 'render' : 'render time in ms' ,
3544 'gcTime' : 'gc time in ms' ,
3645 'gcAmount' : 'gc amount in kbytes' ,
3746 'gcTimeInScript' : 'gc time during script execution in ms' ,
3847 'gcAmountInScript' : 'gc amount during script execution in kbytes'
3948 } ;
49+ if ( this . _microIterations > 0 ) {
50+ res [ 'scriptMicroAvg' ] = 'average script time for a micro iteration' ;
51+ }
52+ return res ;
4053 }
4154
4255 beginMeasure ( ) :Promise {
@@ -148,6 +161,9 @@ export class PerflogMetric extends Metric {
148161 }
149162 } ) ;
150163 result [ 'script' ] -= result [ 'gcTimeInScript' ] ;
164+ if ( this . _microIterations > 0 ) {
165+ result [ 'scriptMicroAvg' ] = result [ 'script' ] / this . _microIterations ;
166+ }
151167 return isPresent ( markStartEvent ) && isPresent ( markEndEvent ) ? result : null ;
152168 }
153169
@@ -161,8 +177,9 @@ var _MARK_NAME_PREFIX = 'benchpress';
161177var _SET_TIMEOUT = new OpaqueToken ( 'PerflogMetric.setTimeout' ) ;
162178var _BINDINGS = [
163179 bind ( PerflogMetric ) . toFactory (
164- ( driverExtension , setTimeout ) => new PerflogMetric ( driverExtension , setTimeout ) ,
165- [ WebDriverExtension , _SET_TIMEOUT ]
180+ ( driverExtension , setTimeout , microIterations ) => new PerflogMetric ( driverExtension , setTimeout , microIterations ) ,
181+ [ WebDriverExtension , _SET_TIMEOUT , Options . MICRO_ITERATIONS ]
166182 ) ,
167- bind ( _SET_TIMEOUT ) . toValue ( ( fn , millis ) => PromiseWrapper . setTimeout ( fn , millis ) )
183+ bind ( _SET_TIMEOUT ) . toValue ( ( fn , millis ) => PromiseWrapper . setTimeout ( fn , millis ) ) ,
184+ bind ( Options . MICRO_ITERATIONS ) . toValue ( 0 )
168185] ;
0 commit comments