Skip to content

Conversation

@ghemawat
Copy link
Contributor

@ghemawat ghemawat commented Sep 1, 2023

We now do some rudimentary testing of the flamegraph web interface. The test code is written in Javascript and uses a simple test fixture class.

@ghemawat ghemawat requested a review from aalexand September 1, 2023 20:07
@codecov-commenter
Copy link

codecov-commenter commented Sep 1, 2023

Codecov Report

Merging #802 (f76c90e) into main (20cde90) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##             main     #802   +/-   ##
=======================================
  Coverage   66.99%   66.99%           
=======================================
  Files          45       45           
  Lines        9861     9861           
=======================================
  Hits         6606     6606           
  Misses       2795     2795           
  Partials      460      460           

setContext(name, ...args) {
let str = name + "(";
let sep = "";
for (const arg of args) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we use args.join(",")?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea. Done.

}

log(...args) {
this.result.push(this.toArray("LOG", this.context, ...args));
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't know JS that well, but poking around a bit I think this can be just this.result.push("LOG", this.context, ...args);.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. You were close. I needed:

this.result.push(["LOG", this.context, ...args]);

@@ -0,0 +1,86 @@
(function () {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: I would maybe give the function a name and then call it explicitly at the end. This syntax with parens gave me a bit of a pause when reading the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

test.err("not above");
}
// TODO: Allow checking boxes above pivots.
if (rb.left < ra.left || rb.right > rb.right) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

rb.right comparison should be rb.right > ra.right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. Fixed.

}
// TODO: Allow checking boxes above pivots.
if (rb.left < ra.left || rb.right > rb.right) {
test.err("horizontal span is not nested inside horizontal span of");
Copy link
Collaborator

Choose a reason for hiding this comment

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

The "inside horizontal span of" part reads unfinished. Or maybe I misread it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Improved.

// rect gets the bounding box for box with text t.
function rect(t) {
const elem = boxMap.get(t);
if (!elem) test.err("did not find", t);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we return here? Otherwise it seems we'd be dereferencing a null in the call in the next line.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor Author

@ghemawat ghemawat left a comment

Choose a reason for hiding this comment

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

Thanks. Suggested changes made.

setContext(name, ...args) {
let str = name + "(";
let sep = "";
for (const arg of args) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea. Done.

}

log(...args) {
this.result.push(this.toArray("LOG", this.context, ...args));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. You were close. I needed:

this.result.push(["LOG", this.context, ...args]);

@@ -0,0 +1,86 @@
(function () {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

// rect gets the bounding box for box with text t.
function rect(t) {
const elem = boxMap.get(t);
if (!elem) test.err("did not find", t);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

test.err("not above");
}
// TODO: Allow checking boxes above pivots.
if (rb.left < ra.left || rb.right > rb.right) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. Fixed.

}
// TODO: Allow checking boxes above pivots.
if (rb.left < ra.left || rb.right > rb.right) {
test.err("horizontal span is not nested inside horizontal span of");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Improved.

We now do some rudimentary testing of the flamegraph web interface.
The test code is written in Javascript and uses a simple test
fixture class.
@ghemawat
Copy link
Contributor Author

ghemawat commented Sep 6, 2023

Cleaned up branch history by moving all changes made here into a single commit at the end.

aalexand
aalexand previously approved these changes Sep 6, 2023
test.setContext("checkWidth", t, fraction);
const r = rect(t);
if (!r) return;
const expect = (chartRect.width - 4) * fraction;
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: a named constant for the 4 might be good, it's a bit obscure as is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good point. Done, and thanks.

Question: I added the change as a separate commit. Do you prefer I amend the previous commit instead during code review and force push to github, or will you squash when you merge into main?

Copy link

@Louis-Ye Louis-Ye Sep 7, 2023

Choose a reason for hiding this comment

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

My 2 cents: personally I think amending the commit is better than squashing it into one, because it would be easier to relate the comments and CI runs to code in the PR.

We will squash them when merging into main.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think you meant "adding a new commit" instead of "amending the commit"?

I agree with the decision to not squash until merging into main. Also makes it easier for reviewers to see the changes since the last round of reviews.

Thanks.

Copy link

Choose a reason for hiding this comment

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

Right, I think "adding a new commit" is better than "amending" (in between reviews), and is much better than "squashing" all previous commits into one.

Thanks!

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't have strong preference, separate commits are easier so probably the default choice. One added advantage is being able to move out a specific part of the change into a separate PR if requested by a reviewer - easier to do if it's a separate commit. Doesn't happen that often though, at least for this repo.

Copy link

@Louis-Ye Louis-Ye left a comment

Choose a reason for hiding this comment

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

LGTM

@aalexand aalexand merged commit d3ddc79 into google:main Sep 7, 2023
@ghemawat ghemawat deleted the flametest branch September 8, 2023 00:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants