I'm thinking to measure time in different parts of several programs in crate (initialization struct, executing etc)
First: I need to pass this struct between programs, how?
Second: for example
//let mut threads = Vec::<chrono::Duration>::with_capacity(N);
if pprint{
//will print last N
(0..N).for_each(|seq_num| { // <---- Closure 1
//access last N in vec
let arc_clone = Arc::clone(&self.0);
let size_vec= arc_clone.lock().unwrap().len();
thread::spawn(move || { // <---- Closure 2
let loc_clone = arc_clone.lock().unwrap();
let cur_loc= loc_clone.get(size_vec- seq_num as usize).unwrap();
let lt = &Local::now();
let next_loc= loc_clone.get(size_vec- seq_num +1 as usize).unwrap_or_else(|| lt);
let utc_time = DateTime::<Utc>::from_utc(next_loc.naive_utc(), Utc);
let dif_locs = next_loc.signed_duration_since(*cur_loc); // difference between locals
println!("Element {} was executed in {:?}\n", size_vec - seq_num, dif_locs);
//threads.push(dif_locs);
});
});
}
If i will uncomment threads- then will be
move occurs because threads
has type std::vec::Vec<chrono::Duration>
, which does not implement the Copy
trait
I saw in somewhat crate this, but forget and can't find the same way now
Also:
let lt = &Local::now();
let next_loc= loc_clone.get(size_vec- seq_num +1 as usize).unwrap_or_else(|| lt);
I create variable lt on stack, but if pass
let next_loc= loc_clone.get(size_vec- seq_num +1 as usize).unwrap_or_else(|| &Local::now(););
or Local::now();
will be problem as temporal value, but i don't create not temporary.
And if you know crates to do the same(maybe also interest in (microcontrollers) embedded rust), will be grateful.
Purpose: simply choose blocks and count time