forked from risingwavelabs/risingwave
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Add time for each slt record in simulation test (risingwavelab…
- Loading branch information
1 parent
ea72ed7
commit 3e8ce31
Showing
6 changed files
with
119 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright 2023 RisingWave Labs | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
mod assert_result; | ||
pub use assert_result::*; | ||
|
||
mod timed_future; | ||
pub use timed_future::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// Copyright 2023 RisingWave Labs | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
use std::future::Future; | ||
use std::pin::{pin, Pin}; | ||
use std::task::{Context, Poll}; | ||
use std::time::{Duration, Instant}; | ||
|
||
use pin_project::pin_project; | ||
|
||
/// Inspired by https://stackoverflow.com/a/59935743/2990323 | ||
/// A wrapper around a Future which adds timing data. | ||
#[pin_project] | ||
pub struct Timed<Fut, F> | ||
where | ||
Fut: Future, | ||
F: Fn(&Fut::Output, Duration), | ||
{ | ||
#[pin] | ||
inner: Fut, | ||
f: F, | ||
start: Option<Instant>, | ||
} | ||
|
||
impl<Fut, F> Future for Timed<Fut, F> | ||
where | ||
Fut: Future, | ||
F: Fn(&Fut::Output, Duration), | ||
{ | ||
type Output = Fut::Output; | ||
|
||
fn poll(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> { | ||
let this = self.project(); | ||
let start = this.start.get_or_insert_with(Instant::now); | ||
|
||
match this.inner.poll(cx) { | ||
// If the inner future is still pending, this wrapper is still pending. | ||
Poll::Pending => Poll::Pending, | ||
|
||
// If the inner future is done, measure the elapsed time and finish this wrapper future. | ||
Poll::Ready(v) => { | ||
let elapsed = start.elapsed(); | ||
(this.f)(&v, elapsed); | ||
|
||
Poll::Ready(v) | ||
} | ||
} | ||
} | ||
} | ||
|
||
pub trait TimedExt: Sized + Future { | ||
fn timed<F>(self, f: F) -> Timed<Self, F> | ||
where | ||
F: Fn(&Self::Output, Duration), | ||
{ | ||
Timed { | ||
inner: self, | ||
f, | ||
start: None, | ||
} | ||
} | ||
} | ||
|
||
// All futures can use the `.timed` method defined above | ||
impl<F: Future> TimedExt for F {} |