You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

hist-interval.rs 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. extern crate logging;
  2. use std::time::{Instant, Duration};
  3. use std::thread;
  4. use logging::hist::{Entry, HistLog, nanos};
  5. const N_SECS: u64 = 300;
  6. fn main() {
  7. let start = Instant::now();
  8. let mut a = HistLog::new("test", "a", Duration::from_millis(100));
  9. let mut b = a.clone_with_tag("b");
  10. let mut c = b.clone_with_tag("c");
  11. thread::spawn(move || {
  12. let mut prev = Instant::now();
  13. let mut loop_time = Instant::now();
  14. let mut i = 0;
  15. loop {
  16. prev = loop_time;
  17. loop_time = Instant::now();
  18. a.record(nanos(loop_time - prev));
  19. a.check_send(loop_time);
  20. if loop_time - start > Duration::from_secs(N_SECS) { break }
  21. i += 1;
  22. if i % 100 == 0 { thread::sleep(Duration::new(0, 0)); }
  23. }
  24. });
  25. thread::spawn(move || {
  26. let mut prev = Instant::now();
  27. let mut loop_time = Instant::now();
  28. let mut i = 0;
  29. loop {
  30. prev = loop_time;
  31. loop_time = Instant::now();
  32. b.record(nanos(loop_time - prev));
  33. b.check_send(loop_time);
  34. if loop_time - start > Duration::from_secs(N_SECS) { break }
  35. i += 1;
  36. //if i % 1_000 == 0 { thread::sleep(Duration::new(0, 0)); }
  37. if i % 100 == 0 { thread::sleep(Duration::new(0, 0)); }
  38. }
  39. });
  40. let mut prev = Instant::now();
  41. let mut loop_time = Instant::now();
  42. let mut i = 0;
  43. loop {
  44. prev = loop_time;
  45. loop_time = Instant::now();
  46. c.record(nanos(loop_time - prev));
  47. c.check_send(loop_time);
  48. if loop_time - start > Duration::from_secs(N_SECS) { break }
  49. i += 1;
  50. //if i % 100_000 == 0 { thread::sleep(Duration::from_millis(10)); }
  51. if i % 100 == 0 { thread::sleep(Duration::new(0, 0)); }
  52. }
  53. }