Added more counters and fixed previous ones
This commit is contained in:
parent
68e933e08a
commit
8787229004
15
src/sfxd.c
15
src/sfxd.c
|
@ -73,8 +73,10 @@ struct sfx_pool sounds_pool = { 0, 0, 0 };
|
||||||
struct global_counters {
|
struct global_counters {
|
||||||
uint64_t pool_read;
|
uint64_t pool_read;
|
||||||
uint64_t pool_write;
|
uint64_t pool_write;
|
||||||
uint64_t hash_misses_write;
|
|
||||||
uint64_t hash_misses_read;
|
uint64_t hash_misses_read;
|
||||||
|
uint64_t hash_misses_write;
|
||||||
|
uint64_t hash_misses_read_acc;
|
||||||
|
uint64_t hash_misses_write_acc;
|
||||||
} global_counters = { 0 };
|
} global_counters = { 0 };
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -303,6 +305,8 @@ void execute_command(struct msg_target tgt, const char *command, const char *par
|
||||||
send_txt(tgt, ".pool_write = %ld\n", global_counters.pool_write);
|
send_txt(tgt, ".pool_write = %ld\n", global_counters.pool_write);
|
||||||
send_txt(tgt, ".hash_misses_read = %ld\n", global_counters.hash_misses_read);
|
send_txt(tgt, ".hash_misses_read = %ld\n", global_counters.hash_misses_read);
|
||||||
send_txt(tgt, ".hash_misses_write = %ld\n", global_counters.hash_misses_write);
|
send_txt(tgt, ".hash_misses_write = %ld\n", global_counters.hash_misses_write);
|
||||||
|
send_txt(tgt, ".hash_misses_read_acc = %ld\n", global_counters.hash_misses_read_acc);
|
||||||
|
send_txt(tgt, ".hash_misses_write_acc = %ld\n", global_counters.hash_misses_write_acc);
|
||||||
send_txt(tgt, ".pool.use = %d\n", sounds_pool.use);
|
send_txt(tgt, ".pool.use = %d\n", sounds_pool.use);
|
||||||
send_txt(tgt, ".pool.cap = %d\n", sounds_pool.cap);
|
send_txt(tgt, ".pool.cap = %d\n", sounds_pool.cap);
|
||||||
#endif
|
#endif
|
||||||
|
@ -391,14 +395,15 @@ void sfx_pool_grow(int size) {
|
||||||
for (int i = 0; i < sounds_pool.cap; i++) {
|
for (int i = 0; i < sounds_pool.cap; i++) {
|
||||||
if (sounds_pool.sounds[i].key[0] == '\0') continue;
|
if (sounds_pool.sounds[i].key[0] == '\0') continue;
|
||||||
uint32_t new_hash = adler32(sounds_pool.sounds[i].key, strlen(sounds_pool.sounds[i].key));
|
uint32_t new_hash = adler32(sounds_pool.sounds[i].key, strlen(sounds_pool.sounds[i].key));
|
||||||
|
global_counters.pool_write++;
|
||||||
for (int offset = 0; offset < size; offset++) {
|
for (int offset = 0; offset < size; offset++) {
|
||||||
int index = (new_hash + offset) % size;
|
int index = (new_hash + offset) % size;
|
||||||
if (new_items[index].key[0] == '\0') {
|
if (new_items[index].key[0] == '\0') {
|
||||||
#ifndef NO_COUNTERS
|
#ifndef NO_COUNTERS
|
||||||
|
global_counters.hash_misses_write_acc++;
|
||||||
if (offset != 0) {
|
if (offset != 0) {
|
||||||
global_counters.hash_misses_write++;
|
global_counters.hash_misses_write++;
|
||||||
}
|
}
|
||||||
global_counters.pool_write++;
|
|
||||||
#endif
|
#endif
|
||||||
memcpy(&new_items[index], &sounds_pool.sounds[i], sizeof(struct sfx_pool_item));
|
memcpy(&new_items[index], &sounds_pool.sounds[i], sizeof(struct sfx_pool_item));
|
||||||
used++;
|
used++;
|
||||||
|
@ -416,11 +421,12 @@ void sfx_pool_grow(int size) {
|
||||||
struct sfx_pool_item *sfx_pool_lookup(const char *key) {
|
struct sfx_pool_item *sfx_pool_lookup(const char *key) {
|
||||||
if (key == NULL) return NULL;
|
if (key == NULL) return NULL;
|
||||||
uint32_t hash = adler32(key, strlen(key));
|
uint32_t hash = adler32(key, strlen(key));
|
||||||
|
global_counters.pool_read++;
|
||||||
for (int offset = 0; offset < sounds_pool.cap; offset++) {
|
for (int offset = 0; offset < sounds_pool.cap; offset++) {
|
||||||
int index = (hash + offset) % sounds_pool.cap;
|
int index = (hash + offset) % sounds_pool.cap;
|
||||||
if (0 == strncmp(key, sounds_pool.sounds[index].key, KEY_LENGTH)) {
|
if (0 == strncmp(key, sounds_pool.sounds[index].key, KEY_LENGTH)) {
|
||||||
#ifndef NO_COUNTERS
|
#ifndef NO_COUNTERS
|
||||||
global_counters.pool_read++;
|
global_counters.hash_misses_read_acc++;
|
||||||
if (offset != 0) {
|
if (offset != 0) {
|
||||||
global_counters.hash_misses_read++;
|
global_counters.hash_misses_read++;
|
||||||
}
|
}
|
||||||
|
@ -433,11 +439,12 @@ struct sfx_pool_item *sfx_pool_lookup(const char *key) {
|
||||||
|
|
||||||
struct sfx_pool_item *sfx_pool_find_place_for(const char *key) {
|
struct sfx_pool_item *sfx_pool_find_place_for(const char *key) {
|
||||||
uint32_t hash = adler32(key, strlen(key));
|
uint32_t hash = adler32(key, strlen(key));
|
||||||
|
global_counters.pool_write++;
|
||||||
for (int offset = 0; offset < sounds_pool.cap; offset++) {
|
for (int offset = 0; offset < sounds_pool.cap; offset++) {
|
||||||
int index = (hash + offset) % sounds_pool.cap;
|
int index = (hash + offset) % sounds_pool.cap;
|
||||||
if (sounds_pool.sounds[index].key[0] == '\0' || 0 == strncmp(sounds_pool.sounds[index].key, key, KEY_LENGTH)) {
|
if (sounds_pool.sounds[index].key[0] == '\0' || 0 == strncmp(sounds_pool.sounds[index].key, key, KEY_LENGTH)) {
|
||||||
#ifndef NO_COUNTERS
|
#ifndef NO_COUNTERS
|
||||||
global_counters.pool_write++;
|
global_counters.hash_misses_write_acc++;
|
||||||
if (offset != 0) {
|
if (offset != 0) {
|
||||||
global_counters.hash_misses_write++;
|
global_counters.hash_misses_write++;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue