Force console output when explicitly requested from dev tools

Related feedback:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1617666#c0

Not being able to see benchmark results when explicitly
requesting benchmark results is not very user-friendly;
this commit fixes this.
This commit is contained in:
Raymond Hill 2020-02-25 11:00:58 -05:00
parent 953e0c3197
commit da71c3a499
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
2 changed files with 17 additions and 14 deletions

View File

@ -30,5 +30,6 @@ self.log = (function() {
this.info = console.info = level === 'info' ? info : noopFunc; this.info = console.info = level === 'info' ? info : noopFunc;
}, },
info: noopFunc, info: noopFunc,
print: info,
}; };
})(); })();

View File

@ -3451,7 +3451,9 @@ FilterContainer.prototype.benchmark = async function(action, target) {
return; return;
} }
console.info(`Benchmarking staticNetFilteringEngine.matchString()...`); const print = log.print;
print(`Benchmarking staticNetFilteringEngine.matchString()...`);
const fctxt = µb.filteringContext.duplicate(); const fctxt = µb.filteringContext.duplicate();
if ( typeof target === 'number' ) { if ( typeof target === 'number' ) {
@ -3460,10 +3462,10 @@ FilterContainer.prototype.benchmark = async function(action, target) {
fctxt.setDocOriginFromURL(request.frameUrl); fctxt.setDocOriginFromURL(request.frameUrl);
fctxt.setType(request.cpt); fctxt.setType(request.cpt);
const r = this.matchString(fctxt); const r = this.matchString(fctxt);
console.log(`Result=${r}:`); print(`Result=${r}:`);
console.log(`\ttype=${fctxt.type}`); print(`\ttype=${fctxt.type}`);
console.log(`\turl=${fctxt.url}`); print(`\turl=${fctxt.url}`);
console.log(`\tdocOrigin=${fctxt.getDocOrigin()}`); print(`\tdocOrigin=${fctxt.getDocOrigin()}`);
if ( r !== 0 ) { if ( r !== 0 ) {
console.log(this.toLogData()); console.log(this.toLogData());
} }
@ -3492,21 +3494,21 @@ FilterContainer.prototype.benchmark = async function(action, target) {
const r = this.matchString(fctxt); const r = this.matchString(fctxt);
if ( recorded !== undefined ) { recorded.push(r); } if ( recorded !== undefined ) { recorded.push(r); }
if ( expected !== undefined && r !== expected[i] ) { if ( expected !== undefined && r !== expected[i] ) {
console.log(`Mismatch with reference results at ${i}:`); print(`Mismatch with reference results at ${i}:`);
console.log(`\tExpected ${expected[i]}, got ${r}:`); print(`\tExpected ${expected[i]}, got ${r}:`);
console.log(`\ttype=${fctxt.type}`); print(`\ttype=${fctxt.type}`);
console.log(`\turl=${fctxt.url}`); print(`\turl=${fctxt.url}`);
console.log(`\tdocOrigin=${fctxt.getDocOrigin()}`); print(`\tdocOrigin=${fctxt.getDocOrigin()}`);
} }
} }
const t1 = self.performance.now(); const t1 = self.performance.now();
const dur = t1 - t0; const dur = t1 - t0;
console.info(`Evaluated ${requests.length} requests in ${dur.toFixed(0)} ms`); print(`Evaluated ${requests.length} requests in ${dur.toFixed(0)} ms`);
console.info(`\tAverage: ${(dur / requests.length).toFixed(3)} ms per request`); print(`\tAverage: ${(dur / requests.length).toFixed(3)} ms per request`);
if ( expected !== undefined ) { if ( expected !== undefined ) {
console.info(`\tBlocked: ${expected.reduce((n,r)=>{return r===1?n+1:n;},0)}`); print(`\tBlocked: ${expected.reduce((n,r)=>{return r===1?n+1:n;},0)}`);
console.info(`\tExcepted: ${expected.reduce((n,r)=>{return r===2?n+1:n;},0)}`); print(`\tExcepted: ${expected.reduce((n,r)=>{return r===2?n+1:n;},0)}`);
} }
if ( recorded !== undefined ) { if ( recorded !== undefined ) {
vAPI.localStorage.setItem( vAPI.localStorage.setItem(