more counters
This commit is contained in:
parent
3f0c4b7237
commit
124c6057be
2 changed files with 23 additions and 13 deletions
|
|
@ -7,12 +7,12 @@ use dht::{Dht, DhtStats};
|
||||||
use http::StatusCode;
|
use http::StatusCode;
|
||||||
use librqbit_core::id20::Id20;
|
use librqbit_core::id20::Id20;
|
||||||
use librqbit_core::torrent_metainfo::TorrentMetaV1Info;
|
use librqbit_core::torrent_metainfo::TorrentMetaV1Info;
|
||||||
use tracing::{warn, info};
|
|
||||||
use parking_lot::RwLock;
|
use parking_lot::RwLock;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
|
use tracing::{info, warn};
|
||||||
|
|
||||||
use axum::Router;
|
use axum::Router;
|
||||||
|
|
||||||
|
|
@ -341,7 +341,10 @@ impl ApiInternal {
|
||||||
let mgr = self.mgr_handle(idx)?;
|
let mgr = self.mgr_handle(idx)?;
|
||||||
Ok(format!(
|
Ok(format!(
|
||||||
"{:?}",
|
"{:?}",
|
||||||
mgr.torrent_state().lock_read().chunks.get_have_pieces(),
|
mgr.torrent_state()
|
||||||
|
.lock_read("api_dump_haves")
|
||||||
|
.chunks
|
||||||
|
.get_have_pieces(),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -115,8 +115,7 @@ impl PeerStates {
|
||||||
reason: &'static str,
|
reason: &'static str,
|
||||||
f: impl FnOnce(&mut Peer) -> R,
|
f: impl FnOnce(&mut Peer) -> R,
|
||||||
) -> Option<R> {
|
) -> Option<R> {
|
||||||
self.states
|
timeit(reason, || self.states.get_mut(&addr))
|
||||||
.get_mut(&addr)
|
|
||||||
.map(|e| f(TimedExistence::new(e, reason).value_mut()))
|
.map(|e| f(TimedExistence::new(e, reason).value_mut()))
|
||||||
}
|
}
|
||||||
pub fn with_live<R>(&self, addr: PeerHandle, f: impl FnOnce(&LivePeerState) -> R) -> Option<R> {
|
pub fn with_live<R>(&self, addr: PeerHandle, f: impl FnOnce(&LivePeerState) -> R) -> Option<R> {
|
||||||
|
|
@ -521,20 +520,23 @@ impl TorrentState {
|
||||||
pub fn initially_needed(&self) -> u64 {
|
pub fn initially_needed(&self) -> u64 {
|
||||||
self.needed
|
self.needed
|
||||||
}
|
}
|
||||||
pub fn lock_read(&self) -> RwLockReadGuard<TorrentStateLocked> {
|
pub fn lock_read(
|
||||||
self.locked.read()
|
&self,
|
||||||
|
reason: &'static str,
|
||||||
|
) -> TimedExistence<RwLockReadGuard<TorrentStateLocked>> {
|
||||||
|
TimedExistence::new(timeit(reason, || self.locked.read()), reason)
|
||||||
}
|
}
|
||||||
pub fn lock_write(
|
pub fn lock_write(
|
||||||
&self,
|
&self,
|
||||||
reason: &'static str,
|
reason: &'static str,
|
||||||
) -> TimedExistence<RwLockWriteGuard<TorrentStateLocked>> {
|
) -> TimedExistence<RwLockWriteGuard<TorrentStateLocked>> {
|
||||||
TimedExistence::new(self.locked.write(), reason)
|
TimedExistence::new(timeit(reason, || self.locked.write()), reason)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_next_needed_piece(&self, peer_handle: PeerHandle) -> Option<ValidPieceIndex> {
|
fn get_next_needed_piece(&self, peer_handle: PeerHandle) -> Option<ValidPieceIndex> {
|
||||||
self.peers
|
self.peers
|
||||||
.with_live_mut(peer_handle, "get_next_needed_piece", |live| {
|
.with_live_mut(peer_handle, "l(get_next_needed_piece)", |live| {
|
||||||
let g = self.locked.read();
|
let g = self.lock_read("g(get_next_needed_piece)");
|
||||||
let bf = live.bitfield.as_ref()?;
|
let bf = live.bitfield.as_ref()?;
|
||||||
for n in g.chunks.iter_needed_pieces() {
|
for n in g.chunks.iter_needed_pieces() {
|
||||||
if bf.get(n).map(|v| *v) == Some(true) {
|
if bf.get(n).map(|v| *v) == Some(true) {
|
||||||
|
|
@ -624,7 +626,7 @@ impl TorrentState {
|
||||||
use rand::seq::IteratorRandom;
|
use rand::seq::IteratorRandom;
|
||||||
self.peers
|
self.peers
|
||||||
.with_live(handle, |live| {
|
.with_live(handle, |live| {
|
||||||
let g = self.locked.read();
|
let g = self.lock_read("try_steal_piece");
|
||||||
g.inflight_pieces
|
g.inflight_pieces
|
||||||
.keys()
|
.keys()
|
||||||
.filter(|p| !live.inflight_requests.iter().any(|req| req.piece == **p))
|
.filter(|p| !live.inflight_requests.iter().any(|req| req.piece == **p))
|
||||||
|
|
@ -889,7 +891,7 @@ impl PeerConnectionHandler for PeerHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn serialize_bitfield_message_to_buf(&self, buf: &mut Vec<u8>) -> Option<usize> {
|
fn serialize_bitfield_message_to_buf(&self, buf: &mut Vec<u8>) -> Option<usize> {
|
||||||
let g = self.state.locked.read();
|
let g = self.state.lock_read("serialize_bitfield_message_to_buf");
|
||||||
let msg = Message::Bitfield(ByteBuf(g.chunks.get_have_pieces().as_raw_slice()));
|
let msg = Message::Bitfield(ByteBuf(g.chunks.get_have_pieces().as_raw_slice()));
|
||||||
let len = msg.serialize(buf, None).unwrap();
|
let len = msg.serialize(buf, None).unwrap();
|
||||||
debug!("sending: {:?}, length={}", &msg, len);
|
debug!("sending: {:?}, length={}", &msg, len);
|
||||||
|
|
@ -946,7 +948,7 @@ impl PeerHandler {
|
||||||
let tx = {
|
let tx = {
|
||||||
if !self
|
if !self
|
||||||
.state
|
.state
|
||||||
.lock_read()
|
.lock_read("is_chunk_ready_to_upload")
|
||||||
.chunks
|
.chunks
|
||||||
.is_chunk_ready_to_upload(&chunk_info)
|
.is_chunk_ready_to_upload(&chunk_info)
|
||||||
{
|
{
|
||||||
|
|
@ -1105,7 +1107,12 @@ impl PeerHandler {
|
||||||
};
|
};
|
||||||
|
|
||||||
for chunk in self.state.lengths.iter_chunk_infos(next) {
|
for chunk in self.state.lengths.iter_chunk_infos(next) {
|
||||||
if self.state.lock_read().chunks.is_chunk_downloaded(&chunk) {
|
if self
|
||||||
|
.state
|
||||||
|
.lock_read("is_chunk_downloaded")
|
||||||
|
.chunks
|
||||||
|
.is_chunk_downloaded(&chunk)
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue