1
0
Fork 0

disable internal statistics by default

This commit is contained in:
Jan Steemann 2012-10-16 17:43:11 +02:00
parent 5efbc9cb07
commit f0b615ab9e
4 changed files with 113 additions and 4 deletions

View File

@ -59,7 +59,9 @@ static void AddNewElement (TRI_associative_array_t* array, void* element) {
while (! array->isEmptyElement(array, array->_table + i * array->_elementSize)) {
i = (i + 1) % array->_nrAlloc;
#ifdef TRI_INTERNAL_STATS
array->_nrProbesR++;
#endif
}
// add a new element to the associative array
@ -80,7 +82,9 @@ static void ResizeAssociativeArray (TRI_associative_array_t* array) {
oldAlloc = array->_nrAlloc;
array->_nrAlloc = 2 * array->_nrAlloc + 1;
#ifdef TRI_INTERNAL_STATS
array->_nrResizes++;
#endif
array->_table = TRI_Allocate(array->_memoryZone, array->_nrAlloc * array->_elementSize, true);
@ -162,6 +166,8 @@ void TRI_InitAssociativeArray (TRI_associative_array_t* array,
}
array->_nrUsed = 0;
#ifdef TRI_INTERNAL_STATS
array->_nrFinds = 0;
array->_nrAdds = 0;
array->_nrRems = 0;
@ -170,6 +176,7 @@ void TRI_InitAssociativeArray (TRI_associative_array_t* array,
array->_nrProbesA = 0;
array->_nrProbesD = 0;
array->_nrProbesR = 0;
#endif
}
////////////////////////////////////////////////////////////////////////////////
@ -214,14 +221,18 @@ void* TRI_LookupByKeyAssociativeArray (TRI_associative_array_t* array, void* key
hash = array->hashKey(array, key);
i = hash % array->_nrAlloc;
#ifdef TRI_INTERNAL_STATS
// update statistics
array->_nrFinds++;
#endif
// search the table
while (! array->isEmptyElement(array, array->_table + i * array->_elementSize)
&& ! array->isEqualKeyElement(array, key, array->_table + i * array->_elementSize)) {
i = (i + 1) % array->_nrAlloc;
#ifdef TRI_INTERNAL_STATS
array->_nrProbesF++;
#endif
}
// return whatever we found
@ -256,14 +267,18 @@ void* TRI_LookupByElementAssociativeArray (TRI_associative_array_t* array, void*
hash = array->hashElement(array, element);
i = hash % array->_nrAlloc;
#ifdef TRI_INTERNAL_STATS
// update statistics
array->_nrFinds++;
#endif
// search the table
while (! array->isEmptyElement(array, array->_table + i * array->_elementSize)
&& ! array->isEqualElementElement(array, element, array->_table + i * array->_elementSize)) {
i = (i + 1) % array->_nrAlloc;
#ifdef TRI_INTERNAL_STATS
array->_nrProbesF++;
#endif
}
// return whatever we found
@ -304,14 +319,18 @@ bool TRI_InsertElementAssociativeArray (TRI_associative_array_t* array, void* el
hash = array->hashElement(array, element);
i = hash % array->_nrAlloc;
#ifdef TRI_INTERNAL_STATS
// update statistics
array->_nrAdds++;
#endif
// search the table
while (! array->isEmptyElement(array, array->_table + i * array->_elementSize)
&& ! array->isEqualElementElement(array, element, array->_table + i * array->_elementSize)) {
i = (i + 1) % array->_nrAlloc;
#ifdef TRI_INTERNAL_STATS
array->_nrProbesA++;
#endif
}
// if we found an element, return
@ -353,14 +372,18 @@ bool TRI_InsertKeyAssociativeArray (TRI_associative_array_t* array, void* key, v
hash = array->hashKey(array, key);
i = hash % array->_nrAlloc;
#ifdef TRI_INTERNAL_STATS
// update statistics
array->_nrAdds++;
#endif
// search the table
while (! array->isEmptyElement(array, array->_table + i * array->_elementSize)
&& ! array->isEqualKeyElement(array, key, array->_table + i * array->_elementSize)) {
i = (i + 1) % array->_nrAlloc;
#ifdef TRI_INTERNAL_STATS
array->_nrProbesA++;
#endif
}
// if we found an element, return
@ -396,14 +419,18 @@ bool TRI_RemoveElementAssociativeArray (TRI_associative_array_t* array, void* el
hash = array->hashElement(array, element);
i = hash % array->_nrAlloc;
#ifdef TRI_INTERNAL_STATS
// update statistics
array->_nrRems++;
#endif
// search the table
while (! array->isEmptyElement(array, array->_table + i * array->_elementSize)
&& ! array->isEqualElementElement(array, element, array->_table + i * array->_elementSize)) {
i = (i + 1) % array->_nrAlloc;
#ifdef TRI_INTERNAL_STATS
array->_nrProbesD++;
#endif
}
// if we did not find such an item return false
@ -454,14 +481,18 @@ bool TRI_RemoveKeyAssociativeArray (TRI_associative_array_t* array, void* key, v
hash = array->hashKey(array, key);
i = hash % array->_nrAlloc;
#ifdef TRI_INTERNAL_STATS
// update statistics
array->_nrRems++;
#endif
// search the table
while (! array->isEmptyElement(array, array->_table + i * array->_elementSize)
&& ! array->isEqualKeyElement(array, key, array->_table + i * array->_elementSize)) {
i = (i + 1) % array->_nrAlloc;
#ifdef TRI_INTERNAL_STATS
array->_nrProbesD++;
#endif
}
// if we did not find such an item return false
@ -541,7 +572,9 @@ static void AddNewElementPointer (TRI_associative_pointer_t* array, void* elemen
while (array->_table[i] != NULL) {
i = (i + 1) % array->_nrAlloc;
#ifdef TRI_INTERNAL_STATS
array->_nrProbesR++;
#endif
}
// add a new element to the associative array
@ -562,7 +595,9 @@ static void ResizeAssociativePointer (TRI_associative_pointer_t* array) {
oldAlloc = array->_nrAlloc;
array->_nrAlloc = 2 * array->_nrAlloc + 1;
#ifdef TRI_INTERNAL_STATS
array->_nrResizes++;
#endif
array->_table = TRI_Allocate(array->_memoryZone, array->_nrAlloc * sizeof(void*), true);
@ -623,6 +658,8 @@ void TRI_InitAssociativePointer (TRI_associative_pointer_t* array,
}
array->_nrUsed = 0;
#ifdef TRI_INTERNAL_STATS
array->_nrFinds = 0;
array->_nrAdds = 0;
array->_nrRems = 0;
@ -631,6 +668,7 @@ void TRI_InitAssociativePointer (TRI_associative_pointer_t* array,
array->_nrProbesA = 0;
array->_nrProbesD = 0;
array->_nrProbesR = 0;
#endif
}
////////////////////////////////////////////////////////////////////////////////
@ -695,13 +733,17 @@ void* TRI_LookupByKeyAssociativePointer (TRI_associative_pointer_t* array,
hash = array->hashKey(array, key);
i = hash % array->_nrAlloc;
#ifdef TRI_INTERNAL_STATS
// update statistics
array->_nrFinds++;
#endif
// search the table
while (array->_table[i] != NULL && ! array->isEqualKeyElement(array, key, array->_table[i])) {
i = (i + 1) % array->_nrAlloc;
#ifdef TRI_INTERNAL_STATS
array->_nrProbesF++;
#endif
}
// return whatever we found
@ -721,13 +763,17 @@ void* TRI_LookupByElementAssociativePointer (TRI_associative_pointer_t* array,
hash = array->hashElement(array, element);
i = hash % array->_nrAlloc;
#ifdef TRI_INTERNAL_STATS
// update statistics
array->_nrFinds++;
#endif
// search the table
while (array->_table[i] != NULL && ! array->isEqualElementElement(array, element, array->_table[i])) {
i = (i + 1) % array->_nrAlloc;
#ifdef TRI_INTERNAL_STATS
array->_nrProbesF++;
#endif
}
// return whatever we found
@ -755,13 +801,17 @@ void* TRI_InsertElementAssociativePointer (TRI_associative_pointer_t* array,
hash = array->hashElement(array, element);
i = hash % array->_nrAlloc;
#ifdef TRI_INTERNAL_STATS
// update statistics
array->_nrAdds++;
#endif
// search the table
while (array->_table[i] != NULL && ! array->isEqualElementElement(array, element, array->_table[i])) {
i = (i + 1) % array->_nrAlloc;
#ifdef TRI_INTERNAL_STATS
array->_nrProbesA++;
#endif
}
old = array->_table[i];
@ -809,13 +859,17 @@ void* TRI_InsertKeyAssociativePointer (TRI_associative_pointer_t* array,
hash = array->hashKey(array, key);
i = hash % array->_nrAlloc;
#ifdef TRI_INTERNAL_STATS
// update statistics
array->_nrAdds++;
#endif
// search the table
while (array->_table[i] != NULL && ! array->isEqualKeyElement(array, key, array->_table[i])) {
i = (i + 1) % array->_nrAlloc;
#ifdef TRI_INTERNAL_STATS
array->_nrProbesA++;
#endif
}
old = array->_table[i];
@ -855,13 +909,17 @@ void* TRI_RemoveElementAssociativePointer (TRI_associative_pointer_t* array,
hash = array->hashElement(array, element);
i = hash % array->_nrAlloc;
#ifdef TRI_INTERNAL_STATS
// update statistics
array->_nrRems++;
#endif
// search the table
while (array->_table[i] != NULL && ! array->isEqualElementElement(array, element, array->_table[i])) {
i = (i + 1) % array->_nrAlloc;
#ifdef TRI_INTERNAL_STATS
array->_nrProbesD++;
#endif
}
// if we did not find such an item return 0
@ -907,13 +965,17 @@ void* TRI_RemoveKeyAssociativePointer (TRI_associative_pointer_t* array,
hash = array->hashKey(array, key);
i = hash % array->_nrAlloc;
#ifdef TRI_INTERNAL_STATS
// update statistics
array->_nrRems++;
#endif
// search the table
while (array->_table[i] != NULL && ! array->isEqualKeyElement(array, key, array->_table[i])) {
i = (i + 1) % array->_nrAlloc;
#ifdef TRI_INTERNAL_STATS
array->_nrProbesD++;
#endif
}
// if we did not find such an item return false
@ -988,7 +1050,9 @@ static void AddNewElementSynced (TRI_associative_synced_t* array, void* element)
while (array->_table[i] != NULL) {
i = (i + 1) % array->_nrAlloc;
#ifdef TRI_INTERNAL_STATS
array->_nrProbesR++;
#endif
}
// add a new element to the associative array
@ -1011,7 +1075,9 @@ static void ResizeAssociativeSynced (TRI_associative_synced_t* array) {
oldAlloc = array->_nrAlloc;
array->_nrAlloc = 2 * array->_nrAlloc + 1;
#ifdef TRI_INTERNAL_STATS
array->_nrResizes++;
#endif
array->_table = TRI_Allocate(array->_memoryZone, array->_nrAlloc * sizeof(void*), true);
@ -1072,6 +1138,8 @@ void TRI_InitAssociativeSynced (TRI_associative_synced_t* array,
}
array->_nrUsed = 0;
#ifdef TRI_INTERNAL_STATS
array->_nrFinds = 0;
array->_nrAdds = 0;
array->_nrRems = 0;
@ -1080,6 +1148,7 @@ void TRI_InitAssociativeSynced (TRI_associative_synced_t* array,
array->_nrProbesA = 0;
array->_nrProbesD = 0;
array->_nrProbesR = 0;
#endif
TRI_InitReadWriteLock(&array->_lock);
}
@ -1129,15 +1198,19 @@ void const* TRI_LookupByKeyAssociativeSynced (TRI_associative_synced_t* array,
hash = array->hashKey(array, key);
i = hash % array->_nrAlloc;
#ifdef TRI_INTERNAL_STATS
// update statistics
array->_nrFinds++;
#endif
// search the table
TRI_ReadLockReadWriteLock(&array->_lock);
while (array->_table[i] != NULL && ! array->isEqualKeyElement(array, key, array->_table[i])) {
i = (i + 1) % array->_nrAlloc;
#ifdef TRI_INTERNAL_STATS
array->_nrProbesF++;
#endif
}
result = array->_table[i];
@ -1162,15 +1235,19 @@ void const* TRI_LookupByElementAssociativeSynced (TRI_associative_synced_t* arra
hash = array->hashElement(array, element);
i = hash % array->_nrAlloc;
#ifdef TRI_INTERNAL_STATS
// update statistics
array->_nrFinds++;
#endif
// search the table
TRI_ReadLockReadWriteLock(&array->_lock);
while (array->_table[i] != NULL && ! array->isEqualElementElement(array, element, array->_table[i])) {
i = (i + 1) % array->_nrAlloc;
#ifdef TRI_INTERNAL_STATS
array->_nrProbesF++;
#endif
}
result = array->_table[i];
@ -1201,15 +1278,19 @@ void* TRI_InsertElementAssociativeSynced (TRI_associative_synced_t* array,
hash = array->hashElement(array, element);
i = hash % array->_nrAlloc;
#ifdef TRI_INTERNAL_STATS
// update statistics
array->_nrAdds++;
#endif
// search the table, TODO optimise the locks
TRI_WriteLockReadWriteLock(&array->_lock);
while (array->_table[i] != NULL && ! array->isEqualElementElement(array, element, array->_table[i])) {
i = (i + 1) % array->_nrAlloc;
#ifdef TRI_INTERNAL_STATS
array->_nrProbesA++;
#endif
}
old = array->_table[i];
@ -1254,15 +1335,19 @@ void* TRI_InsertKeyAssociativeSynced (TRI_associative_synced_t* array,
hash = array->hashKey(array, key);
i = hash % array->_nrAlloc;
#ifdef TRI_INTERNAL_STATS
// update statistics
array->_nrAdds++;
#endif
// search the table
TRI_WriteLockReadWriteLock(&array->_lock);
while (array->_table[i] != NULL && ! array->isEqualKeyElement(array, key, array->_table[i])) {
i = (i + 1) % array->_nrAlloc;
#ifdef TRI_INTERNAL_STATS
array->_nrProbesA++;
#endif
}
old = array->_table[i];
@ -1300,15 +1385,19 @@ void* TRI_RemoveElementAssociativeSynced (TRI_associative_synced_t* array,
hash = array->hashElement(array, element);
i = hash % array->_nrAlloc;
#ifdef TRI_INTERNAL_STATS
// update statistics
array->_nrRems++;
#endif
// search the table
TRI_WriteLockReadWriteLock(&array->_lock);
while (array->_table[i] != NULL && ! array->isEqualElementElement(array, element, array->_table[i])) {
i = (i + 1) % array->_nrAlloc;
#ifdef TRI_INTERNAL_STATS
array->_nrProbesD++;
#endif
}
// if we did not find such an item return 0
@ -1356,15 +1445,19 @@ void* TRI_RemoveKeyAssociativeSynced (TRI_associative_synced_t* array,
hash = array->hashKey(array, key);
i = hash % array->_nrAlloc;
#ifdef TRI_INTERNAL_STATS
// update statistics
array->_nrRems++;
#endif
// search the table
TRI_WriteLockReadWriteLock(&array->_lock);
while (array->_table[i] != NULL && ! array->isEqualKeyElement(array, key, array->_table[i])) {
i = (i + 1) % array->_nrAlloc;
#ifdef TRI_INTERNAL_STATS
array->_nrProbesD++;
#endif
}
// if we did not find such an item return false

View File

@ -72,6 +72,7 @@ typedef struct TRI_associative_array_s {
char* _table; // the table itself
#ifdef TRI_INTERNAL_STATS
uint64_t _nrFinds; // statistics: number of lookup calls
uint64_t _nrAdds; // statistics: number of insert calls
uint64_t _nrRems; // statistics: number of remove calls
@ -81,6 +82,7 @@ typedef struct TRI_associative_array_s {
uint64_t _nrProbesA; // statistics: number of misses while inserting
uint64_t _nrProbesD; // statistics: number of misses while removing
uint64_t _nrProbesR; // statistics: number of misses while adding
#endif
TRI_memory_zone_t* _memoryZone;
}
@ -225,6 +227,7 @@ typedef struct TRI_associative_pointer_s {
void** _table; // the table itself
#ifdef TRI_INTERNAL_STATS
uint64_t _nrFinds; // statistics: number of lookup calls
uint64_t _nrAdds; // statistics: number of insert calls
uint64_t _nrRems; // statistics: number of remove calls
@ -234,6 +237,7 @@ typedef struct TRI_associative_pointer_s {
uint64_t _nrProbesA; // statistics: number of misses while inserting
uint64_t _nrProbesD; // statistics: number of misses while removing
uint64_t _nrProbesR; // statistics: number of misses while adding
#endif
TRI_memory_zone_t* _memoryZone;
}
@ -379,6 +383,7 @@ typedef struct TRI_associative_synced_s {
TRI_read_write_lock_t _lock;
#ifdef TRI_INTERNAL_STATS
uint64_t _nrFinds; // statistics: number of lookup calls
uint64_t _nrAdds; // statistics: number of insert calls
uint64_t _nrRems; // statistics: number of remove calls
@ -388,6 +393,7 @@ typedef struct TRI_associative_synced_s {
uint64_t _nrProbesA; // statistics: number of misses while inserting
uint64_t _nrProbesD; // statistics: number of misses while removing
uint64_t _nrProbesR; // statistics: number of misses while adding
#endif
TRI_memory_zone_t* _memoryZone;
}

View File

@ -75,8 +75,15 @@ void TRI_InitVector (TRI_vector_t* vector, TRI_memory_zone_t* zone, size_t eleme
vector->_growthFactor = GROW_FACTOR;
}
int TRI_InitVector2 (TRI_vector_t* vector, TRI_memory_zone_t* zone, size_t elementSize,
size_t initialCapacity, double growthFactor) {
////////////////////////////////////////////////////////////////////////////////
/// @brief initialises a vector, with user-definable settings
////////////////////////////////////////////////////////////////////////////////
int TRI_InitVector2 (TRI_vector_t* vector,
TRI_memory_zone_t* zone,
size_t elementSize,
size_t initialCapacity,
double growthFactor) {
vector->_memoryZone = zone;
vector->_elementSize = elementSize;
vector->_buffer = NULL;

View File

@ -81,8 +81,11 @@ TRI_vector_t;
void TRI_InitVector (TRI_vector_t*, TRI_memory_zone_t*, size_t elementSize);
int TRI_InitVector2 (TRI_vector_t*, TRI_memory_zone_t*, size_t elementSize,
size_t initialCapacity, double growthFactor);
int TRI_InitVector2 (TRI_vector_t*,
TRI_memory_zone_t*,
size_t elementSize,
size_t initialCapacity,
double growthFactor);
////////////////////////////////////////////////////////////////////////////////
/// @brief destroys a vector, but does not free the pointer