2017-07-21 09:21:59 +00:00
|
|
|
use prelude::*;
|
2017-03-21 10:28:11 +00:00
|
|
|
|
2018-03-10 15:35:40 +00:00
|
|
|
use std::collections::HashMap;
|
2017-03-25 11:43:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
pub struct BundleAnalysis {
|
|
|
|
pub info: BundleInfo,
|
|
|
|
pub chunk_usage: Bitmap,
|
|
|
|
pub used_raw_size: usize
|
|
|
|
}
|
|
|
|
|
|
|
|
impl BundleAnalysis {
|
|
|
|
#[inline]
|
|
|
|
pub fn get_usage_ratio(&self) -> f32 {
|
|
|
|
self.used_raw_size as f32 / self.info.raw_size as f32
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
pub fn get_used_size(&self) -> usize {
|
|
|
|
(self.get_usage_ratio() * self.info.encoded_size as f32) as usize
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
pub fn get_unused_size(&self) -> usize {
|
|
|
|
((1.0 - self.get_usage_ratio()) * self.info.encoded_size as f32) as usize
|
|
|
|
}
|
|
|
|
}
|
2017-03-15 07:27:27 +00:00
|
|
|
|
|
|
|
pub struct RepositoryInfo {
|
|
|
|
pub bundle_count: usize,
|
|
|
|
pub encoded_data_size: u64,
|
|
|
|
pub raw_data_size: u64,
|
|
|
|
pub compression_ratio: f32,
|
|
|
|
pub chunk_count: usize,
|
2017-03-15 20:53:05 +00:00
|
|
|
pub avg_chunk_size: f32,
|
|
|
|
pub index_size: usize,
|
|
|
|
pub index_capacity: usize,
|
|
|
|
pub index_entries: usize
|
2017-03-15 07:27:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-06 21:22:52 +00:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct RepositoryStatistics {
|
2018-03-06 21:53:35 +00:00
|
|
|
pub index: IndexStatistics,
|
|
|
|
pub bundles: BundleStatistics
|
2018-03-06 21:22:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-06-13 21:08:45 +00:00
|
|
|
impl Repository {
|
2018-03-10 15:35:40 +00:00
|
|
|
#[inline]
|
|
|
|
pub fn list_bundles(&self) -> Vec<&BundleInfo> {
|
|
|
|
self.bundles.list_bundles()
|
2017-03-25 11:43:49 +00:00
|
|
|
}
|
|
|
|
|
2018-03-10 15:35:40 +00:00
|
|
|
pub fn get_bundle_map(&self) -> Result<HashMap<u32, &BundleInfo>, RepositoryError> {
|
|
|
|
let mut map = HashMap::with_capacity(self.bundle_map.len());
|
|
|
|
for (id, bundle_id) in self.bundle_map.bundles() {
|
|
|
|
let info = try!(self.bundles.get_bundle_info(&bundle_id).ok_or_else(|| {
|
|
|
|
IntegrityError::MissingBundle(bundle_id)
|
2017-07-21 09:21:59 +00:00
|
|
|
}));
|
2018-03-10 15:35:40 +00:00
|
|
|
map.insert(id, &info.info);
|
2017-03-25 11:43:49 +00:00
|
|
|
}
|
2018-03-10 15:35:40 +00:00
|
|
|
Ok(map)
|
2017-03-15 07:27:27 +00:00
|
|
|
}
|
|
|
|
|
2017-03-24 11:52:01 +00:00
|
|
|
#[inline]
|
2017-04-07 16:57:49 +00:00
|
|
|
pub fn get_bundle(&self, bundle: &BundleId) -> Option<&StoredBundle> {
|
2017-03-24 11:52:01 +00:00
|
|
|
self.bundles.get_bundle_info(bundle)
|
|
|
|
}
|
|
|
|
|
2017-03-15 07:27:27 +00:00
|
|
|
pub fn info(&self) -> RepositoryInfo {
|
|
|
|
let bundles = self.list_bundles();
|
|
|
|
let encoded_data_size = bundles.iter().map(|b| b.encoded_size as u64).sum();
|
|
|
|
let raw_data_size = bundles.iter().map(|b| b.raw_size as u64).sum();
|
|
|
|
let chunk_count = bundles.iter().map(|b| b.chunk_count).sum();
|
|
|
|
RepositoryInfo {
|
|
|
|
bundle_count: bundles.len(),
|
2018-03-03 16:25:05 +00:00
|
|
|
chunk_count,
|
|
|
|
encoded_data_size,
|
|
|
|
raw_data_size,
|
2017-03-15 07:27:27 +00:00
|
|
|
compression_ratio: encoded_data_size as f32 / raw_data_size as f32,
|
2017-03-15 20:53:05 +00:00
|
|
|
avg_chunk_size: raw_data_size as f32 / chunk_count as f32,
|
|
|
|
index_size: self.index.size(),
|
|
|
|
index_capacity: self.index.capacity(),
|
|
|
|
index_entries: self.index.len()
|
2017-03-15 07:27:27 +00:00
|
|
|
}
|
|
|
|
}
|
2018-03-06 21:22:52 +00:00
|
|
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
pub fn statistics(&self) -> RepositoryStatistics {
|
|
|
|
RepositoryStatistics {
|
2018-03-06 21:53:35 +00:00
|
|
|
index: self.index.statistics(),
|
|
|
|
bundles: self.bundles.statistics()
|
2018-03-06 21:22:52 +00:00
|
|
|
}
|
|
|
|
}
|
2017-03-15 07:27:27 +00:00
|
|
|
}
|