{"action":"created","comment":{"url":"https://api.github.com/repos/GoogleChrome/lighthouse/pulls/comments/119268464","pull_request_review_id":41130534,"id":119268464,"diff_hunk":"@@ -241,23 +188,45 @@ class TraceProcessor {\n   }\n \n   /**\n-   * Provides the top level events on the main thread.\n-   * @param {!traceviewer.Model} model\n-   * @param {{traceEvents: !Array<!Object>}} trace\n+   * Provides the top level events on the main thread with timestamps in ms relative to navigation\n+   * start.\n+   * @param {!TraceOfTabArtifact} tabTrace\n    * @param {number=} startTime Optional start time (in ms) of range of interest. Defaults to trace start.\n    * @param {number=} endTime Optional end time (in ms) of range of interest. Defaults to trace end.\n    * @return {!Array<{start: number, end: number, duration: number}>}\n    */\n-  static getMainThreadTopLevelEvents(model, trace, startTime = -Infinity, endTime = Infinity) {\n-    // Find the main thread via the first TracingStartedInPage event in the trace\n-    const startEvent = trace.traceEvents.find(event => event.name === 'TracingStartedInPage');\n-    const mainThread = TraceProcessor._findMainThreadFromIds(model, startEvent.pid, startEvent.tid);\n-\n-    return mainThread.sliceGroup.slices.filter(slice => {\n-      return slice.title === SCHEDULABLE_TASK_TITLE &&\n-          slice.end > startTime &&\n-          slice.start < endTime;\n-    });\n+  static getMainThreadTopLevelEvents(tabTrace, startTime = -Infinity, endTime = Infinity) {\n+    let lastEvt = {start: -Infinity, end: -Infinity};\n+    const topLevelEvents = [];\n+    // note: processEvents is already sorted by event start\n+    for (const event of tabTrace.processEvents) {\n+      if (event.name !== SCHEDULABLE_TASK_TITLE || !event.dur) continue;\n+\n+      const start = (event.ts - tabTrace.navigationStartEvt.ts) / 1000;\n+      const end = (event.ts + event.dur - tabTrace.navigationStartEvt.ts) / 1000;\n+      if (start > endTime || end < startTime) continue;\n+\n+      const currentEvt = {\n+        start,\n+        end,\n+        duration: event.dur / 1000,\n+        events: [event],\n+      };\n+\n+      if (currentEvt.end < lastEvt.end) {\n+        // The current event is completely inside the previous event, add to previous\n+        lastEvt.events.push(event);\n+      } else if (currentEvt.start < lastEvt.end) {\n+        // The current event overlaps with the previous event, extend the duration and add to previous\n+        lastEvt.events.push(event);\n+        lastEvt.end = currentEvt.end;\n+        lastEvt.duration = currentEvt.end - currentEvt.start;","path":"lighthouse-core/lib/traces/tracing-processor.js","position":219,"original_position":219,"commit_id":"184537b97eab56db6cfced4d95a7fad510bb3e18","original_commit_id":"184537b97eab56db6cfced4d95a7fad510bb3e18","user":{"login":"brendankenny","id":316891,"avatar_url":"https://avatars0.githubusercontent.com/u/316891?v=3","gravatar_id":"","url":"https://api.github.com/users/brendankenny","html_url":"https://github.com/brendankenny","followers_url":"https://api.github.com/users/brendankenny/followers","following_url":"https://api.github.com/users/brendankenny/following{/other_user}","gists_url":"https://api.github.com/users/brendankenny/gists{/gist_id}","starred_url":"https://api.github.com/users/brendankenny/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brendankenny/subscriptions","organizations_url":"https://api.github.com/users/brendankenny/orgs","repos_url":"https://api.github.com/users/brendankenny/repos","events_url":"https://api.github.com/users/brendankenny/events{/privacy}","received_events_url":"https://api.github.com/users/brendankenny/received_events","type":"User","site_admin":false},"body":"should this be `lastEvt.duration = currentEvt.end - lastEvt.start;` (or `currentEvt.end - currentEvt.start`) if extending duration by the end of `currentEvt` (but keeping the same `start`)?","created_at":"2017-05-31T04:22:40Z","updated_at":"2017-05-31T05:00:13Z","html_url":"https://github.com/GoogleChrome/lighthouse/pull/2347#discussion_r119268464","pull_request_url":"https://api.github.com/repos/GoogleChrome/lighthouse/pulls/2347","_links":{"self":{"href":"https://api.github.com/repos/GoogleChrome/lighthouse/pulls/comments/119268464"},"html":{"href":"https://github.com/GoogleChrome/lighthouse/pull/2347#discussion_r119268464"},"pull_request":{"href":"https://api.github.com/repos/GoogleChrome/lighthouse/pulls/2347"}}},"pull_request":{"url":"https://api.github.com/repos/GoogleChrome/lighthouse/pulls/2347","id":122123352,"html_url":"https://github.com/GoogleChrome/lighthouse/pull/2347","diff_url":"https://github.com/GoogleChrome/lighthouse/pull/2347.diff","patch_url":"https://github.com/GoogleChrome/lighthouse/pull/2347.patch","issue_url":"https://api.github.com/repos/GoogleChrome/lighthouse/issues/2347","number":2347,"state":"open","locked":false,"title":"fix: normalize all times to navStart, remove traceviewer model","user":{"login":"patrickhulce","id":2301202,"avatar_url":"https://avatars1.githubusercontent.com/u/2301202?v=3","gravatar_id":"","url":"https://api.github.com/users/patrickhulce","html_url":"https://github.com/patrickhulce","followers_url":"https://api.github.com/users/patrickhulce/followers","following_url":"https://api.github.com/users/patrickhulce/following{/other_user}","gists_url":"https://api.github.com/users/patrickhulce/gists{/gist_id}","starred_url":"https://api.github.com/users/patrickhulce/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/patrickhulce/subscriptions","organizations_url":"https://api.github.com/users/patrickhulce/orgs","repos_url":"https://api.github.com/users/patrickhulce/repos","events_url":"https://api.github.com/users/patrickhulce/events{/privacy}","received_events_url":"https://api.github.com/users/patrickhulce/received_events","type":"User","site_admin":false},"body":"brings us closer to closing #2235 (still there for stats we can remove separately)\r\n\r\nWould like to do some more testing of how this impacts metrics, but the current state is pretty bad with ~10% of sites (just did 100 from alexa top 1000) failing to compute TTCI when it should have been computed (there was a 5s quiet of both network and CPU but due to the inconsistency between traceviewer model and network record timestamps the quiet periods didn't appear to line up in the audit)\r\n\r\n~~NOTE: moving to first navStart is optional and can easily be reverted, I wanted to test this out since it still meets the goal of the tests of capturing the correct FMP it just reports longer times which in some cases is definitely the right thing to do and the failure cases are unknown~~ (reverted)","created_at":"2017-05-24T00:36:18Z","updated_at":"2017-05-31T05:00:13Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c4584b7c504922394175a7fa5be930496d7e78f8","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/GoogleChrome/lighthouse/pulls/2347/commits","review_comments_url":"https://api.github.com/repos/GoogleChrome/lighthouse/pulls/2347/comments","review_comment_url":"https://api.github.com/repos/GoogleChrome/lighthouse/pulls/comments{/number}","comments_url":"https://api.github.com/repos/GoogleChrome/lighthouse/issues/2347/comments","statuses_url":"https://api.github.com/repos/GoogleChrome/lighthouse/statuses/184537b97eab56db6cfced4d95a7fad510bb3e18","head":{"label":"GoogleChrome:rmtraceviewer","ref":"rmtraceviewer","sha":"184537b97eab56db6cfced4d95a7fad510bb3e18","user":{"login":"GoogleChrome","id":1778935,"avatar_url":"https://avatars0.githubusercontent.com/u/1778935?v=3","gravatar_id":"","url":"https://api.github.com/users/GoogleChrome","html_url":"https://github.com/GoogleChrome","followers_url":"https://api.github.com/users/GoogleChrome/followers","following_url":"https://api.github.com/users/GoogleChrome/following{/other_user}","gists_url":"https://api.github.com/users/GoogleChrome/gists{/gist_id}","starred_url":"https://api.github.com/users/GoogleChrome/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GoogleChrome/subscriptions","organizations_url":"https://api.github.com/users/GoogleChrome/orgs","repos_url":"https://api.github.com/users/GoogleChrome/repos","events_url":"https://api.github.com/users/GoogleChrome/events{/privacy}","received_events_url":"https://api.github.com/users/GoogleChrome/received_events","type":"Organization","site_admin":false},"repo":{"id":53370988,"name":"lighthouse","full_name":"GoogleChrome/lighthouse","owner":{"login":"GoogleChrome","id":1778935,"avatar_url":"https://avatars0.githubusercontent.com/u/1778935?v=3","gravatar_id":"","url":"https://api.github.com/users/GoogleChrome","html_url":"https://github.com/GoogleChrome","followers_url":"https://api.github.com/users/GoogleChrome/followers","following_url":"https://api.github.com/users/GoogleChrome/following{/other_user}","gists_url":"https://api.github.com/users/GoogleChrome/gists{/gist_id}","starred_url":"https://api.github.com/users/GoogleChrome/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GoogleChrome/subscriptions","organizations_url":"https://api.github.com/users/GoogleChrome/orgs","repos_url":"https://api.github.com/users/GoogleChrome/repos","events_url":"https://api.github.com/users/GoogleChrome/events{/privacy}","received_events_url":"https://api.github.com/users/GoogleChrome/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/GoogleChrome/lighthouse","description":"Auditing, performance metrics, and best practices for Progressive Web Apps","fork":false,"url":"https://api.github.com/repos/GoogleChrome/lighthouse","forks_url":"https://api.github.com/repos/GoogleChrome/lighthouse/forks","keys_url":"https://api.github.com/repos/GoogleChrome/lighthouse/keys{/key_id}","collaborators_url":"https://api.github.com/repos/GoogleChrome/lighthouse/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/GoogleChrome/lighthouse/teams","hooks_url":"https://api.github.com/repos/GoogleChrome/lighthouse/hooks","issue_events_url":"https://api.github.com/repos/GoogleChrome/lighthouse/issues/events{/number}","events_url":"https://api.github.com/repos/GoogleChrome/lighthouse/events","assignees_url":"https://api.github.com/repos/GoogleChrome/lighthouse/assignees{/user}","branches_url":"https://api.github.com/repos/GoogleChrome/lighthouse/branches{/branch}","tags_url":"https://api.github.com/repos/GoogleChrome/lighthouse/tags","blobs_url":"https://api.github.com/repos/GoogleChrome/lighthouse/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/GoogleChrome/lighthouse/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/GoogleChrome/lighthouse/git/refs{/sha}","trees_url":"https://api.github.com/repos/GoogleChrome/lighthouse/git/trees{/sha}","statuses_url":"https://api.github.com/repos/GoogleChrome/lighthouse/statuses/{sha}","languages_url":"https://api.github.com/repos/GoogleChrome/lighthouse/languages","stargazers_url":"https://api.github.com/repos/GoogleChrome/lighthouse/stargazers","contributors_url":"https://api.github.com/repos/GoogleChrome/lighthouse/contributors","subscribers_url":"https://api.github.com/repos/GoogleChrome/lighthouse/subscribers","subscription_url":"https://api.github.com/repos/GoogleChrome/lighthouse/subscription","commits_url":"https://api.github.com/repos/GoogleChrome/lighthouse/commits{/sha}","git_commits_url":"https://api.github.com/repos/GoogleChrome/lighthouse/git/commits{/sha}","comments_url":"https://api.github.com/repos/GoogleChrome/lighthouse/comments{/number}","issue_comment_url":"https://api.github.com/repos/GoogleChrome/lighthouse/issues/comments{/number}","contents_url":"https://api.github.com/repos/GoogleChrome/lighthouse/contents/{+path}","compare_url":"https://api.github.com/repos/GoogleChrome/lighthouse/compare/{base}...{head}","merges_url":"https://api.github.com/repos/GoogleChrome/lighthouse/merges","archive_url":"https://api.github.com/repos/GoogleChrome/lighthouse/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/GoogleChrome/lighthouse/downloads","issues_url":"https://api.github.com/repos/GoogleChrome/lighthouse/issues{/number}","pulls_url":"https://api.github.com/repos/GoogleChrome/lighthouse/pulls{/number}","milestones_url":"https://api.github.com/repos/GoogleChrome/lighthouse/milestones{/number}","notifications_url":"https://api.github.com/repos/GoogleChrome/lighthouse/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/GoogleChrome/lighthouse/labels{/name}","releases_url":"https://api.github.com/repos/GoogleChrome/lighthouse/releases{/id}","deployments_url":"https://api.github.com/repos/GoogleChrome/lighthouse/deployments","created_at":"2016-03-08T01:03:11Z","updated_at":"2017-05-31T03:49:17Z","pushed_at":"2017-05-31T03:21:07Z","git_url":"git://github.com/GoogleChrome/lighthouse.git","ssh_url":"git@github.com:GoogleChrome/lighthouse.git","clone_url":"https://github.com/GoogleChrome/lighthouse.git","svn_url":"https://github.com/GoogleChrome/lighthouse","homepage":"https://developers.google.com/web/tools/lighthouse/","size":16525,"stargazers_count":8795,"watchers_count":8795,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":false,"has_wiki":false,"has_pages":true,"forks_count":424,"mirror_url":null,"open_issues_count":341,"forks":424,"open_issues":341,"watchers":8795,"default_branch":"master"}},"base":{"label":"GoogleChrome:master","ref":"master","sha":"ca7d066b2f183bcddc625ceae0e3571acebb8df5","user":{"login":"GoogleChrome","id":1778935,"avatar_url":"https://avatars0.githubusercontent.com/u/1778935?v=3","gravatar_id":"","url":"https://api.github.com/users/GoogleChrome","html_url":"https://github.com/GoogleChrome","followers_url":"https://api.github.com/users/GoogleChrome/followers","following_url":"https://api.github.com/users/GoogleChrome/following{/other_user}","gists_url":"https://api.github.com/users/GoogleChrome/gists{/gist_id}","starred_url":"https://api.github.com/users/GoogleChrome/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GoogleChrome/subscriptions","organizations_url":"https://api.github.com/users/GoogleChrome/orgs","repos_url":"https://api.github.com/users/GoogleChrome/repos","events_url":"https://api.github.com/users/GoogleChrome/events{/privacy}","received_events_url":"https://api.github.com/users/GoogleChrome/received_events","type":"Organization","site_admin":false},"repo":{"id":53370988,"name":"lighthouse","full_name":"GoogleChrome/lighthouse","owner":{"login":"GoogleChrome","id":1778935,"avatar_url":"https://avatars0.githubusercontent.com/u/1778935?v=3","gravatar_id":"","url":"https://api.github.com/users/GoogleChrome","html_url":"https://github.com/GoogleChrome","followers_url":"https://api.github.com/users/GoogleChrome/followers","following_url":"https://api.github.com/users/GoogleChrome/following{/other_user}","gists_url":"https://api.github.com/users/GoogleChrome/gists{/gist_id}","starred_url":"https://api.github.com/users/GoogleChrome/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GoogleChrome/subscriptions","organizations_url":"https://api.github.com/users/GoogleChrome/orgs","repos_url":"https://api.github.com/users/GoogleChrome/repos","events_url":"https://api.github.com/users/GoogleChrome/events{/privacy}","received_events_url":"https://api.github.com/users/GoogleChrome/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/GoogleChrome/lighthouse","description":"Auditing, performance metrics, and best practices for Progressive Web Apps","fork":false,"url":"https://api.github.com/repos/GoogleChrome/lighthouse","forks_url":"https://api.github.com/repos/GoogleChrome/lighthouse/forks","keys_url":"https://api.github.com/repos/GoogleChrome/lighthouse/keys{/key_id}","collaborators_url":"https://api.github.com/repos/GoogleChrome/lighthouse/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/GoogleChrome/lighthouse/teams","hooks_url":"https://api.github.com/repos/GoogleChrome/lighthouse/hooks","issue_events_url":"https://api.github.com/repos/GoogleChrome/lighthouse/issues/events{/number}","events_url":"https://api.github.com/repos/GoogleChrome/lighthouse/events","assignees_url":"https://api.github.com/repos/GoogleChrome/lighthouse/assignees{/user}","branches_url":"https://api.github.com/repos/GoogleChrome/lighthouse/branches{/branch}","tags_url":"https://api.github.com/repos/GoogleChrome/lighthouse/tags","blobs_url":"https://api.github.com/repos/GoogleChrome/lighthouse/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/GoogleChrome/lighthouse/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/GoogleChrome/lighthouse/git/refs{/sha}","trees_url":"https://api.github.com/repos/GoogleChrome/lighthouse/git/trees{/sha}","statuses_url":"https://api.github.com/repos/GoogleChrome/lighthouse/statuses/{sha}","languages_url":"https://api.github.com/repos/GoogleChrome/lighthouse/languages","stargazers_url":"https://api.github.com/repos/GoogleChrome/lighthouse/stargazers","contributors_url":"https://api.github.com/repos/GoogleChrome/lighthouse/contributors","subscribers_url":"https://api.github.com/repos/GoogleChrome/lighthouse/subscribers","subscription_url":"https://api.github.com/repos/GoogleChrome/lighthouse/subscription","commits_url":"https://api.github.com/repos/GoogleChrome/lighthouse/commits{/sha}","git_commits_url":"https://api.github.com/repos/GoogleChrome/lighthouse/git/commits{/sha}","comments_url":"https://api.github.com/repos/GoogleChrome/lighthouse/comments{/number}","issue_comment_url":"https://api.github.com/repos/GoogleChrome/lighthouse/issues/comments{/number}","contents_url":"https://api.github.com/repos/GoogleChrome/lighthouse/contents/{+path}","compare_url":"https://api.github.com/repos/GoogleChrome/lighthouse/compare/{base}...{head}","merges_url":"https://api.github.com/repos/GoogleChrome/lighthouse/merges","archive_url":"https://api.github.com/repos/GoogleChrome/lighthouse/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/GoogleChrome/lighthouse/downloads","issues_url":"https://api.github.com/repos/GoogleChrome/lighthouse/issues{/number}","pulls_url":"https://api.github.com/repos/GoogleChrome/lighthouse/pulls{/number}","milestones_url":"https://api.github.com/repos/GoogleChrome/lighthouse/milestones{/number}","notifications_url":"https://api.github.com/repos/GoogleChrome/lighthouse/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/GoogleChrome/lighthouse/labels{/name}","releases_url":"https://api.github.com/repos/GoogleChrome/lighthouse/releases{/id}","deployments_url":"https://api.github.com/repos/GoogleChrome/lighthouse/deployments","created_at":"2016-03-08T01:03:11Z","updated_at":"2017-05-31T03:49:17Z","pushed_at":"2017-05-31T03:21:07Z","git_url":"git://github.com/GoogleChrome/lighthouse.git","ssh_url":"git@github.com:GoogleChrome/lighthouse.git","clone_url":"https://github.com/GoogleChrome/lighthouse.git","svn_url":"https://github.com/GoogleChrome/lighthouse","homepage":"https://developers.google.com/web/tools/lighthouse/","size":16525,"stargazers_count":8795,"watchers_count":8795,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":false,"has_wiki":false,"has_pages":true,"forks_count":424,"mirror_url":null,"open_issues_count":341,"forks":424,"open_issues":341,"watchers":8795,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/GoogleChrome/lighthouse/pulls/2347"},"html":{"href":"https://github.com/GoogleChrome/lighthouse/pull/2347"},"issue":{"href":"https://api.github.com/repos/GoogleChrome/lighthouse/issues/2347"},"comments":{"href":"https://api.github.com/repos/GoogleChrome/lighthouse/issues/2347/comments"},"review_comments":{"href":"https://api.github.com/repos/GoogleChrome/lighthouse/pulls/2347/comments"},"review_comment":{"href":"https://api.github.com/repos/GoogleChrome/lighthouse/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/GoogleChrome/lighthouse/pulls/2347/commits"},"statuses":{"href":"https://api.github.com/repos/GoogleChrome/lighthouse/statuses/184537b97eab56db6cfced4d95a7fad510bb3e18"}}}}
{"actor":{"display_login":"brendankenny"}}