@@ -114,22 +114,25 @@ class BootupTime extends Audit {
114114 */
115115 static getExecutionTimingsByURL ( trace ) {
116116 const timelineModel = new DevtoolsTimelineModel ( trace ) ;
117- const bottomUpByName = timelineModel . bottomUpGroupBy ( 'URL' ) ;
117+ const bottomUpByURL = timelineModel . bottomUpGroupBy ( 'URL' ) ;
118118 const result = new Map ( ) ;
119119
120- bottomUpByName . children . forEach ( ( perUrlNode , url ) => {
120+ bottomUpByURL . children . forEach ( ( perUrlNode , url ) => {
121121 // when url is "" or about:blank, we skip it
122122 if ( ! url || url === 'about:blank' ) {
123123 return ;
124124 }
125125
126- const tasks = { } ;
126+ const taskGroups = { } ;
127127 perUrlNode . children . forEach ( ( perTaskPerUrlNode ) => {
128- const taskGroup = WebInspector . TimelineUIUtils . eventStyle ( perTaskPerUrlNode . event ) ;
129- tasks [ taskGroup . title ] = tasks [ taskGroup . title ] || 0 ;
130- tasks [ taskGroup . title ] += Number ( ( perTaskPerUrlNode . selfTime || 0 ) . toFixed ( 1 ) ) ;
128+ // eventStyle() returns a string like 'Evaluate Script'
129+ const task = WebInspector . TimelineUIUtils . eventStyle ( perTaskPerUrlNode . event ) ;
130+ // Resolve which taskGroup we're using
131+ const groupName = taskToGroup [ task . title ] || group . other ;
132+ const groupTotal = taskGroups [ groupName ] || 0 ;
133+ taskGroups [ groupName ] = groupTotal + ( perTaskPerUrlNode . selfTime || 0 ) ;
131134 } ) ;
132- result . set ( url , tasks ) ;
135+ result . set ( url , taskGroups ) ;
133136 } ) ;
134137
135138 return result ;
@@ -141,50 +144,34 @@ class BootupTime extends Audit {
141144 */
142145 static audit ( artifacts ) {
143146 const trace = artifacts . traces [ BootupTime . DEFAULT_PASS ] ;
144- const bootupTimings = BootupTime . getExecutionTimingsByURL ( trace ) ;
147+ const executionTimings = BootupTime . getExecutionTimingsByURL ( trace ) ;
145148
146149 let totalBootupTime = 0 ;
147150 const extendedInfo = { } ;
151+
148152 const headings = [
149153 { key : 'url' , itemType : 'url' , text : 'URL' } ,
154+ { key : 'scripting' , itemType : 'text' , text : group . scripting } ,
155+ { key : 'scriptParseCompile' , itemType : 'text' , text : group . scriptParseCompile } ,
150156 ] ;
151157
152- // Group tasks per url
153- const groupsPerUrl = Array . from ( bootupTimings ) . map ( ( [ url , durations ] ) => {
154- extendedInfo [ url ] = durations ;
155-
156- const groups = [ ] ;
157- Object . keys ( durations ) . forEach ( task => {
158- totalBootupTime += durations [ task ] ;
159- const group = taskToGroup [ task ] ;
160-
161- groups [ group ] = groups [ group ] || 0 ;
162- groups [ group ] += durations [ task ] ;
163-
164- if ( ! headings . find ( heading => heading . key === group ) ) {
165- headings . push (
166- { key : group , itemType : 'text' , text : group }
167- ) ;
168- }
169- } ) ;
158+ // map data in correct format to create a table
159+ const results = Array . from ( executionTimings ) . map ( ( [ url , groups ] ) => {
160+ // Add up the totalBootupTime for all the taskGroups
161+ totalBootupTime += Object . keys ( groups ) . reduce ( ( sum , name ) => sum += groups [ name ] , 0 ) ;
162+ extendedInfo [ url ] = groups ;
170163
164+ const scriptingTotal = groups [ group . scripting ] || 0 ;
165+ const parseCompileTotal = groups [ group . scriptParseCompile ] || 0 ;
171166 return {
172167 url : url ,
173- groups,
168+ sum : scriptingTotal + parseCompileTotal ,
169+ // Only reveal the javascript task costs
170+ // Later we can account for forced layout costs, etc.
171+ scripting : Util . formatMilliseconds ( scriptingTotal , 1 ) ,
172+ scriptParseCompile : Util . formatMilliseconds ( parseCompileTotal , 1 ) ,
174173 } ;
175- } ) ;
176-
177- // map data in correct format to create a table
178- const results = groupsPerUrl . map ( ( { url, groups} ) => {
179- const res = { } ;
180- headings . forEach ( heading => {
181- res [ heading . key ] = Util . formatMilliseconds ( groups [ heading . key ] || 0 , 1 ) ;
182- } ) ;
183-
184- res . url = url ;
185-
186- return res ;
187- } ) ;
174+ } ) . sort ( ( a , b ) => b . sum - a . sum ) ;
188175
189176 const tableDetails = BootupTime . makeTableDetails ( headings , results ) ;
190177
0 commit comments