From 359a1568547994401ffbd11af7fcd751e5f8d8b2 Mon Sep 17 00:00:00 2001 From: Derek Xu Date: Tue, 12 Dec 2023 14:19:16 -0500 Subject: [PATCH] Update --- pkgs/http_profile/lib/http_profile.dart | 64 ++++++++++++------------- 1 file changed, 30 insertions(+), 34 deletions(-) diff --git a/pkgs/http_profile/lib/http_profile.dart b/pkgs/http_profile/lib/http_profile.dart index f3adc2a91f..a980d02e7f 100644 --- a/pkgs/http_profile/lib/http_profile.dart +++ b/pkgs/http_profile/lib/http_profile.dart @@ -3,8 +3,9 @@ // BSD-style license that can be found in the LICENSE file. import 'dart:async' show StreamController, StreamSink; -import 'dart:developer' show addHttpClientProfilingData, Timeline; -import 'dart:io'; +import 'dart:developer' show addHttpClientProfilingData, Service, Timeline; +import 'dart:io' show HttpClient, HttpClientResponseCompressionState; +import 'dart:isolate' show Isolate; /// Describes an event related to an HTTP request. final class HttpProfileRequestEvent { @@ -280,27 +281,6 @@ final class HttpClientRequestProfile { final _data = {}; - /// The ID of the isolate the request was issued from. - String? get isolateId => _data['isolateId'] as String?; - set isolateId(String? value) { - _data['isolateId'] = value; - _updated(); - } - - /// The HTTP request method associated with the request. - String? get requestMethod => _data['requestMethod'] as String?; - set requestMethod(String? value) { - _data['requestMethod'] = value; - _updated(); - } - - /// The URI to which the request was sent. - String? get requestUri => _data['requestUri'] as String?; - set requestUri(String? value) { - _data['requestUri'] = value; - _updated(); - } - /// Records an event related to the request. /// /// Usage example: @@ -314,12 +294,6 @@ final class HttpClientRequestProfile { _updated(); } - /// The time at which the request was initiated. - set requestStartTimestamp(DateTime value) { - _data['requestStartTimestamp'] = value.microsecondsSinceEpoch; - _updated(); - } - /// The time at which the request was completed. Note that DevTools will not /// consider the request to be complete until [requestEndTimestamp] is /// non-null. @@ -354,7 +328,16 @@ final class HttpClientRequestProfile { void _updated() => _data['_lastUpdateTime'] = Timeline.now; - HttpClientRequestProfile._() { + HttpClientRequestProfile._({ + required DateTime requestStartTimestamp, + required String requestMethod, + required String requestUri, + }) { + _data['isolateId'] = Service.getIsolateId(Isolate.current)!; + _data['requestStartTimestamp'] = + requestStartTimestamp.microsecondsSinceEpoch; + _data['requestMethod'] = requestMethod; + _data['requestUri'] = requestUri; _data['events'] = >[]; _data['requestData'] = {}; requestData = HttpProfileRequestData._( @@ -366,22 +349,35 @@ final class HttpClientRequestProfile { _data['_responseBodyStream'] = _responseBody.stream; // This entry is needed to support the updatedSince parameter of // ext.dart.io.getHttpProfile. - _data['_lastUpdateTime'] = 0; + _data['_lastUpdateTime'] = Timeline.now; } /// If HTTP profiling is enabled, returns an [HttpClientRequestProfile], /// otherwise returns `null`. - static HttpClientRequestProfile? profile() { + static HttpClientRequestProfile? profile({ + /// The time at which the request was initiated. + required DateTime requestStartTimestamp, + + /// The HTTP request method associated with the request. + required String requestMethod, + + /// The URI to which the request was sent. + required String requestUri, + }) { // Always return `null` in product mode so that the profiling code can be // tree shaken away. if (const bool.fromEnvironment('dart.vm.product') || !profilingEnabled) { return null; } - final requestProfile = HttpClientRequestProfile._(); + final requestProfile = HttpClientRequestProfile._( + requestStartTimestamp: requestStartTimestamp, + requestMethod: requestMethod, + requestUri: requestUri, + ); // This entry is needed to support the id parameter of // ext.dart.io.getHttpProfileRequest. requestProfile._data['id'] = - 'from_package/${addHttpClientProfilingData(requestProfile._data)}'; + addHttpClientProfilingData(requestProfile._data); return requestProfile; } }