better logs during normal operation

* don't log every time we delete stuff; leave it for the flush
* when flushing, break apart counts by sample file dir and include
  human-readable sizes
This commit is contained in:
Scott Lamb
2019-09-26 06:09:27 -07:00
parent 54e06a5326
commit 0a29f62fd3
8 changed files with 113 additions and 88 deletions

View File

@@ -28,6 +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/>.
use base::strutil::{decode_size, encode_size};
use crate::stream::{self, Opener, Stream};
use cursive::Cursive;
use cursive::traits::{Boxable, Identifiable, Finder};
@@ -37,7 +38,6 @@ use failure::Error;
use std::collections::BTreeMap;
use std::str::FromStr;
use std::sync::Arc;
use super::{decode_size, encode_size};
use url::Url;
/// Builds a `CameraChange` from an active `edit_camera_dialog`.

View File

@@ -28,6 +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/>.
use base::strutil::{decode_size, encode_size};
use cursive::Cursive;
use cursive::traits::{Boxable, Identifiable};
use cursive::views;
@@ -38,7 +39,6 @@ use std::cell::RefCell;
use std::collections::BTreeMap;
use std::rc::Rc;
use std::sync::Arc;
use super::{decode_size, encode_size};
struct Stream {
label: String,

View File

@@ -38,12 +38,8 @@ use cursive::Cursive;
use cursive::views;
use db;
use failure::Error;
use lazy_static::lazy_static;
use regex::Regex;
use serde::Deserialize;
use std::sync::Arc;
use std::fmt::Write;
use std::str::FromStr;
mod cameras;
mod dirs;
@@ -64,60 +60,6 @@ Options:
[default: /var/lib/moonfire-nvr/db]
"#;
static MULTIPLIERS: [(char, u64); 4] = [
// (suffix character, power of 2)
('T', 40),
('G', 30),
('M', 20),
('K', 10),
];
fn encode_size(mut raw: i64) -> String {
let mut encoded = String::new();
for &(c, n) in &MULTIPLIERS {
if raw >= 1i64<<n {
write!(&mut encoded, "{}{} ", raw >> n, c).unwrap();
raw &= (1i64 << n) - 1;
}
}
if raw > 0 || encoded.len() == 0 {
write!(&mut encoded, "{}", raw).unwrap();
} else {
encoded.pop(); // remove trailing space.
}
encoded
}
fn decode_size(encoded: &str) -> Result<i64, ()> {
let mut decoded = 0i64;
lazy_static! {
static ref RE: Regex = Regex::new(r"\s*([0-9]+)([TGMK])?,?\s*").unwrap();
}
let mut last_pos = 0;
for cap in RE.captures_iter(encoded) {
let whole_cap = cap.get(0).unwrap();
if whole_cap.start() > last_pos {
return Err(());
}
last_pos = whole_cap.end();
let mut piece = i64::from_str(&cap[1]).map_err(|_| ())?;
if let Some(m) = cap.get(2) {
let m = m.as_str().as_bytes()[0] as char;
for &(some_m, n) in &MULTIPLIERS {
if some_m == m {
piece *= 1i64<<n;
break;
}
}
}
decoded += piece;
}
if last_pos < encoded.len() {
return Err(());
}
Ok(decoded)
}
#[derive(Debug, Deserialize)]
struct Args {
flag_db_dir: String,
@@ -149,11 +91,3 @@ pub fn run() -> Result<(), Error> {
Ok(())
}
#[cfg(test)]
mod tests {
#[test]
fn test_decode() {
assert_eq!(super::decode_size("100M").unwrap(), 100i64 << 20);
}
}