Changeset 1172

Show
Ignore:
Timestamp:
08/25/10 03:14:19 (18 months ago)
Author:
rakshasa
Message:

* Some debugging tools added.

Location:
trunk
Files:
3 added
6 modified

Legend:

Unmodified
Added
Removed
  • trunk/libtorrent/src/data/chunk.cc

    r1105 r1172  
    114114 
    115115uint32_t 
    116 Chunk::incore_length(uint32_t pos) { 
    117   uint32_t lengthIncore = 0; 
     116Chunk::incore_length(uint32_t pos, uint32_t length) { 
     117  uint32_t result = 0; 
    118118  iterator itr = at_position(pos); 
    119119 
     
    121121    throw internal_error("Chunk::incore_length(...) at end()"); 
    122122 
    123   do { 
    124     uint32_t length = itr->incore_length(pos); 
    125  
    126     pos += length; 
    127     lengthIncore += length; 
     123  length = std::min(length, chunk_size() - pos); 
     124 
     125  do { 
     126    uint32_t incore_len = itr->incore_length(pos, length); 
     127 
     128    if (incore_len > length) 
     129      throw internal_error("Chunk::incore_length(...) incore_len > length."); 
     130 
     131    pos += incore_len; 
     132    length -= incore_len; 
     133    result += incore_len; 
    128134 
    129135  } while (pos == itr->position() + itr->size() && ++itr != end()); 
    130136 
    131   return lengthIncore; 
     137  return result; 
    132138} 
    133139 
  • trunk/libtorrent/src/data/chunk.h

    r1171 r1172  
    8585 
    8686  // Check how much of the chunk is incore from pos. 
    87   uint32_t            incore_length(uint32_t pos); 
     87  uint32_t            incore_length(uint32_t pos, uint32_t length = ~uint32_t()); 
    8888 
    8989  bool                sync(int flags); 
  • trunk/libtorrent/src/data/chunk_part.cc

    r939 r1172  
    6262 
    6363uint32_t 
    64 ChunkPart::incore_length(uint32_t pos) { 
     64ChunkPart::incore_length(uint32_t pos, uint32_t length) { 
    6565  // Do we want to use this? 
    66   pos -= m_position; 
     66  length = std::min(length, remaining_from(pos)); 
     67  pos = pos - m_position; 
    6768 
    6869  if (pos >= size()) 
    6970    throw internal_error("ChunkPart::incore_length(...) got invalid position"); 
    7071 
    71   int length = size() - pos; 
    7272  int touched = m_chunk.pages_touched(pos, length); 
    7373  char buf[touched]; 
  • trunk/libtorrent/src/data/chunk_part.h

    r1171 r1172  
    6565  uint32_t            position() const                      { return m_position; } 
    6666 
    67   uint32_t            incore_length(uint32_t pos); 
     67  uint32_t            remaining_from(uint32_t pos) const    { return size() - (pos - m_position); } 
     68 
     69  uint32_t            incore_length(uint32_t pos, uint32_t length = ~uint32_t()); 
    6870 
    6971private: 
  • trunk/libtorrent/src/protocol/peer_connection_base.cc

    r1145 r1172  
    3838 
    3939#include <cstdio> 
     40#include <fcntl.h> 
    4041#include <rak/error_number.h> 
     42#include <rak/string_manip.h> 
    4143 
    4244#include "torrent/exceptions.h" 
     
    277279} 
    278280 
     281inline static void 
     282log_upload_chunk_mincore(Chunk* chunk, const Piece& piece, bool new_index) { 
     283#ifdef LT_LOG_MINCORE_FILE 
     284  static int mincore_fd = -1; 
     285  static int32_t ticker = rak::timer::current().seconds() / 10 * 10; 
     286 
     287  static int counter_incore = 0; 
     288  static int counter_not_incore = 0; 
     289  static int counter_incore_new = 0; 
     290  static int counter_not_incore_new = 0; 
     291 
     292  if (rak::timer::current().seconds() >= ticker + 10) { 
     293    char buffer[256]; 
     294 
     295    if (mincore_fd == -1) { 
     296      snprintf(buffer, 256, "%s.%u", LT_LOG_MINCORE_FILE, getpid()); 
     297     
     298      if ((mincore_fd = open(buffer, O_WRONLY | O_CREAT | O_TRUNC)) == -1) 
     299        throw internal_error("Could not open mincore log file."); 
     300    } 
     301 
     302    // Log the result of mincore for every piece uploaded to a file. 
     303    unsigned int buf_lenght = snprintf(buffer, 256, "%i %u %u %u %u\n", 
     304                                       ticker, counter_incore, counter_incore_new, counter_not_incore, counter_not_incore_new); 
     305 
     306    write(mincore_fd, buffer, buf_lenght); 
     307     
     308    ticker = rak::timer::current().seconds() / 10 * 10; 
     309 
     310    counter_incore = 0; 
     311    counter_not_incore = 0; 
     312    counter_incore_new = 0; 
     313    counter_not_incore_new = 0; 
     314  } 
     315 
     316  bool is_incore = (chunk->incore_length(piece.offset(), piece.length()) == piece.length()); 
     317 
     318  counter_incore += !new_index && is_incore; 
     319  counter_incore_new += new_index && is_incore; 
     320  counter_not_incore += !new_index && !is_incore; 
     321  counter_not_incore_new += new_index && !is_incore; 
     322#endif 
     323} 
     324 
    279325void 
    280326PeerConnectionBase::load_up_chunk() { 
     
    282328    // Better checking needed. 
    283329    //     m_upChunk.chunk()->preload(m_upPiece.offset(), m_upChunk.chunk()->size()); 
     330    log_upload_chunk_mincore(m_upChunk.chunk(), m_upPiece, false); 
    284331    return; 
    285332  } 
     
    296343    m_encryptBuffer->reset(); 
    297344  } 
     345 
     346  log_upload_chunk_mincore(m_upChunk.chunk(), m_upPiece, true); 
    298347 
    299348  // Also check if we've already preloaded in the recent past, even 
  • trunk/rtorrent/src/command_network.cc

    r1168 r1172  
    421421  CMD2_VAR_STRING("connection_seed", "seed"); 
    422422 
     423  CMD2_ANY         ("throttle.unchoked_uploads", std::tr1::bind(&torrent::currently_unchoked)); 
     424  CMD2_ANY         ("throttle.unchoked_downloads", std::tr1::bind(&torrent::download_unchoked)); 
     425 
    423426  CMD2_VAR_VALUE   ("throttle.min_peers.normal", 40); 
    424427  CMD2_VAR_VALUE   ("throttle.max_peers.normal", 100);