Skip to content

Fetch latest timeline events before exporting Performance data - #10055

Merged
srawlins merged 4 commits into
flutter:masterfrom
khanak0509:fix-9731-export-timeline-events
Nov 12, 2026
Merged

srawlins merged 4 commits into
flutter:masterfrom
khanak0509:fix-9731-export-timeline-events

Conversation

@khanak0509

@khanak0509 khanak0509 commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #9731

this PR fixes issue #9731 where data exported from the Performance screen was missing the most recent timeline events. Timeline events are only pulled from the VM every 10 seconds, so frames drawn after the last poll were exported without them. Now the latest timeline events are pulled before exporting, the same way the Network screen does with fetchFullDataBeforeExport.

Before

most recent frames (1331–1411) had no timeline events in the file.

Screenshot 2026-10-20 at 2 00 34 AM

After

all of them had timeline events, including the most recent frame

Screenshot 2026-10-20 at 2 02 41 AM

Pre-launch Checklist

General checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read the Flutter Style Guide recently, and have followed its advice.
  • I signed the CLA.
  • I updated/added relevant documentation (doc comments with ///).

Issues checklist

Tests checklist

  • I added new tests to check the change I am making...
  • OR there is a reason for not adding tests, which I explained in the PR description.

AI-tooling checklist

  • I did not use any AI tooling in creating this PR.
  • OR I did use AI tooling, and...
    • I read the AI contributions guidelines and agree to follow them.
    • I reviewed all AI-generated code before opening this PR.
    • I understand and am able to discuss the code in this PR.
    • I have verifed the accuracy of any AI-generated text included in the PR description.
    • I commit to verifying the accuracy of any AI-generated code or text that I upload in response to review comments.

Feature-change checklist

  • This PR does not change the DevTools UI or behavior and...
    • I added the release-notes-not-required label or left a comment requesting the label be added.
  • OR this PR does change the DevTools UI or behavior and...
    • I added an entry to packages/devtools_app/release_notes/NEXT_RELEASE_NOTES.md.
    • I included before/after screenshots and/or a GIF demo of the new UI to my PR description.
    • I ran the DevTools app locally to manually verify my changes.

build.yaml badge

If you need help, consider asking for help on Discord.

@khanak0509
khanak0509 marked this pull request as ready for review November 11, 2026 21:04

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request ensures that the latest timeline events are pulled from the VM before exporting performance data, preventing recent events from being missing. It introduces fetchFullDataBeforeExport in PerformanceController and pullLatestTimelineEvents in TimelineEventsController, along with corresponding unit tests. A review comment highlights a potential race condition where concurrent calls to _pullPerfettoVmTimeline could result in duplicate timeline events, and suggests tracking the active pull future to prevent overlapping requests.

Comment on lines +348 to +355
Future<void> pullLatestTimelineEvents() async {
try {
await _pullPerfettoVmTimeline();
} catch (e, st) {
// Don't block the export of the data we already have.
_log.warning('Failed to pull the latest timeline events.', e, st);
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

[MUST-FIX] Potential Race Condition / Duplicate Timeline Events

Calling _pullPerfettoVmTimeline() concurrently can lead to a race condition where duplicate timeline events are fetched and added to traceRingBuffer.

Why this happens:

In _pullPerfettoVmTimeline(), _nextPollStartMicros is read at the beginning of the method but is only updated at the very end (after several asynchronous await points like getVMTimelineMicros and getPerfettoVMTimeline).
If pullLatestTimelineEvents() is called while a periodic poll (via _timelinePollingRateLimiter) or a manual refresh (via forceRefresh()) is already in progress, both executions will use the same _nextPollStartMicros value, resulting in overlapping time ranges and duplicate trace packets being appended to traceRingBuffer.

Suggested Fix:

To prevent concurrent executions of _pullPerfettoVmTimeline(), we should track the active pull Future and return it if a pull is already in progress.

Since _pullPerfettoVmTimeline is outside the current diff hunk, you can declare a Future<void>? _activePull field in TimelineEventsController and update _pullPerfettoVmTimeline as follows:

Future<void>? _activePull;

Future<void> _pullPerfettoVmTimeline({bool isInitialPull = false}) async {
  if (_activePull != null) {
    return _activePull;
  }
  final completer = Completer<void>();
  _activePull = completer.future;
  try {
    final service = serviceConnection.serviceManager.service;
    if (service == null) return;
    // ... existing implementation ...
    completer.complete();
  } catch (e, st) {
    completer.completeError(e, st);
    rethrow;
  } finally {
    _activePull = null;
  }
}
References
  1. Prefix every comment with a severity: [MUST-FIX] for logical bugs. (link)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

thanks! fixed

@khanak0509
khanak0509 requested a review from a team as a code owner November 12, 2026 07:59
@khanak0509
khanak0509 requested review from srawlins and removed request for a team November 12, 2026 07:59
…-9731-export-timeline-events

# Conflicts:
#	packages/devtools_app/release_notes/NEXT_RELEASE_NOTES.md
@srawlins
srawlins merged commit 6676ecd into flutter:master Nov 12, 2026
51 checks passed
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.

Missing timeline events in performance data export

2 participants