Skip to content

Commit c0650ed

Browse files
authored
Merge pull request #67 from metrics-rs/clean-up-api
Bunch of API cleanup.
2 parents fbf383a + ffecdc3 commit c0650ed

File tree

7 files changed

+88
-167
lines changed

7 files changed

+88
-167
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ jobs:
9999
uses: actions-rs/cargo@v1
100100
with:
101101
command: doc
102-
args: --all-features --workspace --exclude=metrics-observer --no-deps
102+
args: --all-features --workspace --no-deps
103103
bench:
104104
name: Bench ${{ matrix.os }}
105105
runs-on: ${{ matrix.os }}
@@ -126,5 +126,5 @@ jobs:
126126
alert-threshold: '10%'
127127
comment-on-alert: true
128128
fail-on-alert: true
129-
alert-comment-cc-users: '@metrics-rs/maintainers'
129+
alert-comment-cc-users: '@tobz'
130130
auto-push: ${{ github.ref == 'refs/heads/main' }}

CHANGELOG.md

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,72 +9,84 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
99
## [Unreleased] - ReleaseDate
1010

1111
### Changed
12+
1213
- Documentation has been updated to reflect that `quanta` does not track time across system
1314
suspends.
14-
- Updated the calibration logic to add an offset to the reference base time that is used to scale
15-
source measurements in TSC mode. Simply put, the "synchronization" -- how close `Clock::now` is
16-
to the underlying monotonic clock, if you called both at the very same moment -- has been improved
17-
by a substantial amount on average.
1815
- Fixed a panic in the calibration loop if a certain edge case with TSC measurements is encountered.
16+
- Updated a unit test that was frequently flaky to be more precise.
1917

2018
### Removed
19+
2120
- `Instant::as_u64` has been removed. As it provided direct access to an value that could
2221
fundamentally change from version-to-version, it felt like time to remove that footgun and push
2322
users more towards the API that mimics `std::time`.
2423
- `Clock::upkeep` has been removed. It doesn't need to exist on `Clock` directly, as we have had
2524
the `quanta::set_recent` free function for a while now, and was just duplicating that.
25+
- `Clock::start` and `Clock::end` have been removed. They saw limited usage and overall just added somewhat needless API
26+
clutter given that users who are looking to do ultra-precise timing will either want more control or use another
27+
technique such as instruction counting.
2628

2729
## [0.9.3] - 2021-09-16
2830

