profiler icon indicating copy to clipboard operation
profiler copied to clipboard

Create a range selection by clicking on a screenshot

Open ecsmyth opened this issue 6 years ago • 6 comments

As a ~PM stumbling through a profile~ user investigating a responsiveness issue, I want to be able to select the nsRefreshDriver::Tick for a screenshot, so that I can quickly and accurately focus on the code that produced the frame.

I can currently select nsRefreshDriver::Tick by double clicking on the entry in the Stack Chart. It would nice if I could create the range selection by, for example, clicking a screenshot. This would allow me to remain on my current view and to more quickly and accurately create the selection than trying to eyeball the correct Tick below (and starting slightly before) a screenshot.

ecsmyth avatar Jul 07 '20 20:07 ecsmyth

Would be a good stopgap until we have an FPS graph where users can select individual frames.

To be consistent with the stacks, the heuristic could be that double-clicking a screenshot puts the selected range on the related vsync range.

digitarald avatar Jul 07 '20 22:07 digitarald

I wrote up a description as a comment in a diff of how this could be handled.

diff --git a/src/components/timeline/TrackScreenshots.js b/src/components/timeline/TrackScreenshots.js
index 5500029e..4adf06c1 100644
--- a/src/components/timeline/TrackScreenshots.js
+++ b/src/components/timeline/TrackScreenshots.js
@@ -93,6 +93,16 @@ class Screenshots extends PureComponent<Props, State> {
         style={{ height: trackHeight }}
         onMouseLeave={this._handleMouseLeave}
         onMouseMove={this._handleMouseMove}
+        onClick={
+          // Dispatch the UPDATE_PREVIEW_SELECTION action with the correct range.
+          // The mouse click event can be translated to a screenshot marker
+          // using the function findScreenshotAtMouse
+          // Then, use that screenshot marker's start and end time to create
+          // the preview selection. You may need to compare the start time of the
+          // marker at that point, and the next marker.
+          //
+          // Make sure to handle clicking the last or first screenshot correctly.
+        }
       >
         <ScreenshotStrip
           thread={thread}

This will also need a test.

diff --git a/src/test/components/TrackScreenshots.test.js b/src/test/components/TrackScreenshots.test.js
index 4291e153..c4020840 100644
--- a/src/test/components/TrackScreenshots.test.js
+++ b/src/test/components/TrackScreenshots.test.js
@@ -56,6 +56,18 @@ describe('timeline/TrackScreenshots', function() {
     expect(screenshotHover()).toBeTruthy();
   });
 
+  it('sets a preview selection when clicking with the mouse', () => {
+    // TODO
+  });
+
+  it('sets a preview selection when clicking before the first screenshot', () => {
+    // TODO
+  });
+
+  it('sets a preview selection when clicking after the last screenshot', () => {
+    // TODO
+  });
+
   it('removes the hover when moving the mouse out', () => {
     const { screenshotHover, screenshotTrack, moveMouse } = setup();
 

gregtatum avatar Oct 09 '20 18:10 gregtatum

@gregtatum @julienw @canova Can I work on this? It looks scary but I am sure I will be able to do something useful.

nibble0101 avatar Oct 12 '20 09:10 nibble0101

Given the instructions by @gregtatum above, these are my thoughts.

  1. findScreenshotAtMouse referred to here is the one which has already been defined in HoverPreview component
  2. findScreenshotAtMouse is invoked with offsetX as argument in _clickHandler
  3. offsetX is obtained from the synthetic event using event.pageX - event.currentTarget.getBoundingClientRect().left
  4. The index i returned by findScreenshotAtMouse is the screenshot marker
  5. If the returned index i is null, exit _clickHandler else dispatch an action like:
 updatePreviewSelection({
      hasSelection: true,
      isModifying: false,
      selectionStart: start,
      selectionEnd: end,
    });

I have failed to understand the instructions below which makes me believe my thought process above is not really correct.

  • You may need to compare the start time of the marker at that point, and the next marker.
  • Make sure to handle clicking the last or first screenshot correctly.

@gregtatum @canova @julienw I need your guidance here. Am I on the right track? You can see more in the PR.

nibble0101 avatar Oct 14 '20 07:10 nibble0101

I think your outline looks good.

Just a quick precision from looking at the code: I think we'll have to change a bit HoverPreview too. Indeed, I believe the new code you'll add will be in Screenshots. Therefore I suggest that findScreenshotAtMouse will be moved to Screenshots: then Screenshots will retrieve the current hovered screenshot, and pass directly a ScreenshotPayload to HoverPreview.

About the 2 remarks from Greg:

  • You may need to compare the start time of the marker at that point, and the next marker.

He meant that, to find the new range, you might need to look at the next screenshot. I think that should be OK to look at start and start + dur which should already take that into account, but Greg's comment was that this might not be the case.

  • Make sure to handle clicking the last or first screenshot correctly.

This is only a warning that the last or first screenshot in a track may behave differently. So just take care that they work. Again I think that start and start+dur should already take that into account, but please just double-check these cases.

Hope this helps!

julienw avatar Oct 14 '20 09:10 julienw

Therefore I suggest that findScreenshotAtMouse will be moved to Screenshots: then Screenshots will retrieve the current hovered screenshot, and pass directly a ScreenshotPayload to HoverPreview

Since the above comment, I have made some major changes.

  1. I wanted to do the extraction in the render method but then essentially I will have to do something like:
    const { pageX, offsetX, containerTop } = this.state;
    let payload: ScreenshotPayload | null;
    if (offsetX !== null) {
      const screenshotIndex = this.findScreenshotAtMouse(offsetX);
      if (screenshotIndex === null) {
        payload = null;
      } else {
        payload = (screenshots[screenshotIndex].data: any);
      }
    } else {
      payload = null;
    }

and then pass payload to HoverPreview. 2) Have payload in state and then pass it to HoverPreview.

I prefer the first one over the second one because I think payload will just be redundant in state because it is derived from offsetX.

This is what is left in HoverPreview after moving findScreenshotAtMouse to Screenshots.

if (
      isMakingPreviewSelection ||
      offsetX === null ||
      pageX === null ||
      payload === null
    ) {
      return null;
    }
    const { url, windowWidth, windowHeight } = payload;

nibble0101 avatar Oct 15 '20 09:10 nibble0101