Skip to content

Commit b78c509

Browse files
authored
Merge pull request #1663 from dart-lang/merge-timing-package
Merge `package:timing`
2 parents 9ab106d + c9dedca commit b78c509

File tree

15 files changed

+1011
-0
lines changed

15 files changed

+1011
-0
lines changed

.github/ISSUE_TEMPLATE/timing.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
name: "package:timing"
3+
about: "Create a bug or file a feature request against package:timing."
4+
labels: "package:timing"
5+
---

.github/labeler.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@
108108
- changed-files:
109109
- any-glob-to-any-file: 'pkgs/sse/**'
110110

111+
'package:timing':
112+
- changed-files:
113+
- any-glob-to-any-file: 'pkgs/timing/**'
114+
111115
'package:unified_analytics':
112116
- changed-files:
113117
- any-glob-to-any-file: 'pkgs/unified_analytics/**'

.github/workflows/timing.yaml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: package:timing
2+
3+
on:
4+
# Run on PRs and pushes to the default branch.
5+
push:
6+
branches: [ main ]
7+
paths:
8+
- '.github/workflows/timing.yaml'
9+
- 'pkgs/timing/**'
10+
pull_request:
11+
branches: [ main ]
12+
paths:
13+
- '.github/workflows/timing.yaml'
14+
- 'pkgs/timing/**'
15+
schedule:
16+
- cron: "0 0 * * 0"
17+
18+
env:
19+
PUB_ENVIRONMENT: bot.github
20+
21+
22+
defaults:
23+
run:
24+
working-directory: pkgs/timing/
25+
26+
jobs:
27+
# Check code formatting and static analysis on a single OS (linux)
28+
# against Dart dev.
29+
analyze:
30+
runs-on: ubuntu-latest
31+
strategy:
32+
fail-fast: false
33+
matrix:
34+
sdk: [3.4, dev]
35+
steps:
36+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
37+
- uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94
38+
with:
39+
sdk: ${{ matrix.sdk }}
40+
- id: install
41+
run: dart pub get
42+
- run: dart format --output=none --set-exit-if-changed .
43+
if: always() && steps.install.outcome == 'success'
44+
- run: dart analyze --fatal-infos
45+
if: always() && steps.install.outcome == 'success'
46+
47+
# Run tests on a matrix consisting of two dimensions:
48+
# 1. OS: ubuntu-latest, (macos-latest, windows-latest)
49+
# 2. release channel: dev, 2.2.0
50+
test:
51+
needs: analyze
52+
runs-on: ${{ matrix.os }}
53+
strategy:
54+
fail-fast: false
55+
matrix:
56+
# Add macos-latest and/or windows-latest if relevant for this package.
57+
os: [ubuntu-latest]
58+
sdk: [3.4, dev]
59+
steps:
60+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
61+
- uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94
62+
with:
63+
sdk: ${{ matrix.sdk }}
64+
- id: install
65+
run: dart pub get
66+
- run: dart test --platform vm
67+
if: always() && steps.install.outcome == 'success'

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ don't naturally belong to other topic monorepos (like
4040
| [source_maps](pkgs/source_maps/) | A library to programmatically manipulate source map files. | [![package issues](https://img.shields.io/badge/package:source_maps-4774bc)](https://github.com/dart-lang/tools/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Asource_maps) | [![pub package](https://img.shields.io/pub/v/source_maps.svg)](https://pub.dev/packages/source_maps) |
4141
| [source_span](pkgs/source_span/) | Provides a standard representation for source code locations and spans. | [![package issues](https://img.shields.io/badge/package:source_span-4774bc)](https://github.com/dart-lang/tools/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Asource_span) | [![pub package](https://img.shields.io/pub/v/source_span.svg)](https://pub.dev/packages/source_span) |
4242
| [sse](pkgs/sse/) | Provides client and server functionality for setting up bi-directional communication through Server Sent Events (SSE) and corresponding POST requests. | [![package issues](https://img.shields.io/badge/package:sse-4774bc)](https://github.com/dart-lang/tools/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Asse) | [![pub package](https://img.shields.io/pub/v/sse.svg)](https://pub.dev/packages/sse) |
43+
| [timing](pkgs/timing/) | A simple package for tracking the performance of synchronous and asynchronous actions. | [![package issues](https://img.shields.io/badge/package:timing-4774bc)](https://github.com/dart-lang/tools/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Atiming) | [![pub package](https://img.shields.io/pub/v/timing.svg)](https://pub.dev/packages/timing) |
4344
| [unified_analytics](pkgs/unified_analytics/) | A package for logging analytics for all Dart and Flutter related tooling to Google Analytics. | [![package issues](https://img.shields.io/badge/package:unified_analytics-4774bc)](https://github.com/dart-lang/tools/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Aunified_analytics) | [![pub package](https://img.shields.io/pub/v/unified_analytics.svg)](https://pub.dev/packages/unified_analytics) |
4445

4546
## Publishing automation

pkgs/timing/.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.packages
2+
/build/
3+
pubspec.lock
4+
5+
# Files generated by dart tools
6+
.dart_tool
7+
doc/

pkgs/timing/CHANGELOG.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
## 1.0.2
2+
3+
- Require Dart `3.4`.
4+
- Move to `dart-lang/tools` monorepo.
5+
6+
## 1.0.1
7+
8+
- Require Dart `2.14`.
9+
10+
## 1.0.0
11+
12+
- Enable null safety.
13+
- Require Dart `2.12`.
14+
15+
## 0.1.1+3
16+
17+
- Allow `package:json_annotation` `'>=1.0.0 <5.0.0'`.
18+
19+
## 0.1.1+2
20+
21+
- Support the latest version of `package:json_annotation`.
22+
- Require Dart 2.2 or later.
23+
24+
## 0.1.1+1
25+
26+
- Support the latest version of `package:json_annotation`.
27+
28+
## 0.1.1
29+
30+
- Add JSON serialization
31+
32+
## 0.1.0
33+
34+
- Initial release

pkgs/timing/LICENSE

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Copyright 2018, the Dart project authors.
2+
3+
Redistribution and use in source and binary forms, with or without
4+
modification, are permitted provided that the following conditions are
5+
met:
6+
7+
* Redistributions of source code must retain the above copyright
8+
notice, this list of conditions and the following disclaimer.
9+
* Redistributions in binary form must reproduce the above
10+
copyright notice, this list of conditions and the following
11+
disclaimer in the documentation and/or other materials provided
12+
with the distribution.
13+
* Neither the name of Google LLC nor the names of its
14+
contributors may be used to endorse or promote products derived
15+
from this software without specific prior written permission.
16+
17+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

pkgs/timing/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
[![Build Status](https://github.com/dart-lang/tools/actions/workflows/timing.yaml/badge.svg)](https://github.com/dart-lang/tools/actions/workflows/timing.yaml)
2+
[![pub package](https://img.shields.io/pub/v/timing.svg)](https://pub.dev/packages/timing)
3+
[![package publisher](https://img.shields.io/pub/publisher/timing.svg)](https://pub.dev/packages/timing/publisher)
4+
5+
Timing is a simple package for tracking performance of both async and sync actions
6+
7+
## Usage
8+
9+
```dart
10+
var tracker = AsyncTimeTracker();
11+
await tracker.track(() async {
12+
// some async code here
13+
});
14+
15+
// Use results
16+
print('${tracker.duration} ${tracker.innerDuration} ${tracker.slices}');
17+
```
18+
19+
## Building
20+
21+
Use the following command to re-generate `lib/src/timing.g.dart` file:
22+
23+
```bash
24+
dart pub run build_runner build
25+
```
26+
27+
## Publishing automation
28+
29+
For information about our publishing automation and release process, see
30+
https://github.com/dart-lang/ecosystem/wiki/Publishing-automation.

pkgs/timing/analysis_options.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# https://dart.dev/tools/analysis#the-analysis-options-file
2+
include: package:dart_flutter_team_lints/analysis_options.yaml

pkgs/timing/lib/src/clock.dart

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'dart:async';
6+
7+
/// A function that returns the current [DateTime].
8+
typedef _Clock = DateTime Function();
9+
DateTime _defaultClock() => DateTime.now();
10+
11+
const _zoneKey = #timing_Clock;
12+
13+
/// Returns the current [DateTime].
14+
///
15+
/// May be overridden for tests using [scopeClock].
16+
DateTime now() => (Zone.current[_zoneKey] as _Clock? ?? _defaultClock)();
17+
18+
/// Runs [f], with [clock] scoped whenever [now] is called.
19+
T scopeClock<T>(DateTime Function() clock, T Function() f) =>
20+
runZoned(f, zoneValues: {_zoneKey: clock});

0 commit comments

Comments
 (0)