Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,15 @@ class NetworkController extends DevToolsScreenController
_currentNetworkRequests,
_filterAndRefreshSearchMatches,
);
autoDisposeStreamSubscription(
serviceConnection.serviceManager.isolateManager.onIsolateCreated.listen((
_,
) async {
if (_recordingNotifier.value) {
await allowedError(_enableNetworkTrafficRecordingOnAllIsolates());
Comment thread
muhammadkamel marked this conversation as resolved.
}
}),
);
}

@override
Expand Down Expand Up @@ -327,7 +336,7 @@ class NetworkController extends DevToolsScreenController
// Cancel existing polling timer before starting recording.
_updatePollingState(false);

networkService.updateLastHttpDataRefreshTime(
await networkService.updateLastHttpDataRefreshTime(
alreadyRecordingHttp: alreadyRecordingHttp,
);
final timestamp = await networkService.updateLastSocketDataRefreshTime(
Expand All @@ -352,11 +361,16 @@ class NetworkController extends DevToolsScreenController

// TODO(kenz): only call these if http logging and socket profiling are not

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Did this TODO get addressed by this PR? If not, please add it back so that we don't lose track of this work.

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.

Good catch — it was not addressed by this PR. I restored the TODO above _enableNetworkTrafficRecordingOnAllIsolates().

// already enabled. Listen to service manager streams for this info.
await _enableNetworkTrafficRecordingOnAllIsolates();
await togglePolling(true);
}

/// Enables HTTP timeline logging and socket profiling on all isolates.
Future<void> _enableNetworkTrafficRecordingOnAllIsolates() async {
await [
http_service.toggleHttpRequestLogging(true),
networkService.toggleSocketProfiling(true),
].wait;
await togglePolling(true);
}

Future<void> stopRecording() async {
Expand All @@ -382,7 +396,7 @@ class NetworkController extends DevToolsScreenController
/// This will ensure that future fetches for http and socket requests will at
/// most fetch requests since [updateLastRefreshTime] was called.
Future<void> updateLastRefreshTime() async {
networkService.updateLastHttpDataRefreshTime();
await networkService.updateLastHttpDataRefreshTime();
await networkService.updateLastSocketDataRefreshTime();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ class NetworkService {
NetworkController get networkController =>
screenControllers.lookup<NetworkController>();

/// Tracks the time (microseconds since epoch) that the HTTP profile was last
/// retrieved for a given isolate ID.
/// Tracks the VM timeline timestamp (microseconds) that the HTTP profile was
/// last retrieved for a given isolate ID.
///
/// These values are passed to `getHttpProfile` as `updatedSince`, which must
/// use the VM's monotonic timeline clock — not wall-clock time.
final lastHttpDataRefreshTimePerIsolate = <String, int>{};

/// Updates the last Socket data refresh time to the current time.
Expand All @@ -41,21 +44,25 @@ class NetworkService {
return timestamp;
}

/// Updates the last HTTP data refresh time to the current time.
/// Updates the last HTTP data refresh time to the current VM timeline time.
///
/// If [alreadyRecordingHttp] is true it's unclear when the last refresh time
/// would have occurred, so the refresh time is not updated. Otherwise,
/// [lastHttpDataRefreshTimePerIsolate] is updated to the current
/// time.
void updateLastHttpDataRefreshTime({bool alreadyRecordingHttp = false}) {
/// [lastHttpDataRefreshTimePerIsolate] is updated to the current VM timeline
/// timestamp for each known isolate.
///
/// Wall-clock time must not be used here: `getHttpProfile`'s `updatedSince`
/// expects the VM timeline clock. A wall-clock value would filter out all
/// subsequent requests.
Future<void> updateLastHttpDataRefreshTime({
bool alreadyRecordingHttp = false,
}) async {
if (!alreadyRecordingHttp) {
final service = serviceConnection.serviceManager.service;
if (service == null) return;
final timestamp = (await service.getVMTimelineMicros()).timestamp!;
for (final isolateId in lastHttpDataRefreshTimePerIsolate.keys.toList()) {
// It's safe to use `DateTime.now()` here since we don't need to worry
// about dropping data between the time the last profile was generated
// by the target application and the time `DateTime.now()` is called
// here.
lastHttpDataRefreshTimePerIsolate[isolateId] =
DateTime.now().microsecondsSinceEpoch;
lastHttpDataRefreshTimePerIsolate[isolateId] = timestamp;
}
}
}
Expand Down Expand Up @@ -202,9 +209,15 @@ class NetworkService {
}

Future<void> clearData() async {
await updateLastSocketDataRefreshTime();
updateLastHttpDataRefreshTime();
await _clearSocketProfile();
await _clearHttpProfile();
try {
await updateLastSocketDataRefreshTime();
await updateLastHttpDataRefreshTime();
await _clearSocketProfile();
await _clearHttpProfile();
} on RPCError catch (e) {
if (!e.isServiceDisposedError) {
rethrow;
}
}
}
Comment thread
muhammadkamel marked this conversation as resolved.
}
8 changes: 6 additions & 2 deletions packages/devtools_app/release_notes/NEXT_RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,12 @@ TODO: Remove this section if there are not any updates.

## Network profiler updates

* Fixed exported response status in HAR files so that they parse as integers
instead of strings. [#9900](https://github.com/flutter/devtools/pull/9900)
* Fixed an issue where the Network tab would stop capturing HTTP requests after
a hot restart. -
[#9856](https://github.com/flutter/devtools/pull/9856)
* Fixed an issue where the Network tab would stop capturing new HTTP requests
after pressing Clear while recording. -
[#9856](https://github.com/flutter/devtools/pull/9856)

## Logging updates

Expand Down
Loading