dart-sdk/sdk/lib/developer/http_profiling.dart
Derek Xu 628d744391 [dart:developer][VM/Service] Add APIs to dart:developer for recording HTTP profiling information, and for later retrieving that information
The APIs mentioned above are `addHttpClientProfilingData` and
`getHttpClientProfilingData`.

This CL also makes it so that profiling information recorded using
`addHttpClientProfilingData` is included in dart:io service extension
responses.

TEST= pkg/vm_service/test/get_http_profile_test.dart

Change-Id: I892a7a8485369bb92cbb0c086b93498bcec25d5f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/341440
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Derek Xu <derekx@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
Reviewed-by: Leaf Petersen <leafp@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
2024-02-15 18:56:08 +00:00

29 lines
1.2 KiB
Dart

// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
part of dart.developer;
// package:http_profile adds HTTP profiling information to this list by using
// the [addHttpClientProfilingData] API below.
List<Map<String, dynamic>> _developerProfilingData = <Map<String, dynamic>>[];
/// Records the data associated with an HTTP request for profiling purposes.
///
/// This function should never be called directly. Instead, use
/// [package:http_profile](https://pub.dev/packages/http_profile).
@Since('3.4')
void addHttpClientProfilingData(Map<String, dynamic> requestProfile) {
_developerProfilingData.add(requestProfile);
requestProfile['id'] = 'from_package/${_developerProfilingData.length}';
}
/// Returns the data added through [addHttpClientProfilingData].
///
/// This function is only meant for use by networking profilers and the format
/// of the returned data may change over time.
@Since('3.4')
List<Map<String, dynamic>> getHttpClientProfilingData() {
return UnmodifiableListView(_developerProfilingData);
}