1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/// # Game-oriented Metrics Collection
///
/// This library leverages `hdrhistogram` and `crossbeam-channel` to allow collecting non-blocking
/// timing metrics. This library is geared towards the specific needs of measuring metrics in a game-specific
/// context; meaning span metrics and frame metrics; although many better libraries exist, these are
/// all mainly geared towards web, server and async contexts.
///
/// The `disable` feature exists to disable the system at compile time.
///
/// # Example
/// ```
/// use game_metrics::{scope, instrument, Metrics};
///use std::time::Duration;
///
///#[instrument]
///fn long() {
///    std::thread::sleep(Duration::from_millis(500));
///}
///
///#[instrument]
///fn short() {
///    std::thread::sleep(Duration::from_millis(50));
///}
///
///
///fn long_scoped() {
///    scope!("long_scoped");
///    std::thread::sleep(Duration::from_millis(500));
///}
///
///
///fn short_scoped() {
///    scope!("short_scoped");
///    std::thread::sleep(Duration::from_millis(50));
///}
///
///
///let metrics = Metrics::new(1);
///
///let t1 =  std::thread::spawn(|| {
///    (0..10).for_each(|_| long_scoped());
///    (0..10).for_each(|_| long());
///    (0..10).for_each(|_| short_scoped());
///    (0..10).for_each(|_| short());
///});
///
///let t2 =  std::thread::spawn(|| {
///    (0..10).for_each(|_| long_scoped());
///    (0..10).for_each(|_| long());
///    (0..10).for_each(|_| short_scoped());
///    (0..10).for_each(|_| short());
///});
///
///t1.join().unwrap();
///t2.join().unwrap();
///
///metrics.for_each_histogram(|span_name, h| {
///    println!("{} -> {:.2}ms", span_name, h.mean() / 1_000_000.0);
///});
///
/// ```


#[cfg(feature = "metrics")]
mod metrics;

#[cfg(feature = "metrics")]
pub use metrics::{Event, Metrics, Span};

#[cfg(feature = "metrics")]
pub use game_metrics_macro::instrument;

#[cfg(feature = "logging")]
mod logging;

#[cfg(feature = "logging")]
pub use logging::{Logger, Settings as LoggerSettings};

#[cfg(feature = "logging")]
pub use log::Level as LogLevel;