From 04777acc92d8abea70e12fb430d65cca16e7d801 Mon Sep 17 00:00:00 2001 From: Brian Quinlan Date: Thu, 2 Nov 2023 12:43:45 -0700 Subject: [PATCH] Add a skeleton "http_profile" package (#1036) --- .github/workflows/dart.yml | 79 +++++++++++++++---- pkgs/http_profile/CHANGELOG.md | 3 + pkgs/http_profile/LICENSE | 27 +++++++ pkgs/http_profile/README.md | 2 + pkgs/http_profile/lib/http_profile.dart | 33 ++++++++ pkgs/http_profile/mono_pkg.yaml | 14 ++++ pkgs/http_profile/pubspec.yaml | 15 ++++ .../test/profiling_enabled_test.dart | 22 ++++++ tool/ci.sh | 2 +- 9 files changed, 179 insertions(+), 18 deletions(-) create mode 100644 pkgs/http_profile/CHANGELOG.md create mode 100644 pkgs/http_profile/LICENSE create mode 100644 pkgs/http_profile/README.md create mode 100644 pkgs/http_profile/lib/http_profile.dart create mode 100644 pkgs/http_profile/mono_pkg.yaml create mode 100644 pkgs/http_profile/pubspec.yaml create mode 100644 pkgs/http_profile/test/profiling_enabled_test.dart diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index b9249217b9..fc4da99ccd 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -1,4 +1,4 @@ -# Created with package:mono_repo v6.5.7 +# Created with package:mono_repo v6.6.0 name: Dart CI on: push: @@ -36,7 +36,7 @@ jobs: name: Checkout repository uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - name: mono_repo self validate - run: dart pub global activate mono_repo 6.5.7 + run: dart pub global activate mono_repo 6.6.0 - name: mono_repo self validate run: dart pub global run mono_repo generate --validate job_002: @@ -70,16 +70,16 @@ jobs: if: "always() && steps.pkgs_http_client_conformance_tests_pub_upgrade.conclusion == 'success'" working-directory: pkgs/http_client_conformance_tests job_003: - name: "analyze_and_format; Dart 3.0.0; PKG: pkgs/http; `dart analyze --fatal-infos`" + name: "analyze_and_format; Dart 3.0.0; PKGS: pkgs/http, pkgs/http_profile; `dart analyze --fatal-infos`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:pkgs/http;commands:analyze" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:pkgs/http-pkgs/http_profile;commands:analyze" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:pkgs/http + os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:pkgs/http-pkgs/http_profile os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest @@ -99,17 +99,26 @@ jobs: run: dart analyze --fatal-infos if: "always() && steps.pkgs_http_pub_upgrade.conclusion == 'success'" working-directory: pkgs/http + - id: pkgs_http_profile_pub_upgrade + name: pkgs/http_profile; dart pub upgrade + run: dart pub upgrade + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: pkgs/http_profile + - name: "pkgs/http_profile; dart analyze --fatal-infos" + run: dart analyze --fatal-infos + if: "always() && steps.pkgs_http_profile_pub_upgrade.conclusion == 'success'" + working-directory: pkgs/http_profile job_004: - name: "analyze_and_format; Dart dev; PKGS: pkgs/http, pkgs/http_client_conformance_tests; `dart analyze --fatal-infos`" + name: "analyze_and_format; Dart dev; PKGS: pkgs/http, pkgs/http_client_conformance_tests, pkgs/http_profile; `dart analyze --fatal-infos`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:pkgs/http-pkgs/http_client_conformance_tests;commands:analyze" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:pkgs/http-pkgs/http_client_conformance_tests-pkgs/http_profile;commands:analyze" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:pkgs/http-pkgs/http_client_conformance_tests + os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:pkgs/http-pkgs/http_client_conformance_tests-pkgs/http_profile os:ubuntu-latest;pub-cache-hosted;sdk:dev os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest @@ -138,17 +147,26 @@ jobs: run: dart analyze --fatal-infos if: "always() && steps.pkgs_http_client_conformance_tests_pub_upgrade.conclusion == 'success'" working-directory: pkgs/http_client_conformance_tests + - id: pkgs_http_profile_pub_upgrade + name: pkgs/http_profile; dart pub upgrade + run: dart pub upgrade + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: pkgs/http_profile + - name: "pkgs/http_profile; dart analyze --fatal-infos" + run: dart analyze --fatal-infos + if: "always() && steps.pkgs_http_profile_pub_upgrade.conclusion == 'success'" + working-directory: pkgs/http_profile job_005: - name: "analyze_and_format; Dart dev; PKGS: pkgs/http, pkgs/http_client_conformance_tests; `dart format --output=none --set-exit-if-changed .`" + name: "analyze_and_format; Dart dev; PKGS: pkgs/http, pkgs/http_client_conformance_tests, pkgs/http_profile; `dart format --output=none --set-exit-if-changed .`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:pkgs/http-pkgs/http_client_conformance_tests;commands:format" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:pkgs/http-pkgs/http_client_conformance_tests-pkgs/http_profile;commands:format" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:pkgs/http-pkgs/http_client_conformance_tests + os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:pkgs/http-pkgs/http_client_conformance_tests-pkgs/http_profile os:ubuntu-latest;pub-cache-hosted;sdk:dev os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest @@ -177,6 +195,15 @@ jobs: run: "dart format --output=none --set-exit-if-changed ." if: "always() && steps.pkgs_http_client_conformance_tests_pub_upgrade.conclusion == 'success'" working-directory: pkgs/http_client_conformance_tests + - id: pkgs_http_profile_pub_upgrade + name: pkgs/http_profile; dart pub upgrade + run: dart pub upgrade + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: pkgs/http_profile + - name: "pkgs/http_profile; dart format --output=none --set-exit-if-changed ." + run: "dart format --output=none --set-exit-if-changed ." + if: "always() && steps.pkgs_http_profile_pub_upgrade.conclusion == 'success'" + working-directory: pkgs/http_profile job_006: name: "unit_test; Dart 3.0.0; PKG: pkgs/http; `dart run --define=no_default_http_client=true test/no_default_http_client_test.dart`" runs-on: ubuntu-latest @@ -250,16 +277,16 @@ jobs: - job_004 - job_005 job_008: - name: "unit_test; Dart 3.0.0; PKG: pkgs/http; `dart test --platform vm`" + name: "unit_test; Dart 3.0.0; PKGS: pkgs/http, pkgs/http_profile; `dart test --platform vm`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:pkgs/http;commands:test_0" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:pkgs/http-pkgs/http_profile;commands:test_0" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:pkgs/http + os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0;packages:pkgs/http-pkgs/http_profile os:ubuntu-latest;pub-cache-hosted;sdk:3.0.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest @@ -279,6 +306,15 @@ jobs: run: dart test --platform vm if: "always() && steps.pkgs_http_pub_upgrade.conclusion == 'success'" working-directory: pkgs/http + - id: pkgs_http_profile_pub_upgrade + name: pkgs/http_profile; dart pub upgrade + run: dart pub upgrade + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: pkgs/http_profile + - name: "pkgs/http_profile; dart test --platform vm" + run: dart test --platform vm + if: "always() && steps.pkgs_http_profile_pub_upgrade.conclusion == 'success'" + working-directory: pkgs/http_profile needs: - job_001 - job_002 @@ -358,16 +394,16 @@ jobs: - job_004 - job_005 job_011: - name: "unit_test; Dart dev; PKG: pkgs/http; `dart test --platform vm`" + name: "unit_test; Dart dev; PKGS: pkgs/http, pkgs/http_profile; `dart test --platform vm`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:pkgs/http;commands:test_0" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:pkgs/http-pkgs/http_profile;commands:test_0" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:pkgs/http + os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:pkgs/http-pkgs/http_profile os:ubuntu-latest;pub-cache-hosted;sdk:dev os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest @@ -387,6 +423,15 @@ jobs: run: dart test --platform vm if: "always() && steps.pkgs_http_pub_upgrade.conclusion == 'success'" working-directory: pkgs/http + - id: pkgs_http_profile_pub_upgrade + name: pkgs/http_profile; dart pub upgrade + run: dart pub upgrade + if: "always() && steps.checkout.conclusion == 'success'" + working-directory: pkgs/http_profile + - name: "pkgs/http_profile; dart test --platform vm" + run: dart test --platform vm + if: "always() && steps.pkgs_http_profile_pub_upgrade.conclusion == 'success'" + working-directory: pkgs/http_profile needs: - job_001 - job_002 diff --git a/pkgs/http_profile/CHANGELOG.md b/pkgs/http_profile/CHANGELOG.md new file mode 100644 index 0000000000..8f2e70fcf2 --- /dev/null +++ b/pkgs/http_profile/CHANGELOG.md @@ -0,0 +1,3 @@ +## 0.0.1 + +* Skeleton class and test definitions. diff --git a/pkgs/http_profile/LICENSE b/pkgs/http_profile/LICENSE new file mode 100644 index 0000000000..baa79ce1d3 --- /dev/null +++ b/pkgs/http_profile/LICENSE @@ -0,0 +1,27 @@ +Copyright 2023, the Dart project authors. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + * Neither the name of Google LLC nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/pkgs/http_profile/README.md b/pkgs/http_profile/README.md new file mode 100644 index 0000000000..1ca1305b76 --- /dev/null +++ b/pkgs/http_profile/README.md @@ -0,0 +1,2 @@ +An **experimental** package that allows HTTP clients outside of the Dart SDK +to integrate with the DevTools Network tab. diff --git a/pkgs/http_profile/lib/http_profile.dart b/pkgs/http_profile/lib/http_profile.dart new file mode 100644 index 0000000000..ea27665fb1 --- /dev/null +++ b/pkgs/http_profile/lib/http_profile.dart @@ -0,0 +1,33 @@ +// Copyright (c) 2023, 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. + +import 'dart:io'; + +/// A record of debugging information about an HTTP request. +final class HttpClientRequestProfile { + /// Whether HTTP profiling is enabled or not. + /// + /// The value can be changed programmatically or through the DevTools Network + /// UX. + static bool get profilingEnabled => HttpClient.enableTimelineLogging; + static set profilingEnabled(bool enabled) => + HttpClient.enableTimelineLogging = enabled; + + String? requestMethod; + String? requestUri; + + HttpClientRequestProfile._(); + + /// If HTTP profiling is enabled, returns + /// a [HttpClientRequestProfile] otherwise returns `null`. + static HttpClientRequestProfile? profile() { + // 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._(); + return requestProfile; + } +} diff --git a/pkgs/http_profile/mono_pkg.yaml b/pkgs/http_profile/mono_pkg.yaml new file mode 100644 index 0000000000..977b336758 --- /dev/null +++ b/pkgs/http_profile/mono_pkg.yaml @@ -0,0 +1,14 @@ +sdk: +- pubspec +- dev + +stages: +- analyze_and_format: + - analyze: --fatal-infos + - format: + sdk: + - dev +- unit_test: + - test: --platform vm + os: + - linux diff --git a/pkgs/http_profile/pubspec.yaml b/pkgs/http_profile/pubspec.yaml new file mode 100644 index 0000000000..9e3b69e12f --- /dev/null +++ b/pkgs/http_profile/pubspec.yaml @@ -0,0 +1,15 @@ +name: http_profile +description: >- + A library used by HTTP client authors to integrate with the DevTools + Network tab. +publish_to: none +repository: https://github.com/dart-lang/http/tree/master/pkgs/http_profile + +environment: + sdk: ^3.0.0 + +dependencies: + test: ^1.24.9 + +dev_dependencies: + dart_flutter_team_lints: ^2.1.1 diff --git a/pkgs/http_profile/test/profiling_enabled_test.dart b/pkgs/http_profile/test/profiling_enabled_test.dart new file mode 100644 index 0000000000..6336da6ee4 --- /dev/null +++ b/pkgs/http_profile/test/profiling_enabled_test.dart @@ -0,0 +1,22 @@ +// Copyright (c) 2023, 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. + +import 'dart:io'; + +import 'package:http_profile/http_profile.dart'; +import 'package:test/test.dart'; + +void main() { + test('profiling enabled', () async { + HttpClientRequestProfile.profilingEnabled = true; + expect(HttpClient.enableTimelineLogging, true); + expect(HttpClientRequestProfile.profile(), isNotNull); + }); + + test('profiling disabled', () async { + HttpClientRequestProfile.profilingEnabled = false; + expect(HttpClient.enableTimelineLogging, false); + expect(HttpClientRequestProfile.profile(), isNull); + }); +} diff --git a/tool/ci.sh b/tool/ci.sh index 91d1c5f752..f9acff8cb0 100755 --- a/tool/ci.sh +++ b/tool/ci.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Created with package:mono_repo v6.5.7 +# Created with package:mono_repo v6.6.0 # Support built in commands on windows out of the box. # When it is a flutter repo (check the pubspec.yaml for "sdk: flutter")