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.

77 lines
2.0KB

  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 = 60 * 60;
  6. fn main() {
  7. let start = Instant::now();
  8. let mut a = HistLog::new("test", "a", Duration::from_millis(1000));
  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. thread::sleep(Duration::new(0, 0));
  24. }
  25. });
  26. thread::spawn(move || {
  27. let mut prev = Instant::now();
  28. let mut loop_time = Instant::now();
  29. let mut i = 0;
  30. loop {
  31. prev = loop_time;
  32. loop_time = Instant::now();
  33. b.record(nanos(loop_time - prev));
  34. b.check_send(loop_time);
  35. if loop_time - start > Duration::from_secs(N_SECS) { break }
  36. i += 1;
  37. //if i % 1_000 == 0 { thread::sleep(Duration::new(0, 0)); }
  38. //if i % 100 == 0 { thread::sleep(Duration::new(0, 0)); }
  39. thread::sleep(Duration::new(0, 0));
  40. }
  41. });
  42. let mut prev = Instant::now();
  43. let mut loop_time = Instant::now();
  44. let mut i = 0;
  45. loop {
  46. prev = loop_time;
  47. loop_time = Instant::now();
  48. c.record(nanos(loop_time - prev));
  49. c.check_send(loop_time);
  50. if loop_time - start > Duration::from_secs(N_SECS) { break }
  51. i += 1;
  52. //if i % 100_000 == 0 { thread::sleep(Duration::from_millis(10)); }
  53. //if i % 100 == 0 { thread::sleep(Duration::new(0, 0)); }
  54. thread::sleep(Duration::new(0, 0));
  55. }
  56. }