git-svn-id: svn://db.shs.com.ru/pip@824 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -35,8 +35,8 @@ PIIntrospectionContainersInterface::~PIIntrospectionContainersInterface() {
|
||||
}
|
||||
|
||||
|
||||
void PIIntrospectionContainersInterface::containerNew(const char * tn) {
|
||||
p->containerNew(tn);
|
||||
void PIIntrospectionContainersInterface::containerNew(const char * tn, uint isz) {
|
||||
p->containerNew(tn, isz);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ class PIIntrospectionContainers;
|
||||
# define _PIIS_TYPENAME_(t) ""
|
||||
#endif
|
||||
|
||||
# define PIINTROSPECTION_CONTAINER_NEW(t) PIINTROSPECTION_CONTAINERS->containerNew (_PIIS_TYPENAME_(t));
|
||||
# define PIINTROSPECTION_CONTAINER_NEW(t, isz) PIINTROSPECTION_CONTAINERS->containerNew (_PIIS_TYPENAME_(t), isz);
|
||||
# define PIINTROSPECTION_CONTAINER_DELETE(t) PIINTROSPECTION_CONTAINERS->containerDelete(_PIIS_TYPENAME_(t));
|
||||
# define PIINTROSPECTION_CONTAINER_ALLOC(t, cnt) PIINTROSPECTION_CONTAINERS->containerAlloc (_PIIS_TYPENAME_(t), cnt);
|
||||
# define PIINTROSPECTION_CONTAINER_FREE(t, cnt) PIINTROSPECTION_CONTAINERS->containerFree (_PIIS_TYPENAME_(t), cnt);
|
||||
@@ -49,7 +49,7 @@ class PIP_EXPORT PIIntrospectionContainersInterface {
|
||||
public:
|
||||
__PIINTROSPECTION_SINGLETON_H__(Containers)
|
||||
|
||||
void containerNew (const char * tn);
|
||||
void containerNew (const char * tn, uint isz);
|
||||
void containerDelete(const char * tn);
|
||||
void containerAlloc (const char * tn, ullong cnt);
|
||||
void containerFree (const char * tn, ullong cnt);
|
||||
@@ -66,7 +66,7 @@ private:
|
||||
|
||||
|
||||
#else
|
||||
# define PIINTROSPECTION_CONTAINER_NEW(t)
|
||||
# define PIINTROSPECTION_CONTAINER_NEW(t, isz)
|
||||
# define PIINTROSPECTION_CONTAINER_DELETE(t)
|
||||
# define PIINTROSPECTION_CONTAINER_ALLOC(t, cnt)
|
||||
# define PIINTROSPECTION_CONTAINER_FREE(t, cnt)
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -30,7 +30,9 @@ class PIP_EXPORT PIIntrospectionContainers {
|
||||
public:
|
||||
PIIntrospectionContainers();
|
||||
|
||||
void containerNew (const char * tn);
|
||||
struct TypeInfo;
|
||||
|
||||
void containerNew (const char * tn, uint isz);
|
||||
void containerDelete(const char * tn);
|
||||
void containerAlloc (const char * tn, ullong cnt);
|
||||
void containerFree (const char * tn, ullong cnt);
|
||||
@@ -39,23 +41,30 @@ public:
|
||||
|
||||
uint typeID(const char * tn);
|
||||
|
||||
struct Type {
|
||||
Type();
|
||||
PIVector<TypeInfo> getInfo() const;
|
||||
|
||||
#pragma pack(push, 1)
|
||||
struct _Type {
|
||||
_Type();
|
||||
uint id;
|
||||
uint count;
|
||||
uint items;
|
||||
ullong bytes_allocated;
|
||||
ullong bytes_used;
|
||||
uint item_size;
|
||||
ullong allocated;
|
||||
ullong used;
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
struct TypeInfo: _Type {
|
||||
PIString name;
|
||||
};
|
||||
|
||||
std::map<uint, Type> data;
|
||||
std::map<uint, _Type> data;
|
||||
std::map<uint, std::string> typenames;
|
||||
PIMutex mutex;
|
||||
mutable PIMutex mutex;
|
||||
CRC_32 crc;
|
||||
};
|
||||
|
||||
PIByteArray & operator <<(PIByteArray & s, const std::map<uint, std::string> & v);
|
||||
|
||||
PIByteArray & operator <<(PIByteArray & s, const PIIntrospectionContainers::Type & v);
|
||||
PIByteArray & operator >>(PIByteArray & s, PIIntrospectionContainers::Type & v);
|
||||
PIByteArray & operator <<(PIByteArray & s, const PIIntrospectionContainers::TypeInfo & v);
|
||||
PIByteArray & operator >>(PIByteArray & s, PIIntrospectionContainers::TypeInfo & v);
|
||||
|
||||
#endif // PIINTROSPECTION_CONTAINERS_P_H
|
||||
|
||||
@@ -86,9 +86,9 @@ PIVector<PIIntrospection::ObjectInfo> PIIntrospection::getObjects() {
|
||||
}
|
||||
|
||||
|
||||
PIByteArray & operator <<(PIByteArray & s, const std::map<uint, PIIntrospectionContainers::Type> & v) {
|
||||
PIMap<uint, PIIntrospectionContainers::Type> m;
|
||||
for (typename std::map<uint, PIIntrospectionContainers::Type>::const_iterator i = v.cbegin(); i != v.cend(); ++i) {
|
||||
PIByteArray & operator <<(PIByteArray & s, const std::map<uint, PIIntrospectionContainers::_Type> & v) {
|
||||
PIMap<uint, PIIntrospectionContainers::_Type> m;
|
||||
for (typename std::map<uint, PIIntrospectionContainers::_Type>::const_iterator i = v.cbegin(); i != v.cend(); ++i) {
|
||||
m[i->first] = i->second;
|
||||
}
|
||||
s << m;
|
||||
@@ -205,27 +205,22 @@ void PIIntrospection::unpackProcStat(PIByteArray & ba, PIIntrospection::ProcessS
|
||||
|
||||
PIByteArray PIIntrospection::packContainers() {
|
||||
PIByteArray ret;
|
||||
std::map<uint, PIIntrospectionContainers::Type> data;
|
||||
std::map<uint, std::string> typenames;
|
||||
PIVector<PIIntrospectionContainers::TypeInfo> data;
|
||||
PIIntrospectionContainers * p = 0;
|
||||
#ifdef PIP_INTROSPECTION
|
||||
p = PIINTROSPECTION_CONTAINERS->p;
|
||||
#endif
|
||||
if (p) {
|
||||
p->mutex.lock();
|
||||
data = p->data;
|
||||
typenames = p->typenames;
|
||||
p->mutex.unlock();
|
||||
data = p->getInfo();
|
||||
}
|
||||
ret << data << typenames;
|
||||
ret << data;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void PIIntrospection::unpackContainers(PIByteArray & ba, PIMap<uint, PIIntrospectionContainers::Type> & data, PIMap<uint, PIString> & typenames) {
|
||||
void PIIntrospection::unpackContainers(PIByteArray & ba, PIVector<PIIntrospectionContainers::TypeInfo> & data) {
|
||||
data.clear();
|
||||
typenames.clear();
|
||||
ba >> data >> typenames;
|
||||
ba >> data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ public:
|
||||
static void unpackProcStat(PIByteArray & ba, ProcessStat & info);
|
||||
|
||||
static PIByteArray packContainers();
|
||||
static void unpackContainers(PIByteArray & ba, PIMap<uint, PIIntrospectionContainers::Type> & data, PIMap<uint, PIString> & typenames);
|
||||
static void unpackContainers(PIByteArray & ba, PIVector<PIIntrospectionContainers::TypeInfo> & data);
|
||||
|
||||
static PIByteArray packThreads();
|
||||
static void unpackThreads(PIByteArray & ba, PIVector<PIIntrospectionThreads::ThreadInfo> & threads);
|
||||
@@ -91,7 +91,7 @@ public:
|
||||
|
||||
};
|
||||
|
||||
PIByteArray & operator <<(PIByteArray & s, const std::map<uint, PIIntrospectionContainers::Type> & v);
|
||||
PIByteArray & operator <<(PIByteArray & s, const std::map<uint, PIIntrospectionContainers::_Type> & v);
|
||||
|
||||
PIByteArray & operator <<(PIByteArray & b, const PIIntrospection::RequiredInfo & v);
|
||||
PIByteArray & operator >>(PIByteArray & b, PIIntrospection::RequiredInfo & v);
|
||||
|
||||
Reference in New Issue
Block a user