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

core: refactor finding of trace start #6370

Merged
merged 6 commits into from
Oct 25, 2018

Conversation

connorjclark
Copy link
Collaborator

Split from #6366.

Refactor how we get the pid/tid/frameId of the current target. The tracing processor was returning a specific event, and even synthesizing it. The callers of this function only grabbed the pid/tid/frameId, so instead of returning an event object I return just the pertinent data.

@connorjclark connorjclark changed the title Refactor tracing processor 2 core: refactor tracing processor Oct 23, 2018
Copy link
Collaborator

@patrickhulce patrickhulce left a comment

Choose a reason for hiding this comment

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

very excited about the explicitness this introduces on why startedInPage was even a thing!!

LGTM other than the ts point, happy to approve if no one else thinks ts change is worth it :)

@connorjclark
Copy link
Collaborator Author

I'll remove the ts stuff now.

Sidenote, check out this cool VSCode Jest plugin (orta.vscode-jest)!
image

Copy link
Collaborator

@patrickhulce patrickhulce left a comment

Choose a reason for hiding this comment

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

LGTM!

@brendankenny brendankenny changed the title core: refactor tracing processor core: refactor finding of trace start Oct 24, 2018
pid,
tid,
frameId,
};
Copy link
Member

Choose a reason for hiding this comment

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

Style bikeshedding: what about some early returns? That makes it a little easier to see it's either the first conditional matches and it's done, or it's the next conditional and done, or it throws.

Something like

static findMainFrameIds(events) {
  // Prefer the newer TracingStartedInBrowser event first, if it exists
  const startedInBrowserEvt = events.find(e => e.name === 'TracingStartedInBrowser');
  if (startedInBrowserEvt && startedInBrowserEvt.args.data &&
      startedInBrowserEvt.args.data.frames) {
    const mainFrame = startedInBrowserEvt.args.data.frames.find(frame => !frame.parent);
    const frameId = mainFrame && mainFrame.frame;
    const pid = mainFrame && mainFrame.processId;

    const threadNameEvt = events.find(e => e.pid === pid && e.ph === 'M' &&
      e.cat === '__metadata' && e.name === 'thread_name' && e.args.name === 'CrRendererMain');
    const tid = threadNameEvt && threadNameEvt.tid;

    if (pid && tid && frameId) {
      return {
        pid,
        tid,
        frameId,
      };
    }
  }

  // Support legacy browser versions that do not emit TracingStartedInBrowser event.
  // The first TracingStartedInPage in the trace is definitely our renderer thread of interest
  // Beware: the tracingStartedInPage event can appear slightly after a navigationStart
  const startedInPageEvt = events.find(e => e.name === 'TracingStartedInPage');
  if (startedInPageEvt && startedInPageEvt.args && startedInPageEvt.args.data) {
    const frameId = startedInPageEvt.args.data.page;

    if (frameId) {
      return {
        pid: startedInPageEvt.pid,
        tid: startedInPageEvt.tid,
        frameId,
      };
    }
  }

  throw new LHError(LHError.errors.NO_TRACING_STARTED);
}

@@ -359,8 +359,8 @@ declare global {
processEvents: Array<TraceEvent>;
/** The subset of trace events from the page's main thread, sorted by timestamp. */
mainThreadEvents: Array<TraceEvent>;
/** The event marking the start of tracing in the target browser. */
startedInPageEvt: TraceEvent;
/** Various ids for the current trace context. */
Copy link
Member

Choose a reason for hiding this comment

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

maybe something like /** IDs for the trace's main frame, process, and thread. */?

Copy link
Member

@brendankenny brendankenny left a comment

Choose a reason for hiding this comment

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

LGTM2!

@brendankenny brendankenny merged commit ff3ccde into master Oct 25, 2018
@brendankenny brendankenny deleted the refactor-tracing-processor-2 branch October 25, 2018 23:24
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.

3 participants