]> granicus.if.org Git - transmission/commitdiff
(trunk) #1408 "total downloading and seeding time per torrent" -- add patch to track...
authorCharles Kerr <charles@transmissionbt.com>
Thu, 23 Dec 2010 19:32:59 +0000 (19:32 +0000)
committerCharles Kerr <charles@transmissionbt.com>
Thu, 23 Dec 2010 19:32:59 +0000 (19:32 +0000)
libtransmission/resume.c
libtransmission/resume.h
libtransmission/rpcimpl.c
libtransmission/session.c
libtransmission/torrent.c
libtransmission/torrent.h
libtransmission/transmission.h

index c83b3954c2d18335c10e07e8b8ab07429b87a3ea..a1bccc2bcfee1cc6acb12d2c009aa06beb1a7bba 100644 (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 ) )
index c7dbdd9850455886c7459dede39c73d1a7d03282..0e8cab7bdd42a1f90cf516ebae01dd296b867819 100644 (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 )
 };
 
 /**
index 3a18ce99a0815506fa42635db58475ce18b6d4b6..fc57dbd6a4db6510f084ad3046fb5a056486d76d 100644 (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" ) ) {
index 6af02bbb7921c49ec9d38191a3d39542ce9217d6..9b8d3553d6a2bfefe949997285dc6782cd38e464 100644 (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 );
index 8e493f1578f3ef2ac2c4c1e503daa4c8b6a2cb89..02dc990cce512b50e87e040963357c31474dec96 100644 (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));
index b2df8142d71074398e717b1186aea743b9c4b56d..649b27dc8f6e4576161a1c0dc47775a57a7aaa8d 100644 (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;
 
index 528c19e3adf68efc0e57fe9b1bda7f5b47f7c6a1..060dfe4d9c4e4fb932fe88e29c77531c58313c3f 100644 (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;