2 * Augment mw.loader to facilitate module-level profiling.
10 var moduleTimes
= Object
.create( null );
13 * Private hooks inserted into mw.loader code if MediaWiki configuration
14 * `$wgResourceLoaderEnableJSProfiler` is `true`.
16 * To use this data, run `mw.inspect( 'time' )` from the browser console.
23 mw
.loader
.profiler
= {
24 onExecuteStart: function ( moduleName
) {
25 var time
= performance
.now();
26 if ( moduleTimes
[ moduleName
] ) {
27 throw new Error( 'Unexpected perf record for "' + moduleName
+ '".' );
29 moduleTimes
[ moduleName
] = {
36 onExecuteEnd: function ( moduleName
) {
37 var time
= performance
.now();
38 moduleTimes
[ moduleName
].executeEnd
= time
;
40 onScriptStart: function ( moduleName
) {
41 var time
= performance
.now();
42 moduleTimes
[ moduleName
].scriptStart
= time
;
44 onScriptEnd: function ( moduleName
) {
45 var time
= performance
.now();
46 moduleTimes
[ moduleName
].scriptEnd
= time
;
50 * For internal use by inspect.reports#time.
53 * @param {string} moduleName
54 * @return {Object|null}
55 * @throws {Error} If the perf record is incomplete.
57 getProfile: function ( moduleName
) {
58 var times
, key
, execute
, script
, total
;
59 times
= moduleTimes
[ moduleName
];
63 for ( key
in times
) {
64 if ( times
[ key
] === null ) {
65 throw new Error( 'Incomplete perf record for "' + moduleName
+ '".', times
);
68 execute
= times
.executeEnd
- times
.executeStart
;
69 script
= times
.scriptEnd
- times
.scriptStart
;
70 total
= execute
+ script
;