exposed read cache info as well as write cache

This commit is contained in:
Arvid Norberg 2008-07-11 10:29:26 +00:00
parent 535aaf8182
commit 9c9c13c7bb
5 changed files with 50 additions and 1 deletions

View File

@ -793,6 +793,8 @@ struct cached_piece_info
int piece;
std::vector<bool> blocks;
ptime last_use;
enum kind_t { read_cache = 0, write_cache = 1 };
kind_t kind;
};
</pre>
</blockquote>
@ -801,6 +803,7 @@ struct cached_piece_info
the data for that block being in the disk cache and <tt class="docutils literal"><span class="pre">false</span></tt> means it's not.</p>
<p><tt class="docutils literal"><span class="pre">last_use</span></tt> is the time when a block was last written to this piece. The older
a piece is, the more likely it is to be flushed to disk.</p>
<p><tt class="docutils literal"><span class="pre">kind</span></tt> specifies if this piece is part of the read cache or the write cache.</p>
</div>
<div class="section">
<h2><a id="is-listening-listen-port-listen-on" name="is-listening-listen-port-listen-on">is_listening() listen_port() listen_on()</a></h2>
@ -2852,6 +2855,7 @@ struct session_settings
bool upnp_ignore_nonrouters;
int send_buffer_watermark;
bool auto_upload_slots;
bool use_parole_mode;
int cache_size;
int cache_expiry;
std::pair&lt;int, int&gt; outgoing_ports;
@ -3018,6 +3022,11 @@ slot is opened. If the upload rate has been saturated for an extended period
of time, on upload slot is closed. The number of upload slots will never be
less than what has been set by <tt class="docutils literal"><span class="pre">session::set_max_uploads()</span></tt>. To query the
current number of upload slots, see <tt class="docutils literal"><span class="pre">session_status::allowed_upload_slots</span></tt>.</p>
<p><tt class="docutils literal"><span class="pre">use_parole_mode</span></tt> specifies if parole mode should be used. Parole mode means
that peers that participate in pieces that fail the hash check are put in a mode
where they are only allowed to download whole pieces. If the whole piece a peer
in parole mode fails the hash check, it is banned. If a peer participates in a
piece that passes the hash check, it is taken out of parole mode.</p>
<p><tt class="docutils literal"><span class="pre">cache_size</span></tt> is the disk write cache. It is specified in units of 16 KiB blocks.
It defaults to 512 (= 8 MB).</p>
<p><tt class="docutils literal"><span class="pre">cache_expiry</span></tt> is the number of seconds from the last cached write to a piece

View File

@ -625,6 +625,8 @@ specified info-hash (``ih``).
int piece;
std::vector<bool> blocks;
ptime last_use;
enum kind_t { read_cache = 0, write_cache = 1 };
kind_t kind;
};
``piece`` is the piece index for this cache entry.
@ -635,6 +637,8 @@ the data for that block being in the disk cache and ``false`` means it's not.
``last_use`` is the time when a block was last written to this piece. The older
a piece is, the more likely it is to be flushed to disk.
``kind`` specifies if this piece is part of the read cache or the write cache.
is_listening() listen_port() listen_on()
----------------------------------------

View File

@ -1344,7 +1344,7 @@ int main(int ac, char* av[])
if (print_peers && !peers.empty())
print_peer_info(out, peers);
if (print_downloads && s.state != torrent_status::seeding)
if (print_downloads)
{
h.get_download_queue(queue);
std::sort(queue.begin(), queue.end(), bind(&partial_piece_info::piece_index, _1)
@ -1398,6 +1398,24 @@ int main(int ac, char* av[])
out << "\n";
}
for (std::vector<cached_piece_info>::iterator i = pieces.begin()
, end(pieces.end()); i != end; ++i)
{
if (i->kind != cached_piece_info::read_cache) continue;
out << to_string(i->piece, 4) << ": [";
for (std::vector<bool>::iterator k = i->blocks.begin()
, end(i->blocks.end()); k != end; ++k)
{
#ifdef ANSI_TERMINAL_COLORS
if (*k) out << esc("33;7") << " " << esc("0");
else out << " ";
#else
if (*k) out << "#";
else out << " ";
#endif
}
out << "]\n";
}
out << "___________________________________\n";
}

View File

@ -58,6 +58,8 @@ namespace libtorrent
int piece;
std::vector<bool> blocks;
ptime last_use;
enum kind_t { read_cache = 0, write_cache = 1 };
kind_t kind;
};
struct disk_io_job

View File

@ -101,6 +101,22 @@ namespace libtorrent
cached_piece_info info;
info.piece = i->piece;
info.last_use = i->last_use;
info.kind = cached_piece_info::write_cache;
int blocks_in_piece = (ti.piece_size(i->piece) + (m_block_size) - 1) / m_block_size;
info.blocks.resize(blocks_in_piece);
for (int b = 0; b < blocks_in_piece; ++b)
if (i->blocks[b]) info.blocks[b] = true;
ret.push_back(info);
}
for (cache_t::const_iterator i = m_read_pieces.begin()
, end(m_read_pieces.end()); i != end; ++i)
{
torrent_info const& ti = *i->storage->info();
if (ti.info_hash() != ih) continue;
cached_piece_info info;
info.piece = i->piece;
info.last_use = i->last_use;
info.kind = cached_piece_info::read_cache;
int blocks_in_piece = (ti.piece_size(i->piece) + (m_block_size) - 1) / m_block_size;
info.blocks.resize(blocks_in_piece);
for (int b = 0; b < blocks_in_piece; ++b)