mirror of
https://github.com/scottlamb/moonfire-nvr.git
synced 2025-12-02 22:20:43 -05:00
compile with stable Rust
The benchmarks now require "cargo bench --features=nightly". The extra #[cfg(nightly)] switches in the code needed for it are a bit annoying; I may move the benches to a separate directory to avoid this. But for now, this works.
This commit is contained in:
14
src/db.rs
14
src/db.rs
@@ -51,11 +51,7 @@
|
||||
//! * the `Transaction` interface allows callers to batch write operations to reduce latency and
|
||||
//! SSD write samples.
|
||||
|
||||
// Suppress false positive warnings caused by using the word SQLite in a docstring.
|
||||
// clippy thinks this is an identifier which should be enclosed in backticks.
|
||||
#![allow(doc_markdown)]
|
||||
|
||||
use error::Error;
|
||||
use error::{Error, ResultExt};
|
||||
use fnv;
|
||||
use lru_cache::LruCache;
|
||||
use openssl::crypto::hash;
|
||||
@@ -999,12 +995,12 @@ impl Database {
|
||||
}));
|
||||
{
|
||||
let mut l = &mut *db.0.lock().unwrap();
|
||||
l.init_video_sample_entries().map_err(Error::annotator("init_video_sample_entries"))?;
|
||||
l.init_cameras().map_err(Error::annotator("init_cameras"))?;
|
||||
l.init_video_sample_entries().annotate_err("init_video_sample_entries")?;
|
||||
l.init_cameras().annotate_err("init_cameras")?;
|
||||
for (&camera_id, ref mut camera) in &mut l.state.cameras_by_id {
|
||||
// TODO: we could use one thread per camera if we had multiple db conns.
|
||||
init_recordings(&mut l.conn, camera_id, camera)
|
||||
.map_err(Error::annotator("init_recordings"))?;
|
||||
.annotate_err("init_recordings")?;
|
||||
}
|
||||
}
|
||||
Ok(db)
|
||||
@@ -1024,8 +1020,6 @@ impl Database {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
extern crate test;
|
||||
|
||||
use core::cmp::Ord;
|
||||
use recording::{self, TIME_UNITS_PER_SEC};
|
||||
use rusqlite::Connection;
|
||||
|
||||
17
src/error.rs
17
src/error.rs
@@ -55,11 +55,20 @@ impl Error {
|
||||
pub fn new(description: String) -> Self {
|
||||
Error{description: description, cause: None }
|
||||
}
|
||||
}
|
||||
|
||||
// Returns a function to pass to std::result::Result::map_err which annotates the given error
|
||||
// with a prefix.
|
||||
pub fn annotator(prefix: &'static str) -> impl Fn(Error) -> Error {
|
||||
move |e| { Error{description: format!("{}: {}", prefix, e.description), cause: e.cause} }
|
||||
pub trait ResultExt<T> {
|
||||
/// Returns a new `Result` like this one except that errors are of type `Error` and annotated
|
||||
/// with the given prefix.
|
||||
fn annotate_err(self, prefix: &'static str) -> Result<T>;
|
||||
}
|
||||
|
||||
impl<T, E> ResultExt<T> for result::Result<T, E> where E: 'static + error::Error + Send + Sync {
|
||||
fn annotate_err(self, prefix: &'static str) -> Result<T> {
|
||||
self.map_err(|e| Error{
|
||||
description: format!("{}: {}", prefix, e.description()),
|
||||
cause: Some(Box::new(e)),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,9 +28,7 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#![cfg_attr(test, feature(test))]
|
||||
#![feature(conservative_impl_trait, plugin, proc_macro)]
|
||||
#![plugin(clippy)]
|
||||
#![cfg_attr(all(nightly, test), feature(test))]
|
||||
|
||||
extern crate byteorder;
|
||||
extern crate core;
|
||||
|
||||
19
src/mp4.rs
19
src/mp4.rs
@@ -1175,19 +1175,22 @@ impl resource::Resource for Mp4File {
|
||||
/// to verify the output is byte-for-byte as expected.
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
extern crate test;
|
||||
#[cfg(nightly)] extern crate test;
|
||||
|
||||
use byteorder::{BigEndian, ByteOrder};
|
||||
use db;
|
||||
use dir;
|
||||
use ffmpeg;
|
||||
use hyper::{self, header};
|
||||
#[cfg(nightly)] use hyper;
|
||||
use hyper::header;
|
||||
use openssl::crypto::hash;
|
||||
use recording::{self, TIME_UNITS_PER_SEC};
|
||||
use resource::{self, Resource};
|
||||
use self::test::Bencher;
|
||||
#[cfg(nightly)] use self::test::Bencher;
|
||||
use std::fs;
|
||||
use std::io;
|
||||
use std::mem;
|
||||
use std::ops::Range;
|
||||
use std::path::Path;
|
||||
use std::sync::Arc;
|
||||
use std::str;
|
||||
@@ -1195,7 +1198,7 @@ mod tests {
|
||||
use super::*;
|
||||
use stream::{self, Opener, Stream};
|
||||
use testutil::{self, TestDb};
|
||||
use uuid::Uuid;
|
||||
#[cfg(nightly)] use uuid::Uuid;
|
||||
|
||||
/// A wrapper around openssl's SHA-1 hashing that implements the `Write` trait.
|
||||
struct Sha1(hash::Hasher);
|
||||
@@ -1305,7 +1308,6 @@ mod tests {
|
||||
}
|
||||
|
||||
/// Navigates to the next box after the current one, or up if the current one is last.
|
||||
#[allow(should_implement_trait)]
|
||||
pub fn next(&mut self) -> bool {
|
||||
let old = self.stack.pop().expect("positioned at root; there is no next");
|
||||
let max = self.stack.last().map(|b| b.interior.end).unwrap_or_else(|| self.mp4.len());
|
||||
@@ -1421,6 +1423,7 @@ mod tests {
|
||||
db.syncer_channel.flush();
|
||||
}
|
||||
|
||||
#[cfg(nightly)]
|
||||
fn add_dummy_recordings_to_db(db: &db::Database) {
|
||||
let mut data = Vec::new();
|
||||
data.extend_from_slice(include_bytes!("testdata/video_sample_index.bin"));
|
||||
@@ -1738,11 +1741,13 @@ mod tests {
|
||||
/// Currently this only serves a single `.mp4` file but we could set up variations to benchmark
|
||||
/// different scenarios: with/without subtitles and edit lists, different lengths, serving
|
||||
/// different fractions of the file, etc.
|
||||
#[cfg(nightly)]
|
||||
struct BenchServer {
|
||||
url: hyper::Url,
|
||||
generated_len: u64,
|
||||
}
|
||||
|
||||
#[cfg(nightly)]
|
||||
impl BenchServer {
|
||||
fn new() -> BenchServer {
|
||||
let mut listener = hyper::net::HttpListener::new("127.0.0.1:0").unwrap();
|
||||
@@ -1771,11 +1776,13 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(nightly)]
|
||||
lazy_static! {
|
||||
static ref SERVER: BenchServer = { BenchServer::new() };
|
||||
}
|
||||
|
||||
/// Benchmarks serving the generated part of a `.mp4` file (up to the first byte from disk).
|
||||
#[cfg(nightly)]
|
||||
#[bench]
|
||||
fn serve_generated_bytes_fresh_client(b: &mut Bencher) {
|
||||
testutil::init();
|
||||
@@ -1801,6 +1808,7 @@ mod tests {
|
||||
/// This should be faster than the `fresh` version, but see
|
||||
/// [this hyper issue](https://github.com/hyperium/hyper/issues/944) relating to Nagle's
|
||||
/// algorithm.
|
||||
#[cfg(nightly)]
|
||||
#[bench]
|
||||
fn serve_generated_bytes_reuse_client(b: &mut Bencher) {
|
||||
testutil::init();
|
||||
@@ -1822,6 +1830,7 @@ mod tests {
|
||||
});
|
||||
}
|
||||
|
||||
#[cfg(nightly)]
|
||||
#[bench]
|
||||
fn mp4_construction(b: &mut Bencher) {
|
||||
testutil::init();
|
||||
|
||||
@@ -28,8 +28,6 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#![allow(inline_always)]
|
||||
|
||||
extern crate uuid;
|
||||
|
||||
use db;
|
||||
@@ -484,11 +482,12 @@ impl Segment {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[cfg(nightly)]
|
||||
extern crate test;
|
||||
|
||||
use super::{append_varint32, decode_varint32, unzigzag32, zigzag32};
|
||||
use super::*;
|
||||
use self::test::Bencher;
|
||||
#[cfg(nightly)] use self::test::Bencher;
|
||||
use testutil::TestDb;
|
||||
|
||||
#[test]
|
||||
@@ -746,6 +745,7 @@ mod tests {
|
||||
// TODO: test segment error cases involving mismatch between row frames/key_frames and index.
|
||||
|
||||
/// Benchmarks the decoder, which is performance-critical for .mp4 serving.
|
||||
#[cfg(nightly)]
|
||||
#[bench]
|
||||
fn bench_decoder(b: &mut Bencher) {
|
||||
let data = include_bytes!("testdata/video_sample_index.bin");
|
||||
|
||||
Reference in New Issue
Block a user