summaryrefslogtreecommitdiff
path: root/ot_stats.c
diff options
context:
space:
mode:
Diffstat (limited to 'ot_stats.c')
-rw-r--r--ot_stats.c60
1 files changed, 30 insertions, 30 deletions
diff --git a/ot_stats.c b/ot_stats.c
index e1bce7c..6116c41 100644
--- a/ot_stats.c
+++ b/ot_stats.c
@@ -1,6 +1,6 @@
1/* This software was written by Dirk Engling <erdgeist@erdgeist.org> 1/* This software was written by Dirk Engling <erdgeist@erdgeist.org>
2 It is considered beerware. Prost. Skol. Cheers or whatever. 2 It is considered beerware. Prost. Skol. Cheers or whatever.
3 3
4 $id$ */ 4 $id$ */
5 5
6/* System */ 6/* System */
@@ -84,10 +84,10 @@ static int stat_increase_network_count( stats_network_node **node, int depth, ui
84 return -1; 84 return -1;
85 memset( *node, 0, sizeof( stats_network_node ) ); 85 memset( *node, 0, sizeof( stats_network_node ) );
86 } 86 }
87 87
88 if( depth < STATS_NETWORK_NODE_MAXDEPTH ) 88 if( depth < STATS_NETWORK_NODE_MAXDEPTH )
89 return stat_increase_network_count( &(*node)->children[ foo ], depth+1, ip ); 89 return stat_increase_network_count( &(*node)->children[ foo ], depth+1, ip );
90 90
91 (*node)->counters[ foo ]++; 91 (*node)->counters[ foo ]++;
92 return 0; 92 return 0;
93} 93}
@@ -122,9 +122,9 @@ static int stats_shift_down_network_count( stats_network_node **node, int depth,
122static void stats_get_highscore_networks( stats_network_node *node, int depth, ot_ip6 node_value, int *scores, ot_ip6 *networks, int network_count ) { 122static void stats_get_highscore_networks( stats_network_node *node, int depth, ot_ip6 node_value, int *scores, ot_ip6 *networks, int network_count ) {
123 uint8_t *_node_value = (uint8_t*)node_value; 123 uint8_t *_node_value = (uint8_t*)node_value;
124 int i; 124 int i;
125 125
126 if( !node ) return; 126 if( !node ) return;
127 127
128 if( depth < STATS_NETWORK_NODE_MAXDEPTH ) { 128 if( depth < STATS_NETWORK_NODE_MAXDEPTH ) {
129 for( i=0; i<STATS_NETWORK_NODE_COUNT; ++i ) 129 for( i=0; i<STATS_NETWORK_NODE_COUNT; ++i )
130 if( node->children[i] ) { 130 if( node->children[i] ) {
@@ -139,7 +139,7 @@ static void stats_get_highscore_networks( stats_network_node *node, int depth, o
139 _node_value[depth] = i; 139 _node_value[depth] = i;
140 while( (j<network_count) && (node->counters[i]>scores[j] ) ) ++j; 140 while( (j<network_count) && (node->counters[i]>scores[j] ) ) ++j;
141 --j; 141 --j;
142 142
143 memcpy( scores, scores + 1, j * sizeof( *scores ) ); 143 memcpy( scores, scores + 1, j * sizeof( *scores ) );
144 memcpy( networks, networks + 1, j * sizeof( *networks ) ); 144 memcpy( networks, networks + 1, j * sizeof( *networks ) );
145 scores[ j ] = node->counters[ i ]; 145 scores[ j ] = node->counters[ i ];
@@ -158,7 +158,7 @@ static size_t stats_return_busy_networks( char * reply ) {
158 memset( networks, 0, sizeof( *networks ) * 256 ); 158 memset( networks, 0, sizeof( *networks ) * 256 );
159 159
160 stats_get_highscore_networks( stats_network_counters_root, 0, node_value, scores, networks, 256 ); 160 stats_get_highscore_networks( stats_network_counters_root, 0, node_value, scores, networks, 256 );
161 161
162 for( i=255; i>=0; --i) { 162 for( i=255; i>=0; --i) {
163 r += sprintf( r, "%08i: ", scores[i] ); 163 r += sprintf( r, "%08i: ", scores[i] );
164 r += fmt_ip6c( r, networks[i] ); 164 r += fmt_ip6c( r, networks[i] );
@@ -195,10 +195,10 @@ size_t stats_top10_txt( char * reply ) {
195 ot_record top10s[10], top10c[10]; 195 ot_record top10s[10], top10c[10];
196 char *r = reply, hex_out[42]; 196 char *r = reply, hex_out[42];
197 int idx, bucket; 197 int idx, bucket;
198 198
199 byte_zero( top10s, sizeof( top10s ) ); 199 byte_zero( top10s, sizeof( top10s ) );
200 byte_zero( top10c, sizeof( top10c ) ); 200 byte_zero( top10c, sizeof( top10c ) );
201 201
202 for( bucket=0; bucket<OT_BUCKET_COUNT; ++bucket ) { 202 for( bucket=0; bucket<OT_BUCKET_COUNT; ++bucket ) {
203 ot_vector *torrents_list = mutex_bucket_lock( bucket ); 203 ot_vector *torrents_list = mutex_bucket_lock( bucket );
204 for( j=0; j<torrents_list->size; ++j ) { 204 for( j=0; j<torrents_list->size; ++j ) {
@@ -220,7 +220,7 @@ size_t stats_top10_txt( char * reply ) {
220 if( !g_opentracker_running ) 220 if( !g_opentracker_running )
221 return 0; 221 return 0;
222 } 222 }
223 223
224 r += sprintf( r, "Top 10 torrents by peers:\n" ); 224 r += sprintf( r, "Top 10 torrents by peers:\n" );
225 for( idx=0; idx<10; ++idx ) 225 for( idx=0; idx<10; ++idx )
226 if( top10c[idx].torrent ) 226 if( top10c[idx].torrent )
@@ -229,7 +229,7 @@ size_t stats_top10_txt( char * reply ) {
229 for( idx=0; idx<10; ++idx ) 229 for( idx=0; idx<10; ++idx )
230 if( top10s[idx].torrent ) 230 if( top10s[idx].torrent )
231 r += sprintf( r, "\t%zd\t%s\n", top10s[idx].val, to_hex( hex_out, top10s[idx].torrent->hash) ); 231 r += sprintf( r, "\t%zd\t%s\n", top10s[idx].val, to_hex( hex_out, top10s[idx].torrent->hash) );
232 232
233 return r - reply; 233 return r - reply;
234} 234}
235 235
@@ -237,23 +237,23 @@ size_t stats_top10_txt( char * reply ) {
237 malloc blocks 237 malloc blocks
238 */ 238 */
239static size_t stats_slash24s_txt( char * reply, size_t amount, uint32_t thresh ) { 239static size_t stats_slash24s_txt( char * reply, size_t amount, uint32_t thresh ) {
240 240
241#define NUM_TOPBITS 12 241#define NUM_TOPBITS 12
242#define NUM_LOWBITS (24-NUM_TOPBITS) 242#define NUM_LOWBITS (24-NUM_TOPBITS)
243#define NUM_BUFS (1<<NUM_TOPBITS) 243#define NUM_BUFS (1<<NUM_TOPBITS)
244#define NUM_S24S (1<<NUM_LOWBITS) 244#define NUM_S24S (1<<NUM_LOWBITS)
245#define MSK_S24S (NUM_S24S-1) 245#define MSK_S24S (NUM_S24S-1)
246 246
247 uint32_t *counts[ NUM_BUFS ]; 247 uint32_t *counts[ NUM_BUFS ];
248 uint32_t slash24s[amount*2]; /* first dword amount, second dword subnet */ 248 uint32_t slash24s[amount*2]; /* first dword amount, second dword subnet */
249 size_t i, j, k, l; 249 size_t i, j, k, l;
250 char *r = reply; 250 char *r = reply;
251 251
252 byte_zero( counts, sizeof( counts ) ); 252 byte_zero( counts, sizeof( counts ) );
253 byte_zero( slash24s, amount * 2 * sizeof(uint32_t) ); 253 byte_zero( slash24s, amount * 2 * sizeof(uint32_t) );
254 254
255 r += sprintf( r, "Stats for all /24s with more than %u announced torrents:\n\n", thresh ); 255 r += sprintf( r, "Stats for all /24s with more than %u announced torrents:\n\n", thresh );
256 256
257#if 0 257#if 0
258 /* XXX: TOOD: Doesn't work yet with new peer storage model */ 258 /* XXX: TOOD: Doesn't work yet with new peer storage model */
259 for( bucket=0; bucket<OT_BUCKET_COUNT; ++bucket ) { 259 for( bucket=0; bucket<OT_BUCKET_COUNT; ++bucket ) {
@@ -284,7 +284,7 @@ static size_t stats_slash24s_txt( char * reply, size_t amount, uint32_t thresh )
284 goto bailout_cleanup; 284 goto bailout_cleanup;
285 } 285 }
286#endif 286#endif
287 287
288 k = l = 0; /* Debug: count allocated bufs */ 288 k = l = 0; /* Debug: count allocated bufs */
289 for( i=0; i < NUM_BUFS; ++i ) { 289 for( i=0; i < NUM_BUFS; ++i ) {
290 uint32_t *count = counts[i]; 290 uint32_t *count = counts[i];
@@ -308,20 +308,20 @@ static size_t stats_slash24s_txt( char * reply, size_t amount, uint32_t thresh )
308 } 308 }
309 free( count ); 309 free( count );
310 } 310 }
311 311
312 r += sprintf( r, "Allocated bufs: %zd, used s24s: %zd\n", k, l ); 312 r += sprintf( r, "Allocated bufs: %zd, used s24s: %zd\n", k, l );
313 313
314 for( i=0; i < amount; ++i ) 314 for( i=0; i < amount; ++i )
315 if( slash24s[ 2*i ] >= thresh ) { 315 if( slash24s[ 2*i ] >= thresh ) {
316 uint32_t ip = slash24s[ 2*i +1 ]; 316 uint32_t ip = slash24s[ 2*i +1 ];
317 r += sprintf( r, "% 10ld %d.%d.%d.0/24\n", (long)slash24s[ 2*i ], (int)(ip >> 16), (int)(255 & ( ip >> 8 )), (int)(ip & 255) ); 317 r += sprintf( r, "% 10ld %d.%d.%d.0/24\n", (long)slash24s[ 2*i ], (int)(ip >> 16), (int)(255 & ( ip >> 8 )), (int)(ip & 255) );
318 } 318 }
319 319
320 return r - reply; 320 return r - reply;
321 321
322 for( i=0; i < NUM_BUFS; ++i ) 322 for( i=0; i < NUM_BUFS; ++i )
323 free( counts[i] ); 323 free( counts[i] );
324 324
325 return 0; 325 return 0;
326} 326}
327 327
@@ -395,9 +395,9 @@ static size_t stats_fullscrapes_mrtg( char * reply ) {
395 395
396static size_t stats_peers_mrtg( char * reply ) { 396static size_t stats_peers_mrtg( char * reply ) {
397 torrent_stats stats = {0,0,0}; 397 torrent_stats stats = {0,0,0};
398 398
399 iterate_all_torrents( torrent_statter, (uintptr_t)&stats ); 399 iterate_all_torrents( torrent_statter, (uintptr_t)&stats );
400 400
401 return sprintf( reply, "%llu\n%llu\nopentracker serving %llu torrents\nopentracker", 401 return sprintf( reply, "%llu\n%llu\nopentracker serving %llu torrents\nopentracker",
402 stats.peer_count, 402 stats.peer_count,
403 stats.seed_count, 403 stats.seed_count,
@@ -408,7 +408,7 @@ static size_t stats_peers_mrtg( char * reply ) {
408static size_t stats_torrents_mrtg( char * reply ) 408static size_t stats_torrents_mrtg( char * reply )
409{ 409{
410 size_t torrent_count = mutex_get_torrent_count(); 410 size_t torrent_count = mutex_get_torrent_count();
411 411
412 return sprintf( reply, "%zd\n%zd\nopentracker serving %zd torrents\nopentracker", 412 return sprintf( reply, "%zd\n%zd\nopentracker serving %zd torrents\nopentracker",
413 torrent_count, 413 torrent_count,
414 (size_t)0, 414 (size_t)0,
@@ -426,7 +426,7 @@ static size_t stats_httperrors_txt ( char * reply ) {
426static size_t stats_return_renew_bucket( char * reply ) { 426static size_t stats_return_renew_bucket( char * reply ) {
427 char *r = reply; 427 char *r = reply;
428 int i; 428 int i;
429 429
430 for( i=0; i<OT_PEER_TIMEOUT; ++i ) 430 for( i=0; i<OT_PEER_TIMEOUT; ++i )
431 r+=sprintf(r,"%02i %llu\n", i, ot_renewed[i] ); 431 r+=sprintf(r,"%02i %llu\n", i, ot_renewed[i] );
432 return r - reply; 432 return r - reply;
@@ -526,12 +526,12 @@ size_t return_stats_for_tracker( char *reply, int mode, int format ) {
526 526
527static void stats_make( int *iovec_entries, struct iovec **iovector, ot_tasktype mode ) { 527static void stats_make( int *iovec_entries, struct iovec **iovector, ot_tasktype mode ) {
528 char *r; 528 char *r;
529 529
530 *iovec_entries = 0; 530 *iovec_entries = 0;
531 *iovector = NULL; 531 *iovector = NULL;
532 if( !( r = iovec_increase( iovec_entries, iovector, OT_STATS_TMPSIZE ) ) ) 532 if( !( r = iovec_increase( iovec_entries, iovector, OT_STATS_TMPSIZE ) ) )
533 return; 533 return;
534 534
535 switch( mode & TASK_TASK_MASK ) { 535 switch( mode & TASK_TASK_MASK ) {
536 case TASK_STATS_TORRENTS: r += stats_torrents_mrtg( r ); break; 536 case TASK_STATS_TORRENTS: r += stats_torrents_mrtg( r ); break;
537 case TASK_STATS_PEERS: r += stats_peers_mrtg( r ); break; 537 case TASK_STATS_PEERS: r += stats_peers_mrtg( r ); break;
@@ -607,9 +607,9 @@ void stats_issue_event( ot_status_event event, PROTO_FLAG proto, uintptr_t event
607static void * stats_worker( void * args ) { 607static void * stats_worker( void * args ) {
608 int iovec_entries; 608 int iovec_entries;
609 struct iovec *iovector; 609 struct iovec *iovector;
610 610
611 args = args; 611 args = args;
612 612
613 while( 1 ) { 613 while( 1 ) {
614 ot_tasktype tasktype = TASK_STATS; 614 ot_tasktype tasktype = TASK_STATS;
615 ot_taskid taskid = mutex_workqueue_poptask( &tasktype ); 615 ot_taskid taskid = mutex_workqueue_poptask( &tasktype );