timing/
timing.rs

1// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2// SPDX-License-Identifier: Apache-2.0
3use chrono::prelude::DateTime;
4use chrono::Utc;
5use clock_bound_c::ClockBoundClient;
6use std::env;
7
8fn foo() -> fn() -> i32 {
9    move || return 1
10}
11
12fn main() {
13    let args: Vec<String> = env::args().collect();
14    let clock_bound_d_socket = &args[1];
15
16    let client =
17        match ClockBoundClient::new_with_path(std::path::PathBuf::from(clock_bound_d_socket)) {
18            Ok(client) => client,
19            Err(e) => {
20                println!("Could not create client: {}", e);
21                return;
22            }
23        };
24
25    let (response, _result) = match client.timing(foo()) {
26        Ok((response, result)) => (response, result),
27        Err((e, _res)) => {
28            println!("Could not complete timing request: {}", e);
29            return;
30        }
31    };
32
33    let datetime_earliest: DateTime<Utc> = response.earliest_start.into();
34    let datetime_latest: DateTime<Utc> = response.latest_finish.into();
35    let datetime_str_earliest = datetime_earliest.format("%Y-%m-%d %H:%M:%S.%f").to_string();
36    let datetime_str_latest = datetime_latest.format("%Y-%m-%d %H:%M:%S.%f").to_string();
37
38    println!(
39        "Earliest start time for the timing request: {:?}", datetime_str_earliest
40    );
41    println!(
42        "Latest finish time for the timing request: {:?}", datetime_str_latest
43    );
44    println!(
45        "Minimum execution duration of timing request: {:?}", response.min_execution_time
46    );
47    println!(
48        "Maximum execution duration of timing request: {:?}", response.max_execution_time
49    )
50}