2931
### Added
32+
3033
- CI tests for MIPS/ARM. ([#55](https://github.com/metrics-rs/quanta/pull/55))
3134

3235
### Changed
36+
3337
- Fixed compilation issue with `Mock` on MIPS/ARM. ([#55](https://github.com/metrics-rs/quanta/pull/55))
3438
- Simplified how TSC/RDTSC suppoort is detected, which should avoid some situations where it was
3539
assumed to be present, but actually was not. ([#57](https://github.com/metrics-rs/quanta/pull/57))
3640

3741
## [0.9.2] - 2021-08-25
3842

3943
### Changed
44+
4045
- Pinned `crossbeam-utils` to `v0.8.5` where `AtomicCell::fetch_update` was introduced to fix, which
4146
fixes broken builds where Cargo chooses a version between `0.8.0` and `0.8.5`.
4247
- Update `raw-cpuid` to `10.2` and `average` to `0.13`.
4348

4449
## [0.9.1] - 2021-08-12
4550

4651
### Changed
52+
4753
- Switched from `atomic-shim` to `crossbeam-utils` for better cross-platform atomic support. ([#52](https://github.com/metrics-rs/quanta/pull/52))
4854

4955
## [0.9.0] - 2021-06-17
5056

5157
### Added
58+
5259
- Support for WASM/WASI targets. ([#45](https://github.com/metrics-rs/quanta/pull/45))
5360

5461
## [0.8.0] - 2021-06-07
5562

5663
### Removed
64+
5765
- `Instant::as_unix_duration` as it was added in error.
5866
- `metrics` feature flag as `metrics-core` is no longer a relevant crate.
5967

6068
## [0.7.2] - 2021-01-25
6169
### Changed
70+
6271
- Bumped dependency on `raw-cpuid` to `9.0` in order to deal with a [RustSec
6372
advisory](https://rustsec.org/advisories/RUSTSEC-2021-0013).
6473

6574
## [0.7.1] - 2021-01-24
6675
### Fixed
76+
6777
- Incorrect method visibility for non-SSE2 implementation of `Counter`.
6878
([#38](https://github.com/metrics-rs/quanta/issues/38))
6979

7080
## [0.7.0] - 2021-01-03
7181
### Changed
82+
7283
- MSRV bumped to 1.45.0.
7384
- `Clock::now` takes `&self` instead of `&mut self`.
7485
- Fixed a bug where a failure to spawn the upkeep thread would not allow subsequent attempts to
7586
spawn the upkeep thread to proceed.
7687

7788
### Added
89+
7890
- New methods --`Instant::now` and `Instant::recent` for getting the current and recent time,
7991
respectively.
8092
- New free function `quanta::with_clock` for setting an override on the current thread that affects
@@ -84,36 +96,43 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
8496

8597
## [0.6.5] - 2020-09-16
8698
### Changed
99+
87100
- Fixed a bug with not being able to start the upkeep thread at all.
88101
([#29](https://github.com/metrics-rs/quanta/issues/29))
89102

90103
## [0.6.4] - 2020-08-27
91104
### Added
105+
92106
- Add `Instant::as_unix_duration` to get the duration of time since the Unix epoch from an
93107
`Instant`.
94108
### Changed
95109
- Remove `clocksource` from dependencies and tests as it no longer compiles on stable or nightly.
96110

97111
## [0.6.3] - 2020-08-03
98112
### Changed
113+
99114
- Publicly expose `Clock::upkeep` for advanced use cases.
100115
- Relax constraints around checking for multiple sockets.
101116
([#25](https://github.com/metrics-rs/quanta/issues/25))
102117

103118
## [0.6.2] - 2020-07-20
104119
### Added
120+
105121
- Add support for MIPS/PowerPC. ([#23](https://github.com/metrics-rs/quanta/pull/23))
106122

107123
## [0.6.1] - 2020-07-13
108124
### Added
125+
109126
- Publicly expose the `Error` type returned by `Upkeep::start`.
110127

111128
## [0.6.0] - 2020-07-06
129+
112130
This version of `quanta` was a massive overhaul of man areas of the API and internals, which was
113131
done in a single PR: ([#19](https://github.com/metrics-rs/quanta/pull/19)). You can read the PR
114132
description for the finer details. All changes below are part of the aforementioned PR.
115133

116134
### Changed
135+
117136
- `Clock::now` now returns a monotonic value in all cases.
118137
- No longer possible to get a negative value from `Clock::delta`.
119138
- Calibration is no longer a fixed one second loop, and will complete when it detects it has a
@@ -124,15 +143,18 @@ description for the finer details. All changes below are part of the aforementi
124143

125144
## [0.5.2] - 2020-05-01
126145
### Changed
146+
127147
- Fix the logic to figure out when calibration is required.
128148
([#14](https://github.com/metrics-rs/quanta/pull/14))
129149

130150
## [0.5.1] - 2020-04-11
131151
### Changed
152+
132153
- Small tweak to the docs.
133154

134155
## [0.5.0] - 2020-04-11
135156
### Changed
157+
136158
- Switch to `mach` for macOS/iOS as it was deprecated in `libc`.
137159
([#12](https://github.com/metrics-rs/quanta/pull/12))
138160
- Switch to `core::arch` for instrinics, and drop the feature flagged configuration to use it.
@@ -141,15 +163,18 @@ description for the finer details. All changes below are part of the aforementi
141163

142164
## [0.4.0] - 2020-02-20
143165
### Changed
166+
144167
- Differentiate between raw and scaled time by adding a new `Instant` type.
145168
([#10](https://github.com/metrics-rs/quanta/pull/10))
146169

147170
## [0.2.0] - 2019-03-10
148171
### Changed
172+
149173
- Fixed support for Windows. It was in a bad way, but actually works correctly now!
150174
- Switched to Azure Pipelines CI + Cirrus CI, including formatting, tests, and benchmarks, for
151175
Linux, macOS, Windows, and FreeBSD.
152176

153177
## [0.1.0] - 2019-01-14
154178
### Added
179+
155180
- Initial commit.

benches/timing.rs

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,6 @@ fn time_quanta_raw_scaled(b: &mut Bencher) {
2626
b.iter(|| clock.scaled(clock.raw()))
2727
}
2828

29-
fn time_quanta_start(b: &mut Bencher) {
30-
let clock = Clock::new();
31-
b.iter(|| clock.start())
32-
}
33-
34-
fn time_quanta_start_scaled(b: &mut Bencher) {
35-
let clock = Clock::new();
36-
b.iter(|| clock.scaled(clock.start()))
37-
}
38-
39-
fn time_quanta_end(b: &mut Bencher) {
40-
let clock = Clock::new();
41-
b.iter(|| clock.end())
42-
}
43-
44-
fn time_quanta_end_scaled(b: &mut Bencher) {
45-
let clock = Clock::new();
46-
b.iter(|| clock.scaled(clock.end()))
47-
}
48-
4929
fn time_instant_delta(b: &mut Bencher) {
5030
b.iter(|| {
5131
let start = StdInstant::now();
@@ -72,15 +52,6 @@ fn time_quanta_now_delta(b: &mut Bencher) {
7252
})
7353
}
7454

75-
fn time_quanta_start_end_delta(b: &mut Bencher) {
76-
let clock = Clock::new();
77-
b.iter(|| {
78-
let start = clock.start();
79-
let end = clock.end();
80-
clock.delta(start, end)
81-
})
82-
}
83-
8455
fn time_quanta_recent(b: &mut Bencher) {
8556
let clock = Clock::new();
8657
b.iter(|| clock.recent())
@@ -104,11 +75,6 @@ fn benchmark(c: &mut Criterion) {
10475
q_group.bench_function("quanta_raw", time_quanta_raw);
10576
q_group.bench_function("quanta_raw_scaled", time_quanta_raw_scaled);
10677
q_group.bench_function("quanta_raw_delta", time_quanta_raw_delta);
107-
q_group.bench_function("quanta_start", time_quanta_start);
108-
q_group.bench_function("quanta_start_scaled", time_quanta_start_scaled);
109-
q_group.bench_function("quanta_end", time_quanta_end);
110-
q_group.bench_function("quanta_end_scaled", time_quanta_end_scaled);
111-
q_group.bench_function("quanta_start/end_delta", time_quanta_start_end_delta);
11278
q_group.bench_function("quanta_recent", time_quanta_recent);
11379
q_group.bench_function("quanta_instant_recent", time_quanta_instant_recent);
11480
q_group.finish();

src/clocks/counter.rs

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,13 @@
11
#[cfg(all(target_arch = "x86_64", target_feature = "sse2"))]
2-
use core::arch::x86_64::{__rdtscp, _mm_lfence, _rdtsc};
2+
use core::arch::x86_64::_rdtsc;
33

44
#[derive(Clone, Debug, Default)]
55
pub struct Counter;
66

77
#[cfg(all(target_arch = "x86_64", target_feature = "sse2"))]
88
impl Counter {
99
pub fn now(&self) -> u64 {
10-
unsafe {
11-
//_mm_lfence();
12-
_rdtsc()
13-
}
14-
}
15-
16-
pub fn start(&self) -> u64 {
17-
unsafe {
18-
_mm_lfence();
19-
let result = _rdtsc();
20-
_mm_lfence();
21-
result
22-
}
23-
}
24-
25-
pub fn end(&self) -> u64 {
26-
let mut aux: u32 = 0;
27-
unsafe {
28-
let result = __rdtscp(&mut aux as *mut _);
29-
_mm_lfence();
30-
result
31-
}
10+
unsafe { _rdtsc() }
3211
}
3312
}
3413

@@ -37,12 +16,4 @@ impl Counter {
3716
pub fn now(&self) -> u64 {
3817
panic!("can't use counter without TSC support");
3918
}
40-
41-
pub fn start(&self) -> u64 {
42-
panic!("can't use counter without TSC support");
43-
}
44-
45-
pub fn end(&self) -> u64 {
46-
panic!("can't use counter without TSC support");
47-
}
4819
}

src/clocks/monotonic/unix.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ impl Monotonic {
1414

1515
// LINT JUSTIFICATION:
1616
//
17-
// We really don't ever except to actually _get_ negative values from `clock_gettime`, but
17+
// We really don't ever expect to actually _get_ negative values from `clock_gettime`, but
1818
// given the types, it's technically possible. This is due to the fact that `tv_sec` is
1919
// supposed to be `time_t`, which Unix/POSIX-compliant systems implement as a signed number.
2020
// Accordingly, `tv_nsec` follows suit using a signed number.
2121
//
2222
// Given the adjustments made by NTP to clocks like CLOCK_MONOTONIC, and that
2323
// CLOCK_MONOTONIC can be anchored to an arbitrary point, and a whole skew of other
24-
// scenarios where it could be modified... it's technicaly possibler to get back valid
24+
// scenarios where it could be modified... it's technicaly possible to get back valid
2525
// negative values. If we did math between `timespec` objects, the delta should be valid,
2626
// even with negative numbers.
2727
//

src/clocks/monotonic/wasm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ impl Monotonic {
1212
.performance()
1313
.expect(WASM_MISSING_WINDOW_PERF)
1414
.now();
15-
// window.performance.now returns the time in milliseconds
15+
// `window.performance.now()` returns the time in milliseconds.
1616
return f64::trunc(now * 1000.0) as u64;
1717
}
1818
}

0 commit comments

Comments
 (0)