Skip to content

Commit

Permalink
Use trace buffer instead of tmp file
Browse files Browse the repository at this point in the history
  • Loading branch information
WunderBart committed Jul 27, 2023
1 parent 182fbc1 commit 1cf298a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 68 deletions.
66 changes: 14 additions & 52 deletions test/performance/specs/post-editor.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ const path = require( 'path' );
* Internal dependencies
*/
const {
readFile,
deleteFile,
getTypingEventDurations,
getClickEventDurations,
getHoverEventDurations,
Expand All @@ -22,7 +20,6 @@ const {
loadBlocksFromHtml,
load1000Paragraphs,
sum,
getTraceFilePath,
} = require( '../utils' );

// See https://github.com/WordPress/gutenberg/issues/51383#issuecomment-1613460429
Expand All @@ -45,16 +42,11 @@ const results = {
};

test.describe( 'Post Editor Performance', () => {
const traceFilePath = getTraceFilePath();

test.afterAll( async ( {}, testInfo ) => {
await testInfo.attach( 'results', {
body: JSON.stringify( results, null, 2 ),
contentType: 'application/json',
} );

// Delete the trace file.
deleteFile( traceFilePath );
} );

test.beforeEach( async ( { admin, page } ) => {
Expand Down Expand Up @@ -132,7 +124,6 @@ test.describe( 'Post Editor Performance', () => {

// Start tracing.
await browser.startTracing( page, {
path: traceFilePath,
screenshots: false,
categories: [ 'devtools.timeline' ],
} );
Expand All @@ -150,9 +141,8 @@ test.describe( 'Post Editor Performance', () => {
} );

// Stop tracing and save results.
await browser.stopTracing();

const traceResults = JSON.parse( readFile( traceFilePath ) );
const traceBuffer = await browser.stopTracing();
const traceResults = JSON.parse( traceBuffer.toString() );
const [ keyDownEvents, keyPressEvents, keyUpEvents ] =
getTypingEventDurations( traceResults );

Expand All @@ -161,9 +151,6 @@ test.describe( 'Post Editor Performance', () => {
keyDownEvents[ i ] + keyPressEvents[ i ] + keyUpEvents[ i ]
);
}

// Delete the trace file.
deleteFile( traceFilePath );
} );

test( 'Typing within containers', async ( { browser, page } ) => {
Expand All @@ -183,7 +170,6 @@ test.describe( 'Post Editor Performance', () => {
.click();

await browser.startTracing( page, {
path: traceFilePath,
screenshots: false,
categories: [ 'devtools.timeline' ],
} );
Expand All @@ -198,9 +184,8 @@ test.describe( 'Post Editor Performance', () => {
delay: BROWSER_IDLE_WAIT,
} );

await browser.stopTracing();

const traceResults = JSON.parse( readFile( traceFilePath ) );
const traceBuffer = await browser.stopTracing();
const traceResults = JSON.parse( traceBuffer.toString() );
const [ keyDownEvents, keyPressEvents, keyUpEvents ] =
getTypingEventDurations( traceResults );

Expand All @@ -209,9 +194,6 @@ test.describe( 'Post Editor Performance', () => {
keyDownEvents[ i ] + keyPressEvents[ i ] + keyUpEvents[ i ]
);
}

// Delete the trace file.
deleteFile( traceFilePath );
} );

test( 'Selecting blocks', async ( { browser, page } ) => {
Expand All @@ -228,17 +210,16 @@ test.describe( 'Post Editor Performance', () => {
// eslint-disable-next-line no-restricted-syntax
await page.waitForTimeout( BROWSER_IDLE_WAIT );
await browser.startTracing( page, {
path: traceFilePath,
screenshots: false,
categories: [ 'devtools.timeline' ],
} );

await paragraphs.nth( i ).click();

await browser.stopTracing();
const traceBuffer = await browser.stopTracing();

if ( i >= throwaway ) {
const traceResults = JSON.parse( readFile( traceFilePath ) );
const traceResults = JSON.parse( traceBuffer.toString() );
const allDurations = getSelectionEventDurations( traceResults );
results.focus.push(
allDurations.reduce( ( acc, eventDurations ) => {
Expand All @@ -247,9 +228,6 @@ test.describe( 'Post Editor Performance', () => {
);
}
}

// Delete the trace file.
deleteFile( traceFilePath );
} );

test( 'Opening persistent list view', async ( { browser, page } ) => {
Expand All @@ -266,18 +244,17 @@ test.describe( 'Post Editor Performance', () => {
// eslint-disable-next-line no-restricted-syntax
await page.waitForTimeout( BROWSER_IDLE_WAIT );
await browser.startTracing( page, {
path: traceFilePath,
screenshots: false,
categories: [ 'devtools.timeline' ],
} );

// Open List View
await listViewToggle.click();

await browser.stopTracing();
const traceBuffer = await browser.stopTracing();

if ( i >= throwaway ) {
const traceResults = JSON.parse( readFile( traceFilePath ) );
const traceResults = JSON.parse( traceBuffer.toString() );
const [ mouseClickEvents ] =
getClickEventDurations( traceResults );
results.listViewOpen.push( mouseClickEvents[ 0 ] );
Expand All @@ -286,9 +263,6 @@ test.describe( 'Post Editor Performance', () => {
// Close List View
await listViewToggle.click();
}

// Delete the trace file.
deleteFile( traceFilePath );
} );

test( 'Opening the inserter', async ( { browser, page } ) => {
Expand All @@ -305,18 +279,17 @@ test.describe( 'Post Editor Performance', () => {
// eslint-disable-next-line no-restricted-syntax
await page.waitForTimeout( BROWSER_IDLE_WAIT );
await browser.startTracing( page, {
path: traceFilePath,
screenshots: false,
categories: [ 'devtools.timeline' ],
} );

// Open Inserter.
await globalInserterToggle.click();

await browser.stopTracing();
const traceBuffer = await browser.stopTracing();

if ( i >= throwaway ) {
const traceResults = JSON.parse( readFile( traceFilePath ) );
const traceResults = JSON.parse( traceBuffer.toString() );
const [ mouseClickEvents ] =
getClickEventDurations( traceResults );
results.inserterOpen.push( mouseClickEvents[ 0 ] );
Expand All @@ -325,9 +298,6 @@ test.describe( 'Post Editor Performance', () => {
// Close Inserter.
await globalInserterToggle.click();
}

// Delete the trace file.
deleteFile( traceFilePath );
} );

test( 'Searching the inserter', async ( { browser, page } ) => {
Expand All @@ -347,17 +317,16 @@ test.describe( 'Post Editor Performance', () => {
// eslint-disable-next-line no-restricted-syntax
await page.waitForTimeout( BROWSER_IDLE_WAIT );
await browser.startTracing( page, {
path: traceFilePath,
screenshots: false,
categories: [ 'devtools.timeline' ],
} );

await page.keyboard.type( 'p' );

await browser.stopTracing();
const traceBuffer = await browser.stopTracing();

if ( i >= throwaway ) {
const traceResults = JSON.parse( readFile( traceFilePath ) );
const traceResults = JSON.parse( traceBuffer.toString() );
const [ keyDownEvents, keyPressEvents, keyUpEvents ] =
getTypingEventDurations( traceResults );
results.inserterSearch.push(
Expand All @@ -370,9 +339,6 @@ test.describe( 'Post Editor Performance', () => {

// Close Inserter.
await globalInserterToggle.click();

// Delete the trace file.
deleteFile( traceFilePath );
} );

test( 'Hovering Inserter Items', async ( { browser, page } ) => {
Expand All @@ -398,7 +364,6 @@ test.describe( 'Post Editor Performance', () => {
// eslint-disable-next-line no-restricted-syntax
await page.waitForTimeout( BROWSER_IDLE_WAIT );
await browser.startTracing( page, {
path: traceFilePath,
screenshots: false,
categories: [ 'devtools.timeline' ],
} );
Expand All @@ -407,10 +372,10 @@ test.describe( 'Post Editor Performance', () => {
await paragraphBlockItem.hover();
await headingBlockItem.hover();

await browser.stopTracing();
const traceBuffer = await browser.stopTracing();

if ( i >= throwaway ) {
const traceResults = JSON.parse( readFile( traceFilePath ) );
const traceResults = JSON.parse( traceBuffer.toString() );
const [ mouseOverEvents, mouseOutEvents ] =
getHoverEventDurations( traceResults );
for ( let k = 0; k < mouseOverEvents.length; k++ ) {
Expand All @@ -423,8 +388,5 @@ test.describe( 'Post Editor Performance', () => {

// Close Inserter.
await globalInserterToggle.click();

// Delete the trace file.
deleteFile( traceFilePath );
} );
} );
13 changes: 2 additions & 11 deletions test/performance/specs/site-editor.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ const path = require( 'path' );
* Internal dependencies
*/
const {
readFile,
deleteFile,
getTraceFilePath,
getTypingEventDurations,
getLoadingDurations,
loadBlocksFromHtml,
Expand Down Expand Up @@ -186,9 +183,7 @@ test.describe( 'Site Editor Performance', () => {
await page.keyboard.press( 'Enter' ); // Exits the list and creates a new paragraph.

// Start tracing.
const traceFilePath = getTraceFilePath();
await browser.startTracing( page, {
path: traceFilePath,
screenshots: false,
categories: [ 'devtools.timeline' ],
} );
Expand All @@ -206,18 +201,14 @@ test.describe( 'Site Editor Performance', () => {
} );

// Stop tracing and save results.
await browser.stopTracing();

const traceResults = JSON.parse( readFile( traceFilePath ) );
const traceBuffer = await browser.stopTracing();
const traceResults = JSON.parse( traceBuffer.toString() );
const [ keyDownEvents, keyPressEvents, keyUpEvents ] =
getTypingEventDurations( traceResults );
for ( let i = throwaway; i < rounds; i++ ) {
results.type.push(
keyDownEvents[ i ] + keyPressEvents[ i ] + keyUpEvents[ i ]
);
}

// Delete the trace file.
deleteFile( traceFilePath );
} );
} );
5 changes: 0 additions & 5 deletions test/performance/utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* External dependencies
*/
import path from 'path';
import { existsSync, readFileSync, unlinkSync } from 'fs';

export function sum( array ) {
Expand Down Expand Up @@ -60,10 +59,6 @@ export function deleteFile( filePath ) {
}
}

export function getTraceFilePath() {
return path.join( process.env.WP_ARTIFACTS_PATH, '/trace.json' );
}

function isEvent( item ) {
return (
item.cat === 'devtools.timeline' &&
Expand Down

0 comments on commit 1cf298a

Please sign in to comment.