#include <IgTools/IgProf/src/IgProfBuffer.h>
Protected Member Functions | |
template<class T> | |
T * | allocate (void) |
void * | allocateRaw (size_t size) |
void * | allocateSpace (size_t amount) |
IgProfBuffer (void) | |
Initialise a buffer. | |
void | unallocateRaw (void *p, size_t size) |
~IgProfBuffer (void) | |
Static Protected Member Functions | |
static uint32_t | hash (uintptr_t key) |
Private Member Functions | |
void | allocatePool (void) |
IgProfBuffer (IgProfBuffer &) | |
IgProfBuffer & | operator= (IgProfBuffer &) |
Private Attributes | |
char * | freeend_ |
char * | freestart_ |
void ** | poolcur_ |
void ** | poolfirst_ |
Definition at line 10 of file IgProfBuffer.h.
IgProfBuffer::IgProfBuffer | ( | void | ) | [protected] |
Initialise a buffer.
Definition at line 13 of file IgProfBuffer.cc.
References allocateRaw(), freeend_, freestart_, MEM_POOL_SIZE, poolcur_, and poolfirst_.
00014 : poolfirst_(0), 00015 poolcur_(0), 00016 freestart_(0), 00017 freeend_(0) 00018 { 00019 // Get the first pool and initialise the chain pointer to null. 00020 void *pool = allocateRaw(MEM_POOL_SIZE); 00021 poolfirst_ = poolcur_ = (void **) pool; 00022 *poolfirst_ = 0; 00023 00024 // Mark the rest free. 00025 freestart_ = (char *) pool + sizeof(void **); 00026 freeend_ = (char *) pool + MEM_POOL_SIZE; 00027 }
IgProfBuffer::~IgProfBuffer | ( | void | ) | [protected] |
Definition at line 29 of file IgProfBuffer.cc.
References MEM_POOL_SIZE, p, and poolfirst_.
00030 { 00031 void **p = poolfirst_; 00032 while (p) 00033 { 00034 void **next = (void **) *p; 00035 munmap(p, MEM_POOL_SIZE); 00036 p = next; 00037 } 00038 }
IgProfBuffer::IgProfBuffer | ( | IgProfBuffer & | ) | [private] |
T* IgProfBuffer::allocate | ( | void | ) | [inline, protected] |
Definition at line 29 of file IgProfBuffer.h.
References allocateSpace().
00030 { return static_cast<T *>(allocateSpace(sizeof(T))); }
Definition at line 62 of file IgProfBuffer.cc.
References allocateRaw(), freeend_, freestart_, MEM_POOL_SIZE, poolcur_, and poolfirst_.
Referenced by allocateSpace().
00063 { 00064 // Get a pool. If we don't have any pools yet, make this the first 00065 // one. If we have an existing pool, chain the new one into the 00066 // last one. Then make this the current and last pool and mark the 00067 // memory free. Note the pool memory is allocated all-zeroes. 00068 void **pool = (void **) allocateRaw(MEM_POOL_SIZE); 00069 00070 if (! poolfirst_) 00071 poolfirst_ = pool; 00072 00073 if (poolcur_) 00074 *poolcur_ = pool; 00075 00076 poolcur_ = pool; 00077 00078 freestart_ = (char *) pool + sizeof(void **); 00079 freeend_ = (char *) pool + MEM_POOL_SIZE; 00080 }
void * IgProfBuffer::allocateRaw | ( | size_t | size | ) | [protected] |
Definition at line 47 of file IgProfBuffer.cc.
References data, IgProf::debug(), and mmap.
Referenced by allocatePool(), IgProfBuffer(), and IgProfTrace::IgProfTrace().
00048 { 00049 void *data = mmap (0, size, PROT_READ | PROT_WRITE, 00050 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); 00051 if (data != MAP_FAILED) 00052 return data; 00053 else 00054 { 00055 IgProf::debug ("Failed to allocate memory for profile buffer: %s (%d)\n", 00056 strerror (errno), errno); 00057 abort (); 00058 } 00059 }
void* IgProfBuffer::allocateSpace | ( | size_t | amount | ) | [inline, protected] |
Definition at line 19 of file IgProfBuffer.h.
References allocatePool(), freeend_, freestart_, and IGPROF_ASSERT.
Referenced by allocate(), and IgProfTrace::IgProfTrace().
00020 { 00021 if (size_t(freeend_ - freestart_) < amount) 00022 allocatePool(); 00023 00024 IGPROF_ASSERT(size_t(freeend_ - freestart_) > amount); 00025 void *p = freestart_; 00026 freestart_ += amount; 00027 return p; 00028 }
static uint32_t IgProfBuffer::hash | ( | uintptr_t | key | ) | [inline, static, protected] |
Definition at line 32 of file IgProfBuffer.h.
Referenced by IgProfTrace::findResource(), IgProfSymCache::roundAddressToSymbol(), and IgProfSymCache::symbolForAddress().
00033 { 00034 // Reduced version of Bob Jenkins' hash function at: 00035 // https://www.burtleburtle.net/bob/c/lookup3.c 00036 // Simply converted to operate on known sized fixed 00037 // integral keys and no initial value (initval = 0). 00038 // 00039 // in the end get the bin with 2^BITS mask: 00040 // uint32_t bin = hash(key) & (((uint32_t)1 << BITS)-1); 00041 # define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k)))) 00042 uint32_t a, b, c; 00043 a = b = c = 0xdeadbeef + sizeof (key); 00044 b += key >> 32; // for 64-bit systems, may warn on 32-bit systems 00045 a += key & 0xffffffffU; 00046 c ^= b; c -= rot(b,14); 00047 a ^= c; a -= rot(c,11); 00048 b ^= a; b -= rot(a,25); 00049 c ^= b; c -= rot(b,16); 00050 a ^= c; a -= rot(c,4); 00051 b ^= a; b -= rot(a,14); 00052 c ^= b; c -= rot(b,24); 00053 return c; 00054 # undef rot 00055 }
IgProfBuffer& IgProfBuffer::operator= | ( | IgProfBuffer & | ) | [private] |
char* IgProfBuffer::freeend_ [private] |
Definition at line 63 of file IgProfBuffer.h.
Referenced by allocatePool(), allocateSpace(), and IgProfBuffer().
char* IgProfBuffer::freestart_ [private] |
Definition at line 62 of file IgProfBuffer.h.
Referenced by allocatePool(), allocateSpace(), and IgProfBuffer().
void** IgProfBuffer::poolcur_ [private] |
Reimplemented in IgProfTrace.
Definition at line 61 of file IgProfBuffer.h.
Referenced by allocatePool(), and IgProfBuffer().
void** IgProfBuffer::poolfirst_ [private] |
Reimplemented in IgProfTrace.
Definition at line 60 of file IgProfBuffer.h.
Referenced by allocatePool(), IgProfBuffer(), and ~IgProfBuffer().