Struct TsDb

Source
pub struct TsDb {
    pub data: HashMap<String, Trace>,
    /* private fields */
}
Expand description

A time series database which can be used as a library. Note that this struct is not usable in multiple threads. To make it accessible from multiple threads, use the TsDbHandle wrapper.

Fields§

§data: HashMap<String, Trace>

Implementations§

Source§

impl TsDb

Database for time series.

Source

pub fn new() -> Self

Examples found in repository?
examples/perf.rs (line 9)
8fn main() {
9    let mut db = TsDb::new();
10
11    insertions(&mut db);
12    do_query(&db);
13}
Source

pub fn into_handle(self) -> TsDbHandle

Source

pub fn add_values(&mut self, name: &str, samples: Vec<Observation<Sample>>)

Add a batch of values

Source

pub fn new_trace(&mut self, name: &str)

Examples found in repository?
examples/perf.rs (line 22)
15fn insertions(db: &mut TsDb) {
16    let num_insertions = 1_000_000;
17    println!(
18        "Created database, now inserting {} data points into a signal.",
19        num_insertions
20    );
21
22    db.new_trace("fu");
23    let t1 = Instant::now();
24    for i in 0..num_insertions {
25        let ts = TimeStamp::new(i as f64);
26        let sample = Sample::new(i as f64);
27        let observation = Observation::new(ts, sample);
28        db.add_value("fu", observation);
29    }
30    let t2 = Instant::now();
31    let time_delta = t2 - t1;
32    let time_delta = time_delta.as_secs_f64();
33
34    println!(
35        "Inserted {} points in {} seconds.",
36        num_insertions, time_delta
37    );
38    let rate = num_insertions as f64 / time_delta;
39    println!("That means {} mega-points per second.", rate / 1.0e6);
40}
Source

pub fn add_value(&mut self, name: &str, observation: Observation<Sample>)

Examples found in repository?
examples/perf.rs (line 28)
15fn insertions(db: &mut TsDb) {
16    let num_insertions = 1_000_000;
17    println!(
18        "Created database, now inserting {} data points into a signal.",
19        num_insertions
20    );
21
22    db.new_trace("fu");
23    let t1 = Instant::now();
24    for i in 0..num_insertions {
25        let ts = TimeStamp::new(i as f64);
26        let sample = Sample::new(i as f64);
27        let observation = Observation::new(ts, sample);
28        db.add_value("fu", observation);
29    }
30    let t2 = Instant::now();
31    let time_delta = t2 - t1;
32    let time_delta = time_delta.as_secs_f64();
33
34    println!(
35        "Inserted {} points in {} seconds.",
36        num_insertions, time_delta
37    );
38    let rate = num_insertions as f64 / time_delta;
39    println!("That means {} mega-points per second.", rate / 1.0e6);
40}
Source

pub fn query(&self, name: &str, query: Query) -> QueryResult

Query the given trace for data.

Examples found in repository?
examples/perf.rs (line 50)
42fn do_query(db: &TsDb) {
43    // Query the data
44    println!("Querying the database!");
45
46    let query = Query::create()
47        .start(TimeStamp::new(0.0))
48        .end(TimeStamp::new(1000.0))
49        .build();
50    let result = db.query("fu", query);
51
52    println!("Got result: {:?}", result.query);
53    println!("Num result: {:?}", result.len());
54    // let raw_samples = result.into_vec();
55    // println!("Raw samples: {}", raw_samples.len());
56}
Source

pub fn summary(&self, name: &str) -> Option<Aggregation<Sample, SampleMetrics>>

Get a summary for the given trace.

Trait Implementations§

Source§

impl Debug for TsDb

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for TsDb

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for TsDb

§

impl !RefUnwindSafe for TsDb

§

impl Send for TsDb

§

impl !Sync for TsDb

§

impl Unpin for TsDb

§

impl UnwindSafe for TsDb

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.