Commit a2c7947c authored by caseq's avatar caseq Committed by Commit bot

DevTools coverage: get script/stylesheet size directly, do not request content

This utilizes length of scripts and stylesheets recently exposed in the protocolto avoid requesting content in CoverageModel.

Review-Url: https://codereview.chromium.org/2735133004
Cr-Commit-Position: refs/heads/master@{#455761}
parent 3c1769f9
...@@ -592,7 +592,7 @@ InspectorTest.createScriptMock = function(url, startLine, startColumn, isContent ...@@ -592,7 +592,7 @@ InspectorTest.createScriptMock = function(url, startLine, startColumn, isContent
var endLine = startLine + lineCount - 1; var endLine = startLine + lineCount - 1;
var endColumn = lineCount === 1 ? startColumn + source.length : source.length - source.computeLineEndings()[lineCount - 2]; var endColumn = lineCount === 1 ? startColumn + source.length : source.length - source.computeLineEndings()[lineCount - 2];
var hasSourceURL = !!source.match(/\/\/#\ssourceURL=\s*(\S*?)\s*$/m) || !!source.match(/\/\/@\ssourceURL=\s*(\S*?)\s*$/m); var hasSourceURL = !!source.match(/\/\/#\ssourceURL=\s*(\S*?)\s*$/m) || !!source.match(/\/\/@\ssourceURL=\s*(\S*?)\s*$/m);
var script = new SDK.Script(debuggerModel, scriptId, url, startLine, startColumn, endLine, endColumn, 0, "", isContentScript, false, undefined, hasSourceURL); var script = new SDK.Script(debuggerModel, scriptId, url, startLine, startColumn, endLine, endColumn, 0, "", isContentScript, false, undefined, hasSourceURL, source.length);
script.requestContent = function() script.requestContent = function()
{ {
var trimmedSource = SDK.Script._trimSourceURLComment(source); var trimmedSource = SDK.Script._trimSourceURLComment(source);
......
...@@ -7,9 +7,9 @@ Coverage.RangeUseCount; ...@@ -7,9 +7,9 @@ Coverage.RangeUseCount;
/** @typedef {{ /** @typedef {{
* contentProvider: !Common.ContentProvider, * contentProvider: !Common.ContentProvider,
* size: (number|undefined), * size: number,
* unusedSize: (number|undefined), * unusedSize: number,
* usedSize: (number|undefined), * usedSize: number,
* type: !Coverage.CoverageType, * type: !Coverage.CoverageType,
* lineOffset: number, * lineOffset: number,
* columnOffset: number, * columnOffset: number,
...@@ -99,10 +99,10 @@ Coverage.CoverageModel = class extends SDK.SDKModel { ...@@ -99,10 +99,10 @@ Coverage.CoverageModel = class extends SDK.SDKModel {
/** /**
* @param {!SDK.DebuggerModel} debuggerModel * @param {!SDK.DebuggerModel} debuggerModel
* @param {!Array<!Protocol.Profiler.ScriptCoverage>} scriptsCoverage * @param {!Array<!Protocol.Profiler.ScriptCoverage>} scriptsCoverage
* @return {!Promise<!Array<!Coverage.CoverageInfo>>} * @return {!Array<!Coverage.CoverageInfo>}
*/ */
static async _processJSCoverage(debuggerModel, scriptsCoverage) { static _processJSCoverage(debuggerModel, scriptsCoverage) {
var promises = []; var result = [];
for (var entry of scriptsCoverage) { for (var entry of scriptsCoverage) {
var script = debuggerModel.scriptForId(entry.scriptId); var script = debuggerModel.scriptForId(entry.scriptId);
if (!script) if (!script)
...@@ -112,10 +112,10 @@ Coverage.CoverageModel = class extends SDK.SDKModel { ...@@ -112,10 +112,10 @@ Coverage.CoverageModel = class extends SDK.SDKModel {
for (var range of func.ranges) for (var range of func.ranges)
ranges.push({startOffset: range.startOffset, endOffset: range.endOffset, count: range.count}); ranges.push({startOffset: range.startOffset, endOffset: range.endOffset, count: range.count});
} }
promises.push( result.push(Coverage.CoverageModel._buildCoverageInfo(
Coverage.CoverageModel._coverageInfoForText(script, script.lineOffset, script.columnOffset, ranges)); script, script.contentLength, script.lineOffset, script.columnOffset, ranges));
} }
return Promise.all(promises); return result;
} }
/** /**
...@@ -133,9 +133,9 @@ Coverage.CoverageModel = class extends SDK.SDKModel { ...@@ -133,9 +133,9 @@ Coverage.CoverageModel = class extends SDK.SDKModel {
/** /**
* @param {!SDK.CSSModel} cssModel * @param {!SDK.CSSModel} cssModel
* @param {!Array<!Protocol.CSS.RuleUsage>} ruleUsageList * @param {!Array<!Protocol.CSS.RuleUsage>} ruleUsageList
* @return {!Promise<!Array<!Coverage.CoverageInfo>>} * @return {!Array<!Coverage.CoverageInfo>}
*/ */
static async _processCSSCoverage(cssModel, ruleUsageList) { static _processCSSCoverage(cssModel, ruleUsageList) {
/** @type {!Map<?SDK.CSSStyleSheetHeader, !Array<!Coverage.RangeUseCount>>} */ /** @type {!Map<?SDK.CSSStyleSheetHeader, !Array<!Coverage.RangeUseCount>>} */
var rulesByStyleSheet = new Map(); var rulesByStyleSheet = new Map();
for (var rule of ruleUsageList) { for (var rule of ruleUsageList) {
...@@ -147,20 +147,22 @@ Coverage.CoverageModel = class extends SDK.SDKModel { ...@@ -147,20 +147,22 @@ Coverage.CoverageModel = class extends SDK.SDKModel {
} }
ranges.push({startOffset: rule.startOffset, endOffset: rule.endOffset, count: Number(rule.used)}); ranges.push({startOffset: rule.startOffset, endOffset: rule.endOffset, count: Number(rule.used)});
} }
return Promise.all(Array.from( return Array.from(
rulesByStyleSheet.entries(), rulesByStyleSheet.entries(),
entry => entry => Coverage.CoverageModel._buildCoverageInfo(
Coverage.CoverageModel._coverageInfoForText(entry[0], entry[0].startLine, entry[0].startColumn, entry[1]))); entry[0], entry[0].contentLength, entry[0].startLine, entry[0].startColumn, entry[1]));
} }
/** /**
* @param {!Common.ContentProvider} contentProvider * @param {!Common.ContentProvider} contentProvider
* @param {number} contentLength
* @param {number} startLine * @param {number} startLine
* @param {number} startColumn * @param {number} startColumn
* @param {!Array<!Coverage.RangeUseCount>} ranges * @param {!Array<!Coverage.RangeUseCount>} ranges
* @return {!Promise<?Coverage.CoverageInfo>} * @return {!Coverage.CoverageInfo}
*/ */
static async _coverageInfoForText(contentProvider, startLine, startColumn, ranges) { static _buildCoverageInfo(contentProvider, contentLength, startLine, startColumn, ranges) {
/** @type Coverage.CoverageType */
var coverageType; var coverageType;
var url = contentProvider.contentURL(); var url = contentProvider.contentURL();
if (contentProvider.contentType().isScript()) if (contentProvider.contentType().isScript())
...@@ -197,16 +199,11 @@ Coverage.CoverageModel = class extends SDK.SDKModel { ...@@ -197,16 +199,11 @@ Coverage.CoverageModel = class extends SDK.SDKModel {
unusedSize += entry.ownSize; unusedSize += entry.ownSize;
} }
// FIXME: get rid of this when we get the size upfront.
var content = await contentProvider.requestContent();
if (typeof content !== 'string')
return null;
var coverageInfo = { var coverageInfo = {
contentProvider: contentProvider, contentProvider: contentProvider,
ranges: ranges, ranges: ranges,
type: coverageType, type: coverageType,
size: content.length, size: contentLength,
usedSize: usedSize, usedSize: usedSize,
unusedSize: unusedSize, unusedSize: unusedSize,
lineOffset: startLine, lineOffset: startLine,
......
...@@ -22,6 +22,7 @@ SDK.CSSStyleSheetHeader = class { ...@@ -22,6 +22,7 @@ SDK.CSSStyleSheetHeader = class {
this.isInline = payload.isInline; this.isInline = payload.isInline;
this.startLine = payload.startLine; this.startLine = payload.startLine;
this.startColumn = payload.startColumn; this.startColumn = payload.startColumn;
this.contentLength = payload.length;
if (payload.ownerNode) if (payload.ownerNode)
this.ownerNode = new SDK.DeferredDOMNode(cssModel.target(), payload.ownerNode); this.ownerNode = new SDK.DeferredDOMNode(cssModel.target(), payload.ownerNode);
this.setSourceMapURL(payload.sourceMapURL); this.setSourceMapURL(payload.sourceMapURL);
......
...@@ -458,25 +458,15 @@ SDK.DebuggerModel = class extends SDK.SDKModel { ...@@ -458,25 +458,15 @@ SDK.DebuggerModel = class extends SDK.SDKModel {
* @param {string} hash * @param {string} hash
* @param {*|undefined} executionContextAuxData * @param {*|undefined} executionContextAuxData
* @param {boolean} isLiveEdit * @param {boolean} isLiveEdit
* @param {string=} sourceMapURL * @param {string|undefined} sourceMapURL
* @param {boolean=} hasSourceURL * @param {boolean} hasSourceURL
* @param {boolean=} hasSyntaxError * @param {boolean} hasSyntaxError
* @param {number} length
* @return {!SDK.Script} * @return {!SDK.Script}
*/ */
_parsedScriptSource( _parsedScriptSource(
scriptId, scriptId, sourceURL, startLine, startColumn, endLine, endColumn, executionContextId, hash,
sourceURL, executionContextAuxData, isLiveEdit, sourceMapURL, hasSourceURL, hasSyntaxError, length) {
startLine,
startColumn,
endLine,
endColumn,
executionContextId,
hash,
executionContextAuxData,
isLiveEdit,
sourceMapURL,
hasSourceURL,
hasSyntaxError) {
var isContentScript = false; var isContentScript = false;
if (executionContextAuxData && ('isDefault' in executionContextAuxData)) if (executionContextAuxData && ('isDefault' in executionContextAuxData))
isContentScript = !executionContextAuxData['isDefault']; isContentScript = !executionContextAuxData['isDefault'];
...@@ -491,7 +481,7 @@ SDK.DebuggerModel = class extends SDK.SDKModel { ...@@ -491,7 +481,7 @@ SDK.DebuggerModel = class extends SDK.SDKModel {
} }
var script = new SDK.Script( var script = new SDK.Script(
this, scriptId, sourceURL, startLine, startColumn, endLine, endColumn, executionContextId, this, scriptId, sourceURL, startLine, startColumn, endLine, endColumn, executionContextId,
this._internString(hash), isContentScript, isLiveEdit, sourceMapURL, hasSourceURL); this._internString(hash), isContentScript, isLiveEdit, sourceMapURL, hasSourceURL, length);
this._registerScript(script); this._registerScript(script);
if (!hasSyntaxError) if (!hasSyntaxError)
this.dispatchEventToListeners(SDK.DebuggerModel.Events.ParsedScriptSource, script); this.dispatchEventToListeners(SDK.DebuggerModel.Events.ParsedScriptSource, script);
...@@ -933,23 +923,15 @@ SDK.DebuggerDispatcher = class { ...@@ -933,23 +923,15 @@ SDK.DebuggerDispatcher = class {
* @param {boolean=} isLiveEdit * @param {boolean=} isLiveEdit
* @param {string=} sourceMapURL * @param {string=} sourceMapURL
* @param {boolean=} hasSourceURL * @param {boolean=} hasSourceURL
* @param {boolean=} isModule
* @param {number=} length
*/ */
scriptParsed( scriptParsed(
scriptId, scriptId, sourceURL, startLine, startColumn, endLine, endColumn, executionContextId, hash,
sourceURL, executionContextAuxData, isLiveEdit, sourceMapURL, hasSourceURL, isModule, length) {
startLine,
startColumn,
endLine,
endColumn,
executionContextId,
hash,
executionContextAuxData,
isLiveEdit,
sourceMapURL,
hasSourceURL) {
this._debuggerModel._parsedScriptSource( this._debuggerModel._parsedScriptSource(
scriptId, sourceURL, startLine, startColumn, endLine, endColumn, executionContextId, hash, scriptId, sourceURL, startLine, startColumn, endLine, endColumn, executionContextId, hash,
executionContextAuxData, !!isLiveEdit, sourceMapURL, hasSourceURL, false); executionContextAuxData, !!isLiveEdit, sourceMapURL, !!hasSourceURL, false, length || 0);
} }
/** /**
...@@ -965,22 +947,15 @@ SDK.DebuggerDispatcher = class { ...@@ -965,22 +947,15 @@ SDK.DebuggerDispatcher = class {
* @param {*=} executionContextAuxData * @param {*=} executionContextAuxData
* @param {string=} sourceMapURL * @param {string=} sourceMapURL
* @param {boolean=} hasSourceURL * @param {boolean=} hasSourceURL
* @param {boolean=} isModule
* @param {number=} length
*/ */
scriptFailedToParse( scriptFailedToParse(
scriptId, scriptId, sourceURL, startLine, startColumn, endLine, endColumn, executionContextId, hash,
sourceURL, executionContextAuxData, sourceMapURL, hasSourceURL, isModule, length) {
startLine,
startColumn,
endLine,
endColumn,
executionContextId,
hash,
executionContextAuxData,
sourceMapURL,
hasSourceURL) {
this._debuggerModel._parsedScriptSource( this._debuggerModel._parsedScriptSource(
scriptId, sourceURL, startLine, startColumn, endLine, endColumn, executionContextId, hash, scriptId, sourceURL, startLine, startColumn, endLine, endColumn, executionContextId, hash,
executionContextAuxData, false, sourceMapURL, hasSourceURL, true); executionContextAuxData, false, sourceMapURL, !!hasSourceURL, true, length || 0);
} }
/** /**
......
...@@ -40,23 +40,13 @@ SDK.Script = class { ...@@ -40,23 +40,13 @@ SDK.Script = class {
* @param {string} hash * @param {string} hash
* @param {boolean} isContentScript * @param {boolean} isContentScript
* @param {boolean} isLiveEdit * @param {boolean} isLiveEdit
* @param {string=} sourceMapURL * @param {string|undefined} sourceMapURL
* @param {boolean=} hasSourceURL * @param {boolean} hasSourceURL
* @param {number} length
*/ */
constructor( constructor(
debuggerModel, debuggerModel, scriptId, sourceURL, startLine, startColumn, endLine, endColumn, executionContextId, hash,
scriptId, isContentScript, isLiveEdit, sourceMapURL, hasSourceURL, length) {
sourceURL,
startLine,
startColumn,
endLine,
endColumn,
executionContextId,
hash,
isContentScript,
isLiveEdit,
sourceMapURL,
hasSourceURL) {
this.debuggerModel = debuggerModel; this.debuggerModel = debuggerModel;
this.scriptId = scriptId; this.scriptId = scriptId;
this.sourceURL = sourceURL; this.sourceURL = sourceURL;
...@@ -71,6 +61,7 @@ SDK.Script = class { ...@@ -71,6 +61,7 @@ SDK.Script = class {
this._isLiveEdit = isLiveEdit; this._isLiveEdit = isLiveEdit;
this.sourceMapURL = sourceMapURL; this.sourceMapURL = sourceMapURL;
this.hasSourceURL = hasSourceURL; this.hasSourceURL = hasSourceURL;
this.contentLength = length;
this._originalContentProvider = null; this._originalContentProvider = null;
this._originalSource = null; this._originalSource = null;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment