Changeset 740
- Timestamp:
- 03/03/08 05:08:36 (6 months ago)
- Files:
-
- trunk/server/items.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/server/items.c
r739 r740 28 28 29 29 #define LARGEST_ID 255 30 typedef struct { 31 unsigned int evicted; 32 unsigned int outofmemory; 33 } itemstats_t; 34 30 35 static item *heads[LARGEST_ID]; 31 36 static item *tails[LARGEST_ID]; 37 static itemstats_t itemstats[LARGEST_ID]; 32 38 static unsigned int sizes[LARGEST_ID]; 33 39 34 40 void item_init(void) { 35 41 int i; 42 memset(itemstats, 0, sizeof(itemstats_t) * LARGEST_ID); 36 43 for(i = 0; i < LARGEST_ID; i++) { 37 44 heads[i] = NULL; … … 98 105 */ 99 106 100 if (settings.evict_to_free == 0) return NULL; 107 if (settings.evict_to_free == 0) { 108 itemstats[id].outofmemory++; 109 return NULL; 110 } 101 111 102 112 /* … … 107 117 */ 108 118 109 if (tails[id] == 0) return NULL; 119 if (tails[id] == 0) { 120 itemstats[id].outofmemory++; 121 return NULL; 122 } 110 123 111 124 for (search = tails[id]; tries > 0 && search != NULL; tries--, search=search->prev) { 112 125 if (search->refcount == 0) { 113 if (search->exptime == 0 || search->exptime > current_time) { 114 STATS_LOCK(); 115 stats.evictions++; 116 STATS_UNLOCK(); 126 if (search->exptime == 0 || search->exptime > current_time) { 127 itemstats[id].evicted++; 128 STATS_LOCK(); 129 stats.evictions++; 130 STATS_UNLOCK(); 117 131 } 118 132 do_item_unlink(search); … … 121 135 } 122 136 it = slabs_alloc(ntotal, id); 123 if (it == 0) return NULL; 137 if (it == 0) { 138 itemstats[id].outofmemory++; 139 return NULL; 140 } 124 141 } 125 142 … … 312 329 313 330 char *do_item_stats(int *bytes) { 314 size_t bufleft = (size_t) LARGEST_ID * 80;331 size_t bufleft = (size_t) LARGEST_ID * 160; 315 332 char *buffer = malloc(bufleft); 316 333 char *bufcurr = buffer; … … 325 342 for (i = 0; i < LARGEST_ID; i++) { 326 343 if (tails[i] != NULL) { 327 linelen = snprintf(bufcurr, bufleft, "STAT items:%d:number %u\r\nSTAT items:%d:age %u\r\n", 328 i, sizes[i], i, now - tails[i]->time); 344 linelen = snprintf(bufcurr, bufleft, 345 "STAT items:%d:number %u\r\n" 346 "STAT items:%d:age %u\r\n" 347 "STAT items:%d:evicted %u\r\n" 348 "STAT items:%d:outofmemory %u\r\n", 349 i, sizes[i], i, now - tails[i]->time, i, 350 itemstats[i].evicted, i, itemstats[i].outofmemory); 329 351 if (linelen + sizeof("END\r\n") < bufleft) { 330 352 bufcurr += linelen;
