Changeset 4920
- Timestamp:
- Feb 4, 2008, 7:52:00 PM (14 years ago)
- Location:
- branches/1.0x/libtransmission
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/1.0x/libtransmission/stats.c
r4778 r4920 25 25 { 26 26 tr_session_stats single; 27 tr_session_stats cumulative;27 tr_session_stats old; 28 28 time_t startTime; 29 29 }; … … 116 116 { 117 117 struct tr_stats_handle * stats = tr_new0( struct tr_stats_handle, 1 ); 118 loadCumulativeStats( &stats-> cumulative);119 stats-> cumulative.sessionCount++;120 stats->startTime = time( NULL);118 loadCumulativeStats( &stats->old ); 119 stats->single.sessionCount = 1; 120 stats->startTime = time( NULL ); 121 121 handle->sessionStats = stats; 122 122 } … … 125 125 tr_statsClose( tr_handle * handle ) 126 126 { 127 tr_session_stats tmp;128 tr_getCumulativeSessionStats( handle, & tmp);129 saveCumulativeStats( & tmp);127 tr_session_stats cumulative; 128 tr_getCumulativeSessionStats( handle, &cumulative ); 129 saveCumulativeStats( &cumulative ); 130 130 131 131 tr_free( handle->sessionStats ); … … 133 133 } 134 134 135 static struct tr_stats_handle * 136 getStats( const tr_handle * handle ) 137 { 138 static struct tr_stats_handle nullObject; 139 140 return handle && handle->sessionStats 141 ? handle->sessionStats 142 : &nullObject; 143 } 144 145 /*** 146 **** 147 ***/ 148 135 149 static void 136 150 updateRatio( tr_session_stats * setme ) 137 151 { 138 setme->ratio = tr_getRatio( setme->uploadedBytes, setme->downloadedBytes ); 152 setme->ratio = tr_getRatio( setme->uploadedBytes, 153 setme->downloadedBytes ); 154 } 155 156 static void 157 addStats( tr_session_stats * setme, 158 const tr_session_stats * a, 159 const tr_session_stats * b ) 160 { 161 setme->uploadedBytes = a->uploadedBytes + b->uploadedBytes; 162 setme->downloadedBytes = a->downloadedBytes + b->downloadedBytes; 163 setme->filesAdded = a->filesAdded + b->filesAdded; 164 setme->sessionCount = a->sessionCount + b->sessionCount; 165 setme->secondsActive = a->secondsActive + b->secondsActive; 166 updateRatio( setme ); 139 167 } 140 168 … … 143 171 tr_session_stats * setme ) 144 172 { 145 const struct tr_stats_handle * stats = handle->sessionStats;173 const struct tr_stats_handle * stats = getStats( handle ); 146 174 *setme = stats->single; 147 setme->secondsActive += ( time(NULL) - stats->startTime );175 setme->secondsActive = time( NULL ) - stats->startTime; 148 176 updateRatio( setme ); 149 177 } … … 153 181 tr_session_stats * setme ) 154 182 { 155 const struct tr_stats_handle * stats = handle->sessionStats; 156 *setme = stats->cumulative; 157 setme->secondsActive += ( time(NULL) - stats->startTime ); 158 updateRatio( setme ); 183 tr_session_stats current; 184 tr_getSessionStats( handle, ¤t ); 185 addStats( setme, &getStats(handle)->old, ¤t ); 159 186 } 160 187 … … 166 193 tr_statsAddUploaded( tr_handle * handle, uint32_t bytes ) 167 194 { 168 struct tr_stats_handle * stats = handle->sessionStats; 169 stats->single.uploadedBytes += bytes; 170 stats->cumulative.uploadedBytes += bytes; 195 getStats(handle)->single.uploadedBytes += bytes; 171 196 } 172 197 … … 174 199 tr_statsAddDownloaded( tr_handle * handle, uint32_t bytes ) 175 200 { 176 struct tr_stats_handle * stats = handle->sessionStats; 177 stats->single.downloadedBytes += bytes; 178 stats->cumulative.downloadedBytes += bytes; 201 getStats(handle)->single.downloadedBytes += bytes; 179 202 } 180 203 … … 182 205 tr_statsFileCreated( tr_handle * handle ) 183 206 { 184 struct tr_stats_handle * stats = handle->sessionStats; 185 ++stats->cumulative.filesAdded; 186 ++stats->single.filesAdded; 187 } 207 getStats(handle)->single.filesAdded++; 208 } -
branches/1.0x/libtransmission/transmission.c
r4776 r4920 393 393 const uint64_t deadline = tr_date( ) + maxwait_msec; 394 394 395 tr_statsClose( h ); 396 395 397 tr_runInEventThread( h, tr_closeImpl, h ); 396 398 while( !h->isClosed && !deadlineReached( deadline ) ) … … 402 404 403 405 tr_fdClose( ); 404 tr_statsClose( h );405 406 tr_lockFree( h->lock ); 406 407 free( h->tag );
Note: See TracChangeset
for help on using the changeset viewer.