Add parameter with_peers to stats_snapshot while its slow
This commit is contained in:
parent
d6cef0952c
commit
0c89ee9248
5 changed files with 11 additions and 7 deletions
|
|
@ -55,7 +55,7 @@ async fn main() -> Result<(), anyhow::Error> {
|
||||||
async move {
|
async move {
|
||||||
loop {
|
loop {
|
||||||
tokio::time::sleep(Duration::from_secs(1)).await;
|
tokio::time::sleep(Duration::from_secs(1)).await;
|
||||||
let stats = handle.torrent_state().stats_snapshot();
|
let stats = handle.torrent_state().stats_snapshot(true);
|
||||||
info!("stats: {stats:?}");
|
info!("stats: {stats:?}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -320,7 +320,7 @@ impl ApiInternal {
|
||||||
|
|
||||||
fn api_stats(&self, idx: usize) -> Result<StatsResponse> {
|
fn api_stats(&self, idx: usize) -> Result<StatsResponse> {
|
||||||
let mgr = self.mgr_handle(idx)?;
|
let mgr = self.mgr_handle(idx)?;
|
||||||
let snapshot = mgr.torrent_state().stats_snapshot();
|
let snapshot = mgr.torrent_state().stats_snapshot(true);
|
||||||
let estimator = mgr.speed_estimator();
|
let estimator = mgr.speed_estimator();
|
||||||
|
|
||||||
// Poor mans download speed computation
|
// Poor mans download speed computation
|
||||||
|
|
|
||||||
|
|
@ -294,8 +294,8 @@ impl TorrentManager {
|
||||||
let state = mgr.state.clone();
|
let state = mgr.state.clone();
|
||||||
async move {
|
async move {
|
||||||
loop {
|
loop {
|
||||||
let stats = state.stats_snapshot();
|
let stats = state.stats_snapshot(false);
|
||||||
let fetched = state.stats_snapshot().fetched_bytes;
|
let fetched = stats.fetched_bytes;
|
||||||
let needed = state.initially_needed();
|
let needed = state.initially_needed();
|
||||||
// fetched can be too high in theory, so for safety make sure that it doesn't wrap around u64.
|
// fetched can be too high in theory, so for safety make sure that it doesn't wrap around u64.
|
||||||
let remaining = needed
|
let remaining = needed
|
||||||
|
|
|
||||||
|
|
@ -809,9 +809,13 @@ impl TorrentState {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn stats_snapshot(&self) -> StatsSnapshot {
|
pub fn stats_snapshot(&self, with_peer_stats: bool) -> StatsSnapshot {
|
||||||
use Ordering::*;
|
use Ordering::*;
|
||||||
let peer_stats = self.peers.stats();
|
let peer_stats = if with_peer_stats {
|
||||||
|
self.peers.stats()
|
||||||
|
} else {
|
||||||
|
Default::default()
|
||||||
|
};
|
||||||
let downloaded = self.stats.downloaded_and_checked.load(Relaxed);
|
let downloaded = self.stats.downloaded_and_checked.load(Relaxed);
|
||||||
let remaining = self.needed - downloaded;
|
let remaining = self.needed - downloaded;
|
||||||
StatsSnapshot {
|
StatsSnapshot {
|
||||||
|
|
|
||||||
|
|
@ -244,7 +244,7 @@ async fn async_main(opts: Opts, spawner: BlockingSpawner) -> anyhow::Result<()>
|
||||||
info!("[{}] initializing", idx);
|
info!("[{}] initializing", idx);
|
||||||
},
|
},
|
||||||
ManagedTorrentState::Running(handle) => {
|
ManagedTorrentState::Running(handle) => {
|
||||||
let stats = timeit("stats_snapshot", || handle.torrent_state().stats_snapshot());
|
let stats = timeit("stats_snapshot", || handle.torrent_state().stats_snapshot(true));
|
||||||
let speed = handle.speed_estimator();
|
let speed = handle.speed_estimator();
|
||||||
let total = stats.total_bytes;
|
let total = stats.total_bytes;
|
||||||
let progress = stats.total_bytes - stats.remaining_bytes;
|
let progress = stats.total_bytes - stats.remaining_bytes;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue