(trunk) #1408 "total downloading and seeding time per torrent" -- add patch to track how long a torrent has been seeding or downloading

This commit is contained in:
Charles Kerr 2010-12-23 19:32:59 +00:00
parent 70c634878e
commit 16a5fa4073
7 changed files with 67 additions and 14 deletions

View File

@ -51,6 +51,8 @@
#define KEY_SPEED_Bps "speed-Bps"
#define KEY_USE_GLOBAL_SPEED_LIMIT "use-global-speed-limit"
#define KEY_USE_SPEED_LIMIT "use-speed-limit"
#define KEY_TIME_SEEDING "seeding-time-seconds"
#define KEY_TIME_DOWNLOADING "downloading-time-seconds"
#define KEY_SPEEDLIMIT_DOWN_SPEED "down-speed"
#define KEY_SPEEDLIMIT_DOWN_MODE "down-mode"
#define KEY_SPEEDLIMIT_UP_SPEED "up-speed"
@ -505,6 +507,8 @@ tr_torrentSaveResume( tr_torrent * tor )
return;
tr_bencInitDict( &top, 50 ); /* arbitrary "big enough" number */
tr_bencDictAddInt( &top, KEY_TIME_SEEDING, tor->secondsSeeding );
tr_bencDictAddInt( &top, KEY_TIME_DOWNLOADING, tor->secondsDownloading );
tr_bencDictAddInt( &top, KEY_ACTIVITY_DATE, tor->activityDate );
tr_bencDictAddInt( &top, KEY_ADDED_DATE, tor->addedDate );
tr_bencDictAddInt( &top, KEY_CORRUPT, tor->corruptPrev + tor->corruptCur );
@ -636,6 +640,20 @@ loadFromFile( tr_torrent * tor,
fieldsLoaded |= TR_FR_ACTIVITY_DATE;
}
if( ( fieldsToLoad & TR_FR_TIME_SEEDING )
&& tr_bencDictFindInt( &top, KEY_TIME_SEEDING, &i ) )
{
tor->secondsSeeding = i;
fieldsLoaded |= TR_FR_TIME_SEEDING;
}
if( ( fieldsToLoad & TR_FR_TIME_DOWNLOADING )
&& tr_bencDictFindInt( &top, KEY_TIME_DOWNLOADING, &i ) )
{
tor->secondsDownloading = i;
fieldsLoaded |= TR_FR_TIME_DOWNLOADING;
}
if( ( fieldsToLoad & TR_FR_BANDWIDTH_PRIORITY )
&& tr_bencDictFindInt( &top, KEY_BANDWIDTH_PRIORITY, &i )
&& tr_isPriority( i ) )

View File

