introspection major optimization
This commit is contained in:
@@ -18,38 +18,23 @@
|
||||
*/
|
||||
|
||||
#include "piintrospection_containers_p.h"
|
||||
#include "piintrospection_containers.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef CC_GCC
|
||||
# include <cxxabi.h>
|
||||
const PIString demangle(const char * name) {
|
||||
int status = -4;
|
||||
char * res = abi::__cxa_demangle(name, NULL, NULL, &status);
|
||||
PIString ret((status == 0) ? res : name);
|
||||
free(res);
|
||||
return ret;
|
||||
}
|
||||
#else
|
||||
const PIString demangle(const char * name) {return PIString(name);}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
PIIntrospectionContainers::PIIntrospectionContainers() {
|
||||
//printf("PIIntrospectionContainers %p\n", this);
|
||||
}
|
||||
|
||||
|
||||
void PIIntrospectionContainers::containerNew(const char * tn, uint isz) {
|
||||
uint id = typeID(tn);
|
||||
PIMutexLocker _ml(mutex);
|
||||
void PIIntrospectionContainers::containerNew(const PIIntrospectionContainersType & ti, uint isz) {
|
||||
PISpinlockLocker _ml(mutex);
|
||||
//printf("containerNew lock\n");
|
||||
std::string & n(typenames[id]);
|
||||
_Type & d(data[id]);
|
||||
if (n.empty()) {
|
||||
n = tn;
|
||||
d.id = id;
|
||||
PIIntrospectionContainersType & t(types[ti.id]);
|
||||
_Type & d(data[ti.id]);
|
||||
if (!t.inited) {
|
||||
t = ti;
|
||||
d.id = ti.id;
|
||||
d.item_size = isz;
|
||||
}
|
||||
d.count++;
|
||||
@@ -57,49 +42,41 @@ void PIIntrospectionContainers::containerNew(const char * tn, uint isz) {
|
||||
}
|
||||
|
||||
|
||||
void PIIntrospectionContainers::containerDelete(const char * tn) {
|
||||
PIMutexLocker _ml(mutex);
|
||||
data[typeID(tn)].count--;
|
||||
void PIIntrospectionContainers::containerDelete(const PIIntrospectionContainersType & ti) {
|
||||
PISpinlockLocker _ml(mutex);
|
||||
data[ti.id].count--;
|
||||
}
|
||||
|
||||
|
||||
void PIIntrospectionContainers::containerAlloc(const char * tn, ullong cnt) {
|
||||
void PIIntrospectionContainers::containerAlloc(const PIIntrospectionContainersType & ti, ullong cnt) {
|
||||
//printf(" alloc %s %d\n", tn, cnt);
|
||||
if (cnt == 0) return;
|
||||
PIMutexLocker _ml(mutex);
|
||||
data[typeID(tn)].allocated += cnt;
|
||||
PISpinlockLocker _ml(mutex);
|
||||
data[ti.id].allocated += cnt;
|
||||
}
|
||||
|
||||
|
||||
void PIIntrospectionContainers::containerFree(const char * tn, ullong cnt) {
|
||||
void PIIntrospectionContainers::containerFree(const PIIntrospectionContainersType & ti, ullong cnt) {
|
||||
//printf(" free %s %d\n", tn, cnt);
|
||||
if (cnt == 0) return;
|
||||
PIMutexLocker _ml(mutex);
|
||||
data[typeID(tn)].allocated -= cnt;
|
||||
PISpinlockLocker _ml(mutex);
|
||||
data[ti.id].allocated -= cnt;
|
||||
}
|
||||
|
||||
|
||||
void PIIntrospectionContainers::containerUsed(const char * tn, ullong cnt) {
|
||||
void PIIntrospectionContainers::containerUsed(const PIIntrospectionContainersType & ti, ullong cnt) {
|
||||
//printf(" used %s %d\n", tn, cnt);
|
||||
if (cnt == 0) return;
|
||||
PIMutexLocker _ml(mutex);
|
||||
data[typeID(tn)].used += cnt;
|
||||
PISpinlockLocker _ml(mutex);
|
||||
data[ti.id].used += cnt;
|
||||
}
|
||||
|
||||
|
||||
void PIIntrospectionContainers::containerUnused(const char * tn, ullong cnt) {
|
||||
void PIIntrospectionContainers::containerUnused(const PIIntrospectionContainersType & ti, ullong cnt) {
|
||||
//printf("unused %s %d\n", tn, cnt);
|
||||
if (cnt == 0) return;
|
||||
PIMutexLocker _ml(mutex);
|
||||
data[typeID(tn)].used -= cnt;
|
||||
}
|
||||
|
||||
|
||||
uint PIIntrospectionContainers::typeID(const char * tn) {
|
||||
if (!tn) return 0u;
|
||||
size_t l = strlen(tn);
|
||||
if (l == 0) return 0u;
|
||||
return piHashData((const uchar*)tn, int(l));
|
||||
PISpinlockLocker _ml(mutex);
|
||||
data[ti.id].used -= cnt;
|
||||
}
|
||||
|
||||
|
||||
@@ -107,15 +84,15 @@ PIVector<PIIntrospectionContainers::TypeInfo> PIIntrospectionContainers::getInfo
|
||||
PIVector<PIIntrospectionContainers::TypeInfo> ret;
|
||||
mutex.lock();
|
||||
std::map<uint, PIIntrospectionContainers::_Type> d = data;
|
||||
std::map<uint, std::string> t = typenames;
|
||||
std::map<uint, PIIntrospectionContainersType> t = types;
|
||||
mutex.unlock();
|
||||
ret.reserve(t.size());
|
||||
for (typename std::map<uint, std::string>::const_iterator i = t.begin(); i != t.end(); ++i) {
|
||||
for (typename std::map<uint, PIIntrospectionContainersType>::const_iterator i = t.begin(); i != t.end(); ++i) {
|
||||
ret.push_back(TypeInfo());
|
||||
TypeInfo & ti(ret.back());
|
||||
_Type & _t(d[i->first]);
|
||||
memcpy((void*)&ti, (const void*)&_t, sizeof(_t));
|
||||
ti.name = demangle(i->second.c_str());
|
||||
ti.name = PIStringAscii(i->second.demangled);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user