()
| 15 | |
| 16 | #[tokio::main(flavor = "current_thread")] |
| 17 | async fn main() { |
| 18 | tracing_subscriber::fmt() |
| 19 | .with_env_filter(EnvFilter::from_default_env()) |
| 20 | .init(); |
| 21 | |
| 22 | println!("Lets get PHC samples!"); |
| 23 | let (phc_sender, phc_receiver) = async_ring_buffer::create(1); |
| 24 | |
| 25 | let daemon_info = DaemonInfo { |
| 26 | major_version: 2, |
| 27 | minor_version: 100, |
| 28 | startup_id: rng().next_u64(), |
| 29 | }; |
| 30 | |
| 31 | let mut sourceio = SourceIO::construct(Arc::new(SelectedClockSource::default()), daemon_info); |
| 32 | sourceio.create_phc(phc_sender).await; |
| 33 | sourceio.spawn_all(); |
| 34 | |
| 35 | let max_events_to_receive = 11; |
| 36 | let mut total_polling_duration = time::Duration::from_secs(0); |
| 37 | let mut num_events_received = 0; |
| 38 | let mut start = time::Instant::now(); |
| 39 | |
| 40 | for i in 0..max_events_to_receive { |
| 41 | // PHC events are expected to be received periodically. |
| 42 | // Use a timeout() to prevent the runner from running forever if there happens |
| 43 | // to be an issue with the PHC or there is a bug that prevents events from |
| 44 | // being sent to us. |
| 45 | let phc_event = timeout(Duration::from_secs(5), phc_receiver.recv()) |
| 46 | .await |
| 47 | .unwrap(); |
| 48 | let now = time::Instant::now(); |
| 49 | let duration = now - start; |
| 50 | println!( |
| 51 | "PHC event received.\n{phc_event:#?}\n{:?} msec", |
| 52 | duration.as_millis() |
| 53 | ); |
| 54 | |
| 55 | // Skip the first sample, the IO runner will poll immediately after it's created. |
| 56 | if i > 0 { |
| 57 | total_polling_duration += duration; |
| 58 | num_events_received += 1; |
| 59 | } |
| 60 | |
| 61 | start = now; |
| 62 | } |
| 63 | |
| 64 | let expected_poll_interval_duration = time::Duration::from_millis(500); |
| 65 | println!("Expected poll interval duration: {expected_poll_interval_duration:?}"); |
| 66 | |
| 67 | let actual_poll_interval_duration = total_polling_duration / num_events_received; |
| 68 | println!("Actual poll interval duration (i.e. measured): {actual_poll_interval_duration:?}"); |
| 69 | |
| 70 | let poll_interval_duration_margin_of_error_allowed = time::Duration::from_millis(30); |
| 71 | println!( |
| 72 | "Margin of error allowed for poll interval duration: {poll_interval_duration_margin_of_error_allowed:?}" |
| 73 | ); |
| 74 |
nothing calls this directly
no test coverage detected