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

* Some debugging tools added.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • 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