… | |
… | |
111 | |
111 | |
112 | cache->id_size = id_size / 4; |
112 | cache->id_size = id_size / 4; |
113 | cache->entry_size = cache->id_size * sizeof(int) + sizeof(struct cache_entry); |
113 | cache->entry_size = cache->id_size * sizeof(int) + sizeof(struct cache_entry); |
114 | cache->size = size; |
114 | cache->size = size; |
115 | |
115 | |
|
|
116 | dbg(0, "_c id_size=%d\n", id_size); |
116 | dbg(0, "_c size=%d\n", size); |
117 | dbg(0, "_c size=%d\n", size); |
117 | |
118 | |
118 | switch (id_size) |
119 | switch (id_size) |
119 | { |
120 | { |
120 | case 4: |
121 | case 4: |
… | |
… | |
210 | void * |
211 | void * |
211 | cache_entry_new(struct cache *cache, void *id, int size) |
212 | cache_entry_new(struct cache *cache, void *id, int size) |
212 | { |
213 | { |
213 | struct cache_entry *ret; |
214 | struct cache_entry *ret; |
214 | size += cache->entry_size; |
215 | size += cache->entry_size; |
215 | cache->misses += size; |
216 | // cache->misses += size; |
|
|
217 | cache->misses += 1; |
216 | ret = (struct cache_entry *) g_slice_alloc0(size); |
218 | ret = (struct cache_entry *) g_slice_alloc0(size); |
217 | ret->size = size; |
219 | ret->size = size; |
218 | ret->usage = 1; |
220 | ret->usage = 1; |
219 | memcpy(ret->id, id, cache->id_size * sizeof(int)); |
221 | memcpy(ret->id, id, cache->id_size * sizeof(int)); |
220 | return &ret->id[cache->id_size]; |
222 | return &ret->id[cache->id_size]; |
… | |
… | |
326 | } |
328 | } |
327 | |
329 | |
328 | // dbg(1,"found 0x%x 0x%x 0x%x 0x%x 0x%x\n", entry->id[0], entry->id[1], entry->id[2], entry->id[3], entry->id[4]); |
330 | // dbg(1,"found 0x%x 0x%x 0x%x 0x%x 0x%x\n", entry->id[0], entry->id[1], entry->id[2], entry->id[3], entry->id[4]); |
329 | if (entry->where == &cache->t1 || entry->where == &cache->t2) |
331 | if (entry->where == &cache->t1 || entry->where == &cache->t2) |
330 | { |
332 | { |
331 | cache->hits += entry->size; |
333 | // cache->hits += entry->size; |
|
|
334 | cache->hits += 1; |
332 | #ifdef DEBUG_CACHE |
335 | #ifdef DEBUG_CACHE |
333 | if (entry->where == &cache->t1) |
336 | if (entry->where == &cache->t1) |
334 | { |
337 | { |
335 | fprintf(stderr,"h"); |
338 | fprintf(stderr,"h"); |
336 | } |
339 | } |
… | |
… | |
416 | } |
419 | } |
417 | |
420 | |
418 | void cache_stats(struct cache *cache) |
421 | void cache_stats(struct cache *cache) |
419 | { |
422 | { |
420 | unsigned long c_ratio = 0; |
423 | unsigned long c_ratio = 0; |
|
|
424 | //if ((cache->hits + cache->misses) > 0) |
|
|
425 | //{ |
|
|
426 | // c_ratio = (long) (cache->hits) * (long) (100L); |
|
|
427 | // //dbg(0,"1 c_ratio=%lu\n", c_ratio); |
|
|
428 | // c_ratio = c_ratio / (long) (cache->hits + cache->misses); |
|
|
429 | // //dbg(0,"2 c_ratio=%lu\n", c_ratio); |
|
|
430 | // |
|
|
431 | // dbg(0, "hits %d misses %lu hitratio %d size %d entry_size %d id_size %d T1 target %d\n", cache->hits, cache->misses, c_ratio, cache->size, cache->entry_size, cache->id_size, cache->t1_target); |
|
|
432 | // // dbg(0,"T1:%d B1:%d T2:%d B2:%d\n", cache->t1.size, cache->b1.size, cache->t2.size, cache->b2.size); |
|
|
433 | // |
|
|
434 | // // if numbers are too big, reset them |
|
|
435 | // if ((cache->hits > 1000000000) || (cache->misses > 1000000000)) |
|
|
436 | // { |
|
|
437 | // cache->hits = 0; |
|
|
438 | // cache->misses = 0; |
|
|
439 | // } |
|
|
440 | //} |
|
|
441 | |
421 | if ((cache->hits + cache->misses) > 0) |
442 | if ((cache->hits + cache->misses) > 0) |
422 | { |
443 | { |
423 | c_ratio = (long) (cache->hits) * (long) (100L); |
444 | c_ratio = (long) (cache->hits) * (long) (100L); |
424 | //dbg(0,"1 c_ratio=%lu\n", c_ratio); |
|
|
425 | c_ratio = c_ratio / (long) (cache->hits + cache->misses); |
445 | c_ratio = c_ratio / (long) (cache->hits + cache->misses); |
426 | //dbg(0,"2 c_ratio=%lu\n", c_ratio); |
|
|
427 | |
446 | |
428 | dbg(0, "hits %d misses %lu hitratio %d size %d entry_size %d id_size %d T1 target %d\n", cache->hits, cache->misses, c_ratio, cache->size, cache->entry_size, cache->id_size, cache->t1_target); |
447 | dbg(0, "hits %lu misses %lu hitratio %d size %d entry_size %d id_size %d T1 target %d\n", cache->hits, cache->misses, c_ratio, cache->size, cache->entry_size, cache->id_size, cache->t1_target); |
429 | // dbg(0,"T1:%d B1:%d T2:%d B2:%d\n", cache->t1.size, cache->b1.size, cache->t2.size, cache->b2.size); |
|
|
430 | |
448 | |
431 | // if numbers are too big, reset them |
449 | // if numbers are too big, reset them |
432 | if ((cache->hits > 1000000000) || (cache->misses > 1000000000)) |
450 | if ((cache->hits > 1000000000) || (cache->misses > 1000000000)) |
433 | { |
451 | { |
434 | cache->hits = 0; |
452 | cache->hits = 0; |
435 | cache->misses = 0; |
453 | cache->misses = 0; |
436 | } |
454 | } |
437 | } |
455 | } |
|
|
456 | |
|
|
457 | |
|
|
458 | |
438 | } |
459 | } |
439 | |
460 | |
440 | void cache_dump(struct cache *cache) |
461 | void cache_dump(struct cache *cache) |
441 | { |
462 | { |
442 | struct cache_entry *first; |
463 | struct cache_entry *first; |