Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli(asset-saver): print one devtoolsLog event per line #12348

Merged
merged 4 commits into from
Apr 12, 2021

Conversation

brendankenny
Copy link
Member

It's very nice that the trace that comes out of -GA is saved with a trace event per line. Doing some recent work with devtoolsLogs made me really want the same printing style for those.

const writeStream = fs.createWriteStream(traceFilename);
writeStream.on('finish', resolve);
writeStream.on('error', reject);
return pipeline(stream.Readable.from(traceIter), writeStream);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was able to get way nicer than the old version. Node 13+ will let us drop the stream.Readable.from() part (pipeline will take iterables directly) and node 15+ will let us drop the promisify(stream.pipeline) call

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a compat TODO comment for the latter bit?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yah

{"args":{"data":{"encodedDataLength":20,"requestId":"1.22"}},"pid":1,"ts":6}
]}
`);
});
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we didn't have any tests of the printing style, just that all the correct content was being printed in a JSON.parse()able way.

version "10.14.0"
resolved "https://registry.yarnpkg.com/@types/node/-/node-10.14.0.tgz#1c297530428c6f4e0a0a3222f5b44745669aa9f7"
integrity sha512-1UhSMMDix7bVdUeqtZERQQyJr3QuFoN5X5APtpIooGkumE3crPaeq7UgFeJNjGD8yCQ8od8PzRkgptR5+x327Q==
version "12.20.7"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needed up to date (for Node 12) types to be able to use stream.Readable.from().

(@adamraine these outdated node types were also the thing preventing this suggestion from working: #12145 (comment))

@brendankenny
Copy link
Member Author

brendankenny commented Apr 9, 2021

test failure is browserify not supplying util.promisify(), and because asset-saver.js is pulled into the bundle (even though it's not used in bundle code :/) it's causing an error.

It is included in browserify 17 (up from the current 16.2.3`). I'm looking at how easy the update is vs just doing a workaround.

@brendankenny
Copy link
Member Author

It is included in browserify 17 (up from the current 16.2.3`). I'm looking at how easy the update is vs just doing a workaround.

it's not bad at all

Copy link
Member

@paulirish paulirish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

coool. a few nits

const firstElement = elementsIterator.next().value;
yield ` ${JSON.stringify(firstElement)}`;

let elementsRemaining = ELEMENTS_PER_ITERATION;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"element" => "item"? or "value"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


yield '{\n';
function* arrayOfObjectsJsonGenerator(arrayOfObjects) {
const ELEMENTS_PER_ITERATION = 500;

// Stringify and emit trace events separately to avoid a giant string in memory.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update comment

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

* @return {IterableIterator<string>}
*/
function* traceJsonGenerator(traceData) {
const {traceEvents, ...rest} = traceData;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

def nicer than the old way. 👍

const writeStream = fs.createWriteStream(traceFilename);
writeStream.on('finish', resolve);
writeStream.on('error', reject);
return pipeline(stream.Readable.from(traceIter), writeStream);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a compat TODO comment for the latter bit?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants