@@ -27,7 +27,7 @@ export function main() {
2727 var commandLog ;
2828 var eventFactory = new TraceEventFactory ( 'timeline' , 'pid0' ) ;
2929
30- function createMetric ( perfLogs , microMetrics = null , perfLogFeatures = null ) {
30+ function createMetric ( perfLogs , microMetrics = null , perfLogFeatures = null , forceGc = null ) {
3131 commandLog = [ ] ;
3232 if ( isBlank ( perfLogFeatures ) ) {
3333 perfLogFeatures = new PerfLogFeatures ( { render : true , gc : true } ) ;
@@ -45,34 +45,48 @@ export function main() {
4545 } ) ,
4646 bind ( WebDriverExtension ) . toValue ( new MockDriverExtension ( perfLogs , commandLog , perfLogFeatures ) )
4747 ] ;
48+ if ( isPresent ( forceGc ) ) {
49+ ListWrapper . push ( bindings , bind ( Options . FORCE_GC ) . toValue ( forceGc ) ) ;
50+ }
4851 return Injector . resolveAndCreate ( bindings ) . get ( PerflogMetric ) ;
4952 }
5053
5154 describe ( 'perflog metric' , ( ) => {
5255
53- it ( 'should describe itself based on the perfLogFeatrues' , ( ) => {
54- expect ( createMetric ( [ [ ] ] , null , new PerfLogFeatures ( ) ) . describe ( ) ) . toEqual ( {
55- 'scriptTime' : 'script execution time in ms, including gc and render' ,
56- 'pureScriptTime' : 'script execution time in ms, without gc nor render'
56+ function sortedKeys ( stringMap ) {
57+ var res = [ ] ;
58+ StringMapWrapper . forEach ( stringMap , ( _ , key ) => {
59+ ListWrapper . push ( res , key ) ;
5760 } ) ;
61+ res . sort ( ) ;
62+ return res ;
63+ }
64+
65+ it ( 'should describe itself based on the perfLogFeatrues' , ( ) => {
66+ expect ( sortedKeys ( createMetric ( [ [ ] ] , null , new PerfLogFeatures ( ) ) . describe ( ) ) ) . toEqual ( [
67+ 'pureScriptTime' , 'scriptTime'
68+ ] ) ;
5869
59- expect ( createMetric ( [ [ ] ] , null , new PerfLogFeatures ( {
70+ expect ( sortedKeys ( createMetric ( [ [ ] ] , null , new PerfLogFeatures ( {
6071 render : true ,
6172 gc : false
62- } ) ) . describe ( ) ) . toEqual ( {
63- 'scriptTime' : 'script execution time in ms, including gc and render' ,
64- 'pureScriptTime' : 'script execution time in ms, without gc nor render' ,
65- 'renderTime' : 'render time in and ouside of script in ms' ,
66- } ) ;
73+ } ) ) . describe ( ) ) ) . toEqual ( [
74+ 'pureScriptTime' , 'renderTime' , 'scriptTime'
75+ ] ) ;
6776
68- expect ( createMetric ( [ [ ] ] ) . describe ( ) ) . toEqual ( {
69- 'scriptTime' : 'script execution time in ms, including gc and render' ,
70- 'pureScriptTime' : 'script execution time in ms, without gc nor render' ,
71- 'renderTime' : 'render time in and ouside of script in ms' ,
72- 'gcTime' : 'gc time in and ouside of script in ms' ,
73- 'gcAmount' : 'gc amount in kbytes' ,
74- 'majorGcTime' : 'time of major gcs in ms'
75- } ) ;
77+ expect ( sortedKeys ( createMetric ( [ [ ] ] ) . describe ( ) ) ) . toEqual ( [
78+ 'gcAmount' , 'gcTime' , 'majorGcTime' ,
79+ 'pureScriptTime' , 'renderTime' , 'scriptTime'
80+ ] ) ;
81+
82+ expect ( sortedKeys ( createMetric ( [ [ ] ] , null , new PerfLogFeatures ( {
83+ render : true ,
84+ gc : true
85+ } ) , true ) . describe ( ) ) ) . toEqual ( [
86+ 'forcedGcAmount' , 'forcedGcTime' ,
87+ 'gcAmount' , 'gcTime' , 'majorGcTime' ,
88+ 'pureScriptTime' , 'renderTime' , 'scriptTime'
89+ ] ) ;
7690 } ) ;
7791
7892 it ( 'should describe itself based on micro metrics' , ( ) => {
@@ -84,7 +98,7 @@ export function main() {
8498
8599 describe ( 'beginMeasure' , ( ) => {
86100
87- it ( 'should mark the timeline' , inject ( [ AsyncTestCompleter ] , ( async ) => {
101+ it ( 'should not force gc and mark the timeline' , inject ( [ AsyncTestCompleter ] , ( async ) => {
88102 var metric = createMetric ( [ [ ] ] ) ;
89103 metric . beginMeasure ( ) . then ( ( _ ) => {
90104 expect ( commandLog ) . toEqual ( [ [ 'timeBegin' , 'benchpress0' ] ] ) ;
@@ -93,6 +107,15 @@ export function main() {
93107 } ) ;
94108 } ) ) ;
95109
110+ it ( 'should force gc and mark the timeline' , inject ( [ AsyncTestCompleter ] , ( async ) => {
111+ var metric = createMetric ( [ [ ] ] , null , null , true ) ;
112+ metric . beginMeasure ( ) . then ( ( _ ) => {
113+ expect ( commandLog ) . toEqual ( [ [ 'gc' ] , [ 'timeBegin' , 'benchpress0' ] ] ) ;
114+
115+ async . done ( ) ;
116+ } ) ;
117+ } ) ) ;
118+
96119 } ) ;
97120
98121 describe ( 'endMeasure' , ( ) => {
@@ -200,6 +223,57 @@ export function main() {
200223 } ) ;
201224 } ) ) ;
202225
226+ describe ( 'with forced gc' , ( ) => {
227+ var events ;
228+ beforeEach ( ( ) => {
229+ events = [
230+ [
231+ eventFactory . markStart ( 'benchpress0' , 0 ) ,
232+ eventFactory . start ( 'script' , 4 ) ,
233+ eventFactory . end ( 'script' , 6 ) ,
234+ eventFactory . markEnd ( 'benchpress0' , 10 ) ,
235+ eventFactory . markStart ( 'benchpress1' , 11 ) ,
236+ eventFactory . start ( 'gc' , 12 , { 'usedHeapSize' : 2500 } ) ,
237+ eventFactory . end ( 'gc' , 15 , { 'usedHeapSize' : 1000 } ) ,
238+ eventFactory . markEnd ( 'benchpress1' , 20 )
239+ ]
240+ ] ;
241+ } ) ;
242+
243+ it ( 'should measure forced gc' , inject ( [ AsyncTestCompleter ] , ( async ) => {
244+ var metric = createMetric ( events , null , null , true ) ;
245+ metric . beginMeasure ( )
246+ . then ( ( _ ) => metric . endMeasure ( false ) )
247+ . then ( ( data ) => {
248+ expect ( commandLog ) . toEqual ( [
249+ [ 'gc' ] ,
250+ [ 'timeBegin' , 'benchpress0' ] ,
251+ [ 'timeEnd' , 'benchpress0' , 'benchpress1' ] ,
252+ 'readPerfLog' ,
253+ [ 'gc' ] ,
254+ [ 'timeEnd' , 'benchpress1' , null ] ,
255+ 'readPerfLog'
256+ ] ) ;
257+ expect ( data [ 'forcedGcTime' ] ) . toBe ( 3 ) ;
258+ expect ( data [ 'forcedGcAmount' ] ) . toBe ( 1.5 ) ;
259+
260+ async . done ( ) ;
261+ } ) ;
262+ } ) ) ;
263+
264+ it ( 'should restart after the forced gc if needed' , inject ( [ AsyncTestCompleter ] , ( async ) => {
265+ var metric = createMetric ( events , null , null , true ) ;
266+ metric . beginMeasure ( )
267+ . then ( ( _ ) => metric . endMeasure ( true ) )
268+ . then ( ( data ) => {
269+ expect ( commandLog [ 5 ] ) . toEqual ( [ 'timeEnd' , 'benchpress1' , 'benchpress2' ] ) ;
270+
271+ async . done ( ) ;
272+ } ) ;
273+ } ) ) ;
274+
275+ } ) ;
276+
203277 } ) ;
204278
205279 describe ( 'aggregation' , ( ) => {
@@ -403,4 +477,9 @@ class MockDriverExtension extends WebDriverExtension {
403477 return PromiseWrapper . resolve ( [ ] ) ;
404478 }
405479 }
480+
481+ gc ( ) :Promise {
482+ ListWrapper . push ( this . _commandLog , [ 'gc' ] ) ;
483+ return PromiseWrapper . resolve ( null ) ;
484+ }
406485}
0 commit comments