Do not trigger track update if selected track has not changed

This avoids unnecessary work in the load of the panel. See the
screenshots that show that 3 track updates are done on every trace load.
Interestingly enough, we don't need to do that many.

Before: https://screenshot.googleplex.com/8Y7c4jWbnWnqoyU
After: https://screenshot.googleplex.com/8zLxtnkkYTBTkFz

Bug: 1472155
Change-Id: I038b2add48342e4e7d83d694136c8d3d76712f44
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/4935530
Reviewed-by: Nancy Li <nancyly@chromium.org>
Commit-Queue: Andres Olivares <andoli@chromium.org>
Commit-Queue: Nancy Li <nancyly@chromium.org>
Auto-Submit: Andres Olivares <andoli@chromium.org>
diff --git a/front_end/panels/timeline/TimelineFlameChartView.ts b/front_end/panels/timeline/TimelineFlameChartView.ts
index 58555f1..6411138 100644
--- a/front_end/panels/timeline/TimelineFlameChartView.ts
+++ b/front_end/panels/timeline/TimelineFlameChartView.ts
@@ -75,7 +75,7 @@
   private searchRegex?: RegExp;
   #traceEngineData: TraceEngine.Handlers.Migration.PartialTraceData|null;
   #currentBreadcrumbTimeWindow?: TraceEngine.Types.Timing.TraceWindow;
-
+  private selectedGroupName: string|null = null;
   constructor(
       delegate: TimelineModeViewDelegate, threadTracksSource: ThreadTracksSource = ThreadTracksSource.BOTH_ENGINES) {
     super();
@@ -215,9 +215,10 @@
   }
 
   updateSelectedGroup(flameChart: PerfUI.FlameChart.FlameChart, group: PerfUI.FlameChart.Group|null): void {
-    if (flameChart !== this.mainFlameChart) {
+    if (flameChart !== this.mainFlameChart || this.selectedGroupName === group?.name) {
       return;
     }
+    this.selectedGroupName = group?.name || null;
     this.#selectedEvents = group ? this.mainDataProvider.groupTreeEvents(group) : null;
     this.updateTrack();
   }
diff --git a/test/e2e/performance/recording_test.ts b/test/e2e/performance/recording_test.ts
index b79ed13..fb8ad91 100644
--- a/test/e2e/performance/recording_test.ts
+++ b/test/e2e/performance/recording_test.ts
@@ -2,8 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-import {assert} from 'chai';
-
+import {waitForFunction} from '../../shared/helper.js';
 import {describe, it} from '../../shared/mocha-extensions.js';
 import {
   getTotalTimeFromSummary,
@@ -19,16 +18,19 @@
 
     await startRecording();
     await stopRecording();
-
-    // Check that the recording shows the pie chart with a non 0 total time.
-    const totalTime = await getTotalTimeFromSummary();
-    assert.isAbove(totalTime, 0, 'The recording was created successfully');
+    await waitForFunction(async () => {
+      const totalTime = await getTotalTimeFromSummary();
+      return totalTime > 0;
+    });
   });
 
   it('can reload and record a trace', async () => {
     await navigateToPerformanceTab('fake-website');
     await reloadAndRecord();
-    const totalTime = await getTotalTimeFromSummary();
-    assert.isAbove(totalTime, 0, 'The recording was created successfully');
+
+    await waitForFunction(async () => {
+      const totalTime = await getTotalTimeFromSummary();
+      return totalTime > 0;
+    });
   });
 });