git-svn-id: svn://db.shs.com.ru/pip@824 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -20,10 +20,23 @@
|
||||
#include "piintrospection_containers_p.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::Type::Type() {
|
||||
count = items = 0u;
|
||||
bytes_allocated = bytes_used = 0U;
|
||||
|
||||
PIIntrospectionContainers::_Type::_Type() {
|
||||
id = count = item_size = 0u;
|
||||
allocated = used = 0U;
|
||||
}
|
||||
|
||||
|
||||
@@ -35,12 +48,18 @@ PIIntrospectionContainers::PIIntrospectionContainers() {
|
||||
}
|
||||
|
||||
|
||||
void PIIntrospectionContainers::containerNew(const char * tn) {
|
||||
void PIIntrospectionContainers::containerNew(const char * tn, uint isz) {
|
||||
uint id = typeID(tn);
|
||||
PIMutexLocker _ml(mutex);
|
||||
//printf("containerNew lock\n");
|
||||
typenames[id] = tn;
|
||||
data[id].count++;
|
||||
std::string & n(typenames[id]);
|
||||
_Type & d(data[id]);
|
||||
if (n.empty()) {
|
||||
n = tn;
|
||||
d.id = id;
|
||||
d.item_size = isz;
|
||||
}
|
||||
d.count++;
|
||||
//printf("containerNew unlock\n");
|
||||
}
|
||||
|
||||
@@ -55,7 +74,7 @@ void PIIntrospectionContainers::containerAlloc(const char * tn, ullong cnt) {
|
||||
//printf(" alloc %s %d\n", tn, cnt);
|
||||
if (cnt == 0) return;
|
||||
PIMutexLocker _ml(mutex);
|
||||
data[typeID(tn)].bytes_allocated += cnt;
|
||||
data[typeID(tn)].allocated += cnt;
|
||||
}
|
||||
|
||||
|
||||
@@ -63,7 +82,7 @@ void PIIntrospectionContainers::containerFree(const char * tn, ullong cnt) {
|
||||
//printf(" free %s %d\n", tn, cnt);
|
||||
if (cnt == 0) return;
|
||||
PIMutexLocker _ml(mutex);
|
||||
data[typeID(tn)].bytes_allocated -= cnt;
|
||||
data[typeID(tn)].allocated -= cnt;
|
||||
}
|
||||
|
||||
|
||||
@@ -71,7 +90,7 @@ void PIIntrospectionContainers::containerUsed(const char * tn, ullong cnt) {
|
||||
//printf(" used %s %d\n", tn, cnt);
|
||||
if (cnt == 0) return;
|
||||
PIMutexLocker _ml(mutex);
|
||||
data[typeID(tn)].bytes_used += cnt;
|
||||
data[typeID(tn)].used += cnt;
|
||||
}
|
||||
|
||||
|
||||
@@ -79,7 +98,7 @@ void PIIntrospectionContainers::containerUnused(const char * tn, ullong cnt) {
|
||||
//printf("unused %s %d\n", tn, cnt);
|
||||
if (cnt == 0) return;
|
||||
PIMutexLocker _ml(mutex);
|
||||
data[typeID(tn)].bytes_used -= cnt;
|
||||
data[typeID(tn)].used -= cnt;
|
||||
}
|
||||
|
||||
|
||||
@@ -91,23 +110,31 @@ uint PIIntrospectionContainers::typeID(const char * tn) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
PIByteArray & operator <<(PIByteArray & s, const std::map<uint, std::string> & v) {
|
||||
PIMap<uint, PIString> m;
|
||||
for (typename std::map<uint, std::string>::const_iterator i = v.cbegin(); i != v.cend(); ++i) {
|
||||
m[i->first] = PIStringAscii(i->second.c_str());
|
||||
PIVector<PIIntrospectionContainers::TypeInfo> PIIntrospectionContainers::getInfo() const {
|
||||
PIVector<PIIntrospectionContainers::TypeInfo> ret;
|
||||
mutex.lock();
|
||||
std::map<uint, PIIntrospectionContainers::_Type> d = data;
|
||||
std::map<uint, std::string> t = typenames;
|
||||
mutex.unlock();
|
||||
ret.reserve(t.size());
|
||||
for (typename std::map<uint, std::string>::const_iterator i = t.cbegin(); i != t.cend(); ++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());
|
||||
}
|
||||
s << m;
|
||||
return s;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
PIByteArray & operator <<(PIByteArray & s, const PIIntrospectionContainers::Type & v) {
|
||||
s << v.count << v.items << v.bytes_allocated << v.bytes_used;
|
||||
|
||||
|
||||
PIByteArray & operator <<(PIByteArray & s, const PIIntrospectionContainers::TypeInfo & v) {
|
||||
s << PIByteArray::RawData(&v, sizeof(PIIntrospectionContainers::_Type)) << v.name;
|
||||
return s;
|
||||
}
|
||||
PIByteArray & operator >>(PIByteArray & s, PIIntrospectionContainers::Type & v) {
|
||||
s >> v.count >> v.items >> v.bytes_allocated >> v.bytes_used;
|
||||
PIByteArray & operator >>(PIByteArray & s, PIIntrospectionContainers::TypeInfo & v) {
|
||||
s >> PIByteArray::RawData(&v, sizeof(PIIntrospectionContainers::_Type)) >> v.name;
|
||||
return s;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user