@ -36,7 +36,9 @@ enum
TR_FR_DONE_DATE = ( 1 << 14 ),
TR_FR_ACTIVITY_DATE = ( 1 << 15 ),
TR_FR_RATIOLIMIT = ( 1 << 16 ),
TR_FR_IDLELIMIT = ( 1 << 17 )
TR_FR_IDLELIMIT = ( 1 << 17 ),
TR_FR_TIME_SEEDING = ( 1 << 18 ),
TR_FR_TIME_DOWNLOADING = ( 1 << 19 )
};
/**

View File

@ -594,6 +594,10 @@ addField( const tr_torrent * tor, tr_benc * d, const char * key )
tr_bencDictAddInt( d, key, st->startDate );
else if( tr_streq( key, keylen, "status" ) )
tr_bencDictAddInt( d, key, st->activity );
else if( tr_streq( key, keylen, "secondsDownloading" ) )
tr_bencDictAddInt( d, key, st->secondsDownloading );
else if( tr_streq( key, keylen, "secondsSeeding" ) )
tr_bencDictAddInt( d, key, st->secondsSeeding );
else if( tr_streq( key, keylen, "trackers" ) )
addTrackers( inf, tr_bencDictAddList( d, key, inf->trackerCount ) );
else if( tr_streq( key, keylen, "trackerStats" ) ) {

View File

@ -546,11 +546,34 @@ onNowTimer( int foo UNUSED, short bar UNUSED, void * vsession )
const int min = 100;
const int max = 999999;
struct timeval tv;
tr_torrent * tor = NULL;
tr_session * session = vsession;
assert( tr_isSession( session ) );
assert( session->nowTimer != NULL );
/**
*** tr_session things to do once per second
**/
tr_timeUpdate( time( NULL ) );
if( session->turtle.isClockEnabled )
turtleCheckClock( session, &session->turtle );
while(( tor = tr_torrentNext( session, tor ))) {
if( tor->isRunning ) {
if( tr_torrentIsSeed( tor ) )
++tor->secondsSeeding;
else
++tor->secondsDownloading;
}
}
/**
*** Set the timer
**/
/* schedule the next timer for right after the next second begins */
gettimeofday( &tv, NULL );
usec = 1000000 - tv.tv_usec;
@ -558,11 +581,6 @@ onNowTimer( int foo UNUSED, short bar UNUSED, void * vsession )
if( usec < min ) usec = min;
tr_timerAdd( session->nowTimer, 0, usec );
/* fprintf( stderr, "time %zu sec, %zu microsec\n", (size_t)tr_time(), (size_t)tv.tv_usec ); */
/* tr_session things to do once per second */
tr_timeUpdate( tv.tv_sec );
if( session->turtle.isClockEnabled )
turtleCheckClock( session, &session->turtle );
}
static void loadBlocklists( tr_session * session );

View File

@ -1160,14 +1160,16 @@ tr_torrentStat( tr_torrent * tor )
s->percentComplete = tr_cpPercentComplete ( &tor->completion );
s->metadataPercentComplete = tr_torrentGetMetadataPercent( tor );
s->percentDone = tr_cpPercentDone ( &tor->completion );
s->leftUntilDone = tr_cpLeftUntilDone( &tor->completion );
s->sizeWhenDone = tr_cpSizeWhenDone ( &tor->completion );
s->recheckProgress = s->activity == TR_STATUS_CHECK ? getVerifyProgress( tor ) : 0;
s->activityDate = tor->activityDate;
s->addedDate = tor->addedDate;
s->doneDate = tor->doneDate;
s->startDate = tor->startDate;
s->percentDone = tr_cpPercentDone ( &tor->completion );
s->leftUntilDone = tr_cpLeftUntilDone( &tor->completion );
s->sizeWhenDone = tr_cpSizeWhenDone ( &tor->completion );
s->recheckProgress = s->activity == TR_STATUS_CHECK ? getVerifyProgress( tor ) : 0;
s->activityDate = tor->activityDate;
s->addedDate = tor->addedDate;
s->doneDate = tor->doneDate;
s->startDate = tor->startDate;
s->secondsSeeding = tor->secondsSeeding;
s->secondsDownloading = tor->secondsDownloading;
if ((s->activity == TR_STATUS_DOWNLOAD || s->activity == TR_STATUS_SEED) && s->startDate != 0)
s->idleSecs = difftime(tr_time(), MAX(s->startDate, s->activityDate));

View File

@ -206,6 +206,9 @@ struct tr_torrent
time_t startDate;
time_t anyDate;
time_t secondsDownloading;
time_t secondsSeeding;
tr_torrent_metadata_func * metadata_func;
void * metadata_func_user_data;

View File

@ -1873,6 +1873,12 @@ typedef struct tr_stat
-1 if activity is not seeding or downloading. */
int idleSecs;
/** Cumulative seconds the torrent's ever spent downloading */
int secondsDownloading;
/** Cumulative seconds the torrent's ever spent seeding */
int secondsSeeding;
/** A torrent is considered finished if it has met its seed ratio.
As a result, only paused torrents can be finished. */
tr_bool finished;