summaryrefslogtreecommitdiff
path: root/ot_stats.c
diff options
context:
space:
mode:
authorerdgeist <>2009-09-02 02:18:36 +0000
committererdgeist <>2009-09-02 02:18:36 +0000
commit0bf88427c6c33f0aabc4e8374ed77542c4f18d2a (patch)
tree3290e11f0a5f95c3ffdb4d2d1d04bf0c05a7e366 /ot_stats.c
parentc76814cfecbf2fabcc316e7f14f52766a8f59a45 (diff)
Add spotting woodpeckers, thanks to Vasya P. again
Diffstat (limited to 'ot_stats.c')
-rw-r--r--ot_stats.c55
1 files changed, 31 insertions, 24 deletions
diff --git a/ot_stats.c b/ot_stats.c
index 8e6a0c9..a7c01c6 100644
--- a/ot_stats.c
+++ b/ot_stats.c
@@ -181,7 +181,7 @@ static size_t stats_get_highscore_networks( stats_network_node *node, int depth,
181 return score; 181 return score;
182} 182}
183 183
184static size_t stats_return_busy_networks( char * reply, stats_network_node *tree, int amount ) { 184static size_t stats_return_busy_networks( char * reply, stats_network_node *tree, int amount, int limit ) {
185 ot_ip6 networks[amount]; 185 ot_ip6 networks[amount];
186 ot_ip6 node_value; 186 ot_ip6 node_value;
187 size_t scores[amount]; 187 size_t scores[amount];
@@ -192,9 +192,9 @@ static size_t stats_return_busy_networks( char * reply, stats_network_node *tree
192 memset( networks, 0, sizeof( networks ) ); 192 memset( networks, 0, sizeof( networks ) );
193 memset( node_value, 0, sizeof( node_value ) ); 193 memset( node_value, 0, sizeof( node_value ) );
194 194
195 stats_get_highscore_networks( tree, 0, node_value, scores, networks, amount, STATS_NETWORK_NODE_MAXDEPTH ); 195 stats_get_highscore_networks( tree, 0, node_value, scores, networks, amount, limit );
196 196
197 r += sprintf( r, "Networks, limit /%d:\n", STATS_NETWORK_NODE_MAXDEPTH+STATS_NETWORK_NODE_BITWIDTH ); 197 r += sprintf( r, "Networks, limit /%d:\n", limit+STATS_NETWORK_NODE_BITWIDTH );
198 for( i=amount-1; i>=0; --i) { 198 for( i=amount-1; i>=0; --i) {
199 if( scores[i] ) { 199 if( scores[i] ) {
200 r += sprintf( r, "%08zd: ", scores[i] ); 200 r += sprintf( r, "%08zd: ", scores[i] );
@@ -206,25 +206,7 @@ static size_t stats_return_busy_networks( char * reply, stats_network_node *tree
206 *r++ = '\n'; 206 *r++ = '\n';
207 } 207 }
208 } 208 }
209 209 *r++ = '\n';
210 memset( scores, 0, sizeof( scores ) );
211 memset( networks, 0, sizeof( networks ) );
212 memset( node_value, 0, sizeof( node_value ) );
213
214 stats_get_highscore_networks( tree, 0, node_value, scores, networks, amount, STATS_NETWORK_NODE_LIMIT );
215
216 r += sprintf( r, "\nNetworks, limit /%d:\n", STATS_NETWORK_NODE_LIMIT+STATS_NETWORK_NODE_BITWIDTH );
217 for( i=amount-1; i>=0; --i) {
218 if( scores[i] ) {
219 r += sprintf( r, "%08zd: ", scores[i] );
220#ifdef WANT_V6
221 r += fmt_ip6c( r, networks[i] );
222#else
223 r += fmt_ip4( r, networks[i] );
224#endif
225 *r++ = '\n';
226 }
227 }
228 210
229 return r - reply; 211 return r - reply;
230} 212}
@@ -262,7 +244,8 @@ static size_t stats_slash24s_txt( char *reply, size_t amount ) {
262 } 244 }
263 245
264 /* The tree is built. Now analyze */ 246 /* The tree is built. Now analyze */
265 r += stats_return_busy_networks( r, slash24s_network_counters_root, amount ); 247 r += stats_return_busy_networks( r, slash24s_network_counters_root, amount, STATS_NETWORK_NODE_MAXDEPTH );
248 r += stats_return_busy_networks( r, slash24s_network_counters_root, amount, STATS_NETWORK_NODE_LIMIT );
266 goto success; 249 goto success;
267 250
268bailout_unlock: 251bailout_unlock:
@@ -275,11 +258,25 @@ success:
275 return r-reply; 258 return r-reply;
276} 259}
277 260
261#ifdef WANT_SPOT_WOODPECKER
262static stats_network_node *stats_woodpeckers_tree;
263static pthread_mutex_t g_woodpeckers_mutex = PTHREAD_MUTEX_INITIALIZER;
264
265static size_t stats_return_woodpeckers( char * reply, int amount ) {
266 char * r = reply;
267
268 pthread_mutex_lock( &g_woodpeckers_mutex );
269 r += stats_return_busy_networks( r, stats_woodpeckers_tree, amount, STATS_NETWORK_NODE_MAXDEPTH );
270 pthread_mutex_unlock( &g_woodpeckers_mutex );
271 return r-reply;
272}
273
278typedef struct { 274typedef struct {
279 unsigned long long torrent_count; 275 unsigned long long torrent_count;
280 unsigned long long peer_count; 276 unsigned long long peer_count;
281 unsigned long long seed_count; 277 unsigned long long seed_count;
282} torrent_stats; 278} torrent_stats;
279#endif
283 280
284static int torrent_statter( ot_torrent *torrent, uintptr_t data ) { 281static int torrent_statter( ot_torrent *torrent, uintptr_t data ) {
285 torrent_stats *stats = (torrent_stats*)data; 282 torrent_stats *stats = (torrent_stats*)data;
@@ -611,6 +608,9 @@ static void stats_make( int *iovec_entries, struct iovec **iovector, ot_tasktype
611 case TASK_STATS_SLASH24S: r += stats_slash24s_txt( r, 128 ); break; 608 case TASK_STATS_SLASH24S: r += stats_slash24s_txt( r, 128 ); break;
612 case TASK_STATS_TOP10: r += stats_top10_txt( r ); break; 609 case TASK_STATS_TOP10: r += stats_top10_txt( r ); break;
613 case TASK_STATS_EVERYTHING: r += stats_return_everything( r ); break; 610 case TASK_STATS_EVERYTHING: r += stats_return_everything( r ); break;
611#ifdef WANT_SPOT_WOODPECKER
612 case TASK_STATS_WOODPECKERS: r += stats_return_woodpeckers( r, 128 ); break;
613#endif
614#ifdef WANT_FULLLOG_NETWORKS 614#ifdef WANT_FULLLOG_NETWORKS
615 case TASK_STATS_FULLLOG: stats_return_fulllog( iovec_entries, iovector, r ); 615 case TASK_STATS_FULLLOG: stats_return_fulllog( iovec_entries, iovector, r );
616 return; 616 return;
@@ -670,7 +670,7 @@ void stats_issue_event( ot_status_event event, PROTO_FLAG proto, uintptr_t event
670 case EVENT_FAILED: 670 case EVENT_FAILED:
671 ot_failed_request_counts[event_data]++; 671 ot_failed_request_counts[event_data]++;
672 break; 672 break;
673 case EVENT_RENEW: 673 case EVENT_RENEW:
674 ot_renewed[event_data]++; 674 ot_renewed[event_data]++;
675 break; 675 break;
676 case EVENT_SYNC: 676 case EVENT_SYNC:
@@ -679,6 +679,13 @@ void stats_issue_event( ot_status_event event, PROTO_FLAG proto, uintptr_t event
679 case EVENT_BUCKET_LOCKED: 679 case EVENT_BUCKET_LOCKED:
680 ot_overall_stall_count++; 680 ot_overall_stall_count++;
681 break; 681 break;
682#ifdef WANT_SPOT_WOODPECKER
683 case EVENT_WOODPECKER:
684 pthread_mutex_lock( &g_woodpeckers_mutex );
685 stat_increase_network_count( &stats_woodpeckers_tree, 0, event_data );
686 pthread_mutex_unlock( &g_woodpeckers_mutex );
687 break;
688#endif
682 default: 689 default:
683 break; 690 break;
684 } 691 }