From cfe13586267efe559013623c09de78a001ae3a75 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 19 Jan 2009 21:17:29 +0000 Subject: [PATCH] (trunk libT) #1715: More stats information in rpc session-stats command --- doc/rpc-spec.txt | 18 ++++++++++++++++++ libtransmission/rpcimpl.c | 22 ++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/doc/rpc-spec.txt b/doc/rpc-spec.txt index b00395773..24d193ce7 100644 --- a/doc/rpc-spec.txt +++ b/doc/rpc-spec.txt @@ -362,6 +362,22 @@ "pausedTorrentCount" | number "torrentCount" | number "uploadSpeed" | number + ---------------------------+-------------------------------+ + "cumulative-stats" | object, containing: | + +------------------+------------+ + | uploadedBytes | number | tr_session_stats + | downloadedBytes | number | tr_session_stats + | filesAdded | number | tr_session_stats + | sessionCount | number | tr_session_stats + | secondsActive | number | tr_session_stats + ---------------------------+-------------------------------+ + "current-stats" | object, containing: | + +------------------+------------+ + | uploadedBytes | number | tr_session_stats + | downloadedBytes | number | tr_session_stats + | filesAdded | number | tr_session_stats + | sessionCount | number | tr_session_stats + | secondsActive | number | tr_session_stats 5.0. Protocol Versions @@ -382,6 +398,8 @@ ------+---------+-----------+----------------+------------------------------- 4 | 1.50 | yes | session-get | new arg "rpc-version" | | | session-get | new arg "rpc-version-minimum" + | | | session-stats | added "cumulative-stats" + | | | session-stats | added "current-stats" | | | torrent-get | new arg "downloadDir" ------+---------+-----------+----------------+------------------------------- diff --git a/libtransmission/rpcimpl.c b/libtransmission/rpcimpl.c index 0f0f897cd..6fe736559 100644 --- a/libtransmission/rpcimpl.c +++ b/libtransmission/rpcimpl.c @@ -22,6 +22,7 @@ #include "rpcimpl.h" #include "json.h" #include "session.h" +#include "stats.h" #include "torrent.h" #include "utils.h" #include "web.h" @@ -822,6 +823,9 @@ sessionStats( tr_session * session, { int running = 0; int total = 0; + tr_benc * d; + tr_session_stats currentStats = { 0.0f, 0, 0, 0, 0, 0 }; + tr_session_stats cumulativeStats = { 0.0f, 0, 0, 0, 0, 0 }; tr_torrent * tor = NULL; assert( idle_data == NULL ); @@ -832,11 +836,29 @@ sessionStats( tr_session * session, ++running; } + tr_sessionGetStats( session, ¤tStats ); + tr_sessionGetCumulativeStats( session, &cumulativeStats ); + tr_bencDictAddInt( args_out, "activeTorrentCount", running ); tr_bencDictAddInt( args_out, "downloadSpeed", (int)( tr_sessionGetPieceSpeed( session, TR_DOWN ) * 1024 ) ); tr_bencDictAddInt( args_out, "pausedTorrentCount", total - running ); tr_bencDictAddInt( args_out, "torrentCount", total ); tr_bencDictAddInt( args_out, "uploadSpeed", (int)( tr_sessionGetPieceSpeed( session, TR_UP ) * 1024 ) ); + + d = tr_bencDictAddDict( args_out, "cumulative-stats", 5 ); + tr_bencDictAddInt( d, "downloadedBytes", cumulativeStats.downloadedBytes ); + tr_bencDictAddInt( d, "filesAdded", cumulativeStats.filesAdded ); + tr_bencDictAddInt( d, "secondsActive", cumulativeStats.secondsActive ); + tr_bencDictAddInt( d, "sessionCount", cumulativeStats.sessionCount ); + tr_bencDictAddInt( d, "uploadedBytes", cumulativeStats.uploadedBytes ); + + d = tr_bencDictAddDict( args_out, "current-stats", 5 ); + tr_bencDictAddInt( d, "downloadedBytes", currentStats.downloadedBytes ); + tr_bencDictAddInt( d, "filesAdded", currentStats.filesAdded ); + tr_bencDictAddInt( d, "secondsActive", currentStats.secondsActive ); + tr_bencDictAddInt( d, "sessionCount", currentStats.sessionCount ); + tr_bencDictAddInt( d, "uploadedBytes", currentStats.uploadedBytes ); + return NULL; }