git-svn-id: svn://db.shs.com.ru/pip@824 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -36,26 +36,26 @@ class PIDeque {
|
||||
public:
|
||||
inline PIDeque(): pid_data(0), pid_size(0), pid_rsize(0), pid_start(0) {
|
||||
//piCout << "PIDeque";
|
||||
PIINTROSPECTION_CONTAINER_NEW(T)
|
||||
PIINTROSPECTION_CONTAINER_NEW(T, sizeof(T))
|
||||
}
|
||||
inline PIDeque(const PIDeque<T> & other): pid_data(0), pid_size(0), pid_rsize(0), pid_start(0) {
|
||||
PIINTROSPECTION_CONTAINER_NEW(T)
|
||||
PIINTROSPECTION_CONTAINER_NEW(T, sizeof(T))
|
||||
alloc(other.pid_size, true);
|
||||
newT(pid_data + pid_start, other.pid_data + other.pid_start, pid_size);
|
||||
}
|
||||
inline PIDeque(const T * data, size_t size): pid_data(0), pid_size(0), pid_rsize(0), pid_start(0) {
|
||||
PIINTROSPECTION_CONTAINER_NEW(T)
|
||||
PIINTROSPECTION_CONTAINER_NEW(T, sizeof(T))
|
||||
alloc(size, true);
|
||||
newT(pid_data + pid_start, data, pid_size);
|
||||
}
|
||||
inline PIDeque(size_t pid_size, const T & f = T()): pid_data(0), pid_size(0), pid_rsize(0), pid_start(0) {
|
||||
PIINTROSPECTION_CONTAINER_NEW(T)
|
||||
PIINTROSPECTION_CONTAINER_NEW(T, sizeof(T))
|
||||
resize(pid_size, f);
|
||||
}
|
||||
inline virtual ~PIDeque() {
|
||||
//piCout << "~PIDeque";
|
||||
PIINTROSPECTION_CONTAINER_DELETE(T)
|
||||
PIINTROSPECTION_CONTAINER_FREE(T, (pid_rsize)*sizeof(T))
|
||||
PIINTROSPECTION_CONTAINER_FREE(T, (pid_rsize))
|
||||
deleteT(pid_data + pid_start, pid_size);
|
||||
dealloc();
|
||||
_reset();
|
||||
@@ -206,7 +206,7 @@ public:
|
||||
inline PIDeque<T> & clear() {resize(0); return *this;}
|
||||
inline PIDeque<T> & fill(const T & f = T()) {
|
||||
deleteT(pid_data + pid_start, pid_size);
|
||||
PIINTROSPECTION_CONTAINER_USED(T, pid_size*sizeof(T))
|
||||
PIINTROSPECTION_CONTAINER_USED(T, pid_size)
|
||||
for (size_t i = pid_start; i < pid_start + pid_size; ++i)
|
||||
elementNew(pid_data + i, f);
|
||||
return *this;
|
||||
@@ -225,7 +225,7 @@ public:
|
||||
if (new_size > pid_size) {
|
||||
size_t os = pid_size;
|
||||
alloc(new_size, true);
|
||||
PIINTROSPECTION_CONTAINER_USED(T, (new_size-os)*sizeof(T))
|
||||
PIINTROSPECTION_CONTAINER_USED(T, (new_size-os))
|
||||
for (size_t i = os + pid_start; i < new_size + pid_start; ++i) elementNew(pid_data + i, f);
|
||||
}
|
||||
return *this;
|
||||
@@ -257,7 +257,7 @@ public:
|
||||
if (index > 0)
|
||||
memmove((void*)(&(pid_data[pid_start])), (const void*)(&(pid_data[pid_start + 1])), index * sizeof(T));
|
||||
}
|
||||
PIINTROSPECTION_CONTAINER_USED(T, sizeof(T))
|
||||
PIINTROSPECTION_CONTAINER_USED(T, 1)
|
||||
elementNew(pid_data + pid_start + index, v);
|
||||
return *this;
|
||||
}
|
||||
@@ -337,7 +337,7 @@ public:
|
||||
|
||||
inline PIDeque<T> & push_back(const T & v) {
|
||||
alloc(pid_size + 1, true);
|
||||
PIINTROSPECTION_CONTAINER_USED(T, sizeof(T));
|
||||
PIINTROSPECTION_CONTAINER_USED(T, 1);
|
||||
elementNew(pid_data + pid_start + pid_size - 1, v);
|
||||
return *this;
|
||||
}
|
||||
@@ -381,12 +381,12 @@ private:
|
||||
return (1 << t);
|
||||
}
|
||||
inline void newT(T * dst, const T * src, size_t s) {
|
||||
PIINTROSPECTION_CONTAINER_USED(T, s*sizeof(T))
|
||||
PIINTROSPECTION_CONTAINER_USED(T, s)
|
||||
for (size_t i = 0; i < s; ++i)
|
||||
elementNew(dst + i, src[i]);
|
||||
}
|
||||
inline void deleteT(T * d, size_t sz) {
|
||||
PIINTROSPECTION_CONTAINER_UNUSED(T, sz*sizeof(T))
|
||||
PIINTROSPECTION_CONTAINER_UNUSED(T, sz)
|
||||
if ((uchar*)d != 0) {
|
||||
for (size_t i = 0; i < sz; ++i)
|
||||
elementDelete(d[i]);
|
||||
@@ -427,7 +427,7 @@ private:
|
||||
pid_size = new_size;
|
||||
size_t as = asize(pid_start + new_size);
|
||||
if (as != pid_rsize) {
|
||||
PIINTROSPECTION_CONTAINER_ALLOC(T, (as-pid_rsize)*sizeof(T))
|
||||
PIINTROSPECTION_CONTAINER_ALLOC(T, (as-pid_rsize))
|
||||
T * p_d = (T*)(realloc((void*)(pid_data), as*sizeof(T)));
|
||||
assert(p_d);
|
||||
pid_data = p_d;
|
||||
@@ -442,7 +442,7 @@ private:
|
||||
if (as > pid_rsize) {
|
||||
T * td = (T*)(malloc(as * sizeof(T)));
|
||||
ssize_t ns = pid_start + as - pid_rsize;
|
||||
PIINTROSPECTION_CONTAINER_ALLOC(T, (as-pid_rsize)*sizeof(T))
|
||||
PIINTROSPECTION_CONTAINER_ALLOC(T, (as-pid_rsize))
|
||||
if (pid_rsize > 0 && pid_data != 0) {
|
||||
memcpy((void*)(td + ns), (const void*)(pid_data + pid_start), pid_size * sizeof(T));
|
||||
dealloc();
|
||||
@@ -463,21 +463,21 @@ private:
|
||||
};
|
||||
|
||||
#define __PIDEQUE_SIMPLE_TYPE__(T) \
|
||||
template<> inline void PIDeque<T>::newT(T * dst, const T * src, size_t s) {PIINTROSPECTION_CONTAINER_USED(T, s*sizeof(T)); memcpy((void*)(dst), (const void*)(src), s * sizeof(T));} \
|
||||
template<> inline void PIDeque<T>::deleteT(T *, size_t sz) {PIINTROSPECTION_CONTAINER_UNUSED(T, sz*sizeof(T));} \
|
||||
template<> inline void PIDeque<T>::newT(T * dst, const T * src, size_t s) {PIINTROSPECTION_CONTAINER_USED(T, s); memcpy((void*)(dst), (const void*)(src), s * sizeof(T));} \
|
||||
template<> inline void PIDeque<T>::deleteT(T *, size_t sz) {PIINTROSPECTION_CONTAINER_UNUSED(T, sz);} \
|
||||
template<> inline void PIDeque<T>::elementNew(T * to, const T & from) {(*to) = from;} \
|
||||
template<> inline void PIDeque<T>::elementDelete(T &) {;} \
|
||||
template<> inline PIDeque<T> & PIDeque<T>::_resizeRaw(size_t new_size) { \
|
||||
if (new_size > pid_size) { \
|
||||
PIINTROSPECTION_CONTAINER_USED(T, (new_size-pid_size)*sizeof(T)); \
|
||||
PIINTROSPECTION_CONTAINER_USED(T, (new_size-pid_size)); \
|
||||
} \
|
||||
if (new_size < pid_size) { \
|
||||
PIINTROSPECTION_CONTAINER_UNUSED(T, (pid_size-new_size)*sizeof(T)); \
|
||||
PIINTROSPECTION_CONTAINER_UNUSED(T, (pid_size-new_size)); \
|
||||
} \
|
||||
alloc(new_size, true); \
|
||||
return *this; \
|
||||
} \
|
||||
template<> inline PIDeque<T> & PIDeque<T>::clear() {PIINTROSPECTION_CONTAINER_UNUSED(T, pid_size*sizeof(T)); pid_size = 0; return *this;} \
|
||||
template<> inline PIDeque<T> & PIDeque<T>::clear() {PIINTROSPECTION_CONTAINER_UNUSED(T, pid_size); pid_size = 0; return *this;} \
|
||||
template<> inline PIDeque<T> & PIDeque<T>::assign(size_t new_size, const T & f) {_resizeRaw(new_size); return fill(f);}
|
||||
|
||||
|
||||
|
||||
@@ -35,25 +35,25 @@ template <typename T>
|
||||
class PIVector {
|
||||
public:
|
||||
inline PIVector(): piv_data(0), piv_size(0), piv_rsize(0) {
|
||||
PIINTROSPECTION_CONTAINER_NEW(T)
|
||||
PIINTROSPECTION_CONTAINER_NEW(T, sizeof(T))
|
||||
}
|
||||
inline PIVector(const T * data, size_t size): piv_data(0), piv_size(0), piv_rsize(0) {
|
||||
PIINTROSPECTION_CONTAINER_NEW(T)
|
||||
PIINTROSPECTION_CONTAINER_NEW(T, sizeof(T))
|
||||
alloc(size);
|
||||
newT(piv_data, data, piv_size);
|
||||
}
|
||||
inline PIVector(const PIVector<T> & other): piv_data(0), piv_size(0), piv_rsize(0) {
|
||||
PIINTROSPECTION_CONTAINER_NEW(T)
|
||||
PIINTROSPECTION_CONTAINER_NEW(T, sizeof(T))
|
||||
alloc(other.piv_size);
|
||||
newT(piv_data, other.piv_data, piv_size);
|
||||
}
|
||||
inline PIVector(size_t piv_size, const T & f = T()): piv_data(0), piv_size(0), piv_rsize(0) {
|
||||
PIINTROSPECTION_CONTAINER_NEW(T)
|
||||
PIINTROSPECTION_CONTAINER_NEW(T, sizeof(T))
|
||||
resize(piv_size, f);
|
||||
}
|
||||
inline virtual ~PIVector() {
|
||||
PIINTROSPECTION_CONTAINER_DELETE(T)
|
||||
PIINTROSPECTION_CONTAINER_FREE(T, (piv_rsize)*sizeof(T))
|
||||
PIINTROSPECTION_CONTAINER_FREE(T, (piv_rsize))
|
||||
deleteT(piv_data, piv_size);
|
||||
dealloc();
|
||||
_reset();
|
||||
@@ -203,7 +203,7 @@ public:
|
||||
inline PIVector<T> & clear() {resize(0); return *this;}
|
||||
inline PIVector<T> & fill(const T & f = T()) {
|
||||
deleteT(piv_data, piv_size);
|
||||
PIINTROSPECTION_CONTAINER_USED(T, piv_size*sizeof(T))
|
||||
PIINTROSPECTION_CONTAINER_USED(T, piv_size)
|
||||
for (size_t i = 0; i < piv_size; ++i)
|
||||
elementNew(piv_data + i, f);
|
||||
return *this;
|
||||
@@ -223,7 +223,7 @@ public:
|
||||
if (new_size > piv_size) {
|
||||
size_t os = piv_size;
|
||||
alloc(new_size);
|
||||
PIINTROSPECTION_CONTAINER_USED(T, (new_size-os)*sizeof(T))
|
||||
PIINTROSPECTION_CONTAINER_USED(T, (new_size-os))
|
||||
for (size_t i = os; i < new_size; ++i)
|
||||
elementNew(piv_data + i, f);
|
||||
}
|
||||
@@ -252,7 +252,7 @@ public:
|
||||
size_t os = piv_size - index - 1;
|
||||
memmove((void*)(&(piv_data[index + 1])), (const void*)(&(piv_data[index])), os * sizeof(T));
|
||||
}
|
||||
PIINTROSPECTION_CONTAINER_USED(T, sizeof(T))
|
||||
PIINTROSPECTION_CONTAINER_USED(T, 1)
|
||||
elementNew(piv_data + index, v);
|
||||
return *this;
|
||||
}
|
||||
@@ -319,7 +319,7 @@ public:
|
||||
|
||||
inline PIVector<T> & push_back(const T & v) {
|
||||
alloc(piv_size + 1);
|
||||
PIINTROSPECTION_CONTAINER_USED(T, sizeof(T));
|
||||
PIINTROSPECTION_CONTAINER_USED(T, 1);
|
||||
elementNew(piv_data + piv_size - 1, v);
|
||||
return *this;
|
||||
}
|
||||
@@ -372,12 +372,12 @@ private:
|
||||
return (1 << t);
|
||||
}
|
||||
inline void newT(T * dst, const T * src, size_t s) {
|
||||
PIINTROSPECTION_CONTAINER_USED(T, s*sizeof(T))
|
||||
PIINTROSPECTION_CONTAINER_USED(T, s)
|
||||
for (size_t i = 0; i < s; ++i)
|
||||
elementNew(dst + i, src[i]);
|
||||
}
|
||||
inline void deleteT(T * d, size_t sz) {
|
||||
PIINTROSPECTION_CONTAINER_UNUSED(T, sz*sizeof(T))
|
||||
PIINTROSPECTION_CONTAINER_UNUSED(T, sz)
|
||||
if ((uchar*)d != 0) {
|
||||
for (size_t i = 0; i < sz; ++i)
|
||||
elementDelete(d[i]);
|
||||
@@ -397,7 +397,7 @@ private:
|
||||
piv_size = new_size;
|
||||
size_t as = asize(new_size);
|
||||
if (as == piv_rsize) return;
|
||||
PIINTROSPECTION_CONTAINER_ALLOC(T, (as-piv_rsize)*sizeof(T))
|
||||
PIINTROSPECTION_CONTAINER_ALLOC(T, (as-piv_rsize))
|
||||
T * p_d = (T*)(realloc((void*)(piv_data), as*sizeof(T)));
|
||||
assert(p_d);
|
||||
piv_data = p_d;
|
||||
@@ -410,21 +410,21 @@ private:
|
||||
|
||||
|
||||
#define __PIVECTOR_SIMPLE_TYPE__(T) \
|
||||
template<> inline void PIVector<T>::newT(T * dst, const T * src, size_t s) {PIINTROSPECTION_CONTAINER_USED(T, s*sizeof(T)); memcpy((void*)(dst), (const void*)(src), s * sizeof(T));} \
|
||||
template<> inline void PIVector<T>::deleteT(T *, size_t sz) {PIINTROSPECTION_CONTAINER_UNUSED(T, sz*sizeof(T));} \
|
||||
template<> inline void PIVector<T>::newT(T * dst, const T * src, size_t s) {PIINTROSPECTION_CONTAINER_USED(T, s); memcpy((void*)(dst), (const void*)(src), s * sizeof(T));} \
|
||||
template<> inline void PIVector<T>::deleteT(T *, size_t sz) {PIINTROSPECTION_CONTAINER_UNUSED(T, sz);} \
|
||||
template<> inline void PIVector<T>::elementNew(T * to, const T & from) {(*to) = from;} \
|
||||
template<> inline void PIVector<T>::elementDelete(T &) {;} \
|
||||
template<> inline PIVector<T> & PIVector<T>::_resizeRaw(size_t new_size) { \
|
||||
if (new_size > piv_size) { \
|
||||
PIINTROSPECTION_CONTAINER_USED(T, (new_size-piv_size)*sizeof(T)); \
|
||||
PIINTROSPECTION_CONTAINER_USED(T, (new_size-piv_size)); \
|
||||
} \
|
||||
if (new_size < piv_size) { \
|
||||
PIINTROSPECTION_CONTAINER_UNUSED(T, (piv_size-new_size)*sizeof(T)); \
|
||||
PIINTROSPECTION_CONTAINER_UNUSED(T, (piv_size-new_size)); \
|
||||
} \
|
||||
alloc(new_size); \
|
||||
return *this; \
|
||||
} \
|
||||
template<> inline PIVector<T> & PIVector<T>::clear() {PIINTROSPECTION_CONTAINER_UNUSED(T, piv_size*sizeof(T)); piv_size = 0; return *this;} \
|
||||
template<> inline PIVector<T> & PIVector<T>::clear() {PIINTROSPECTION_CONTAINER_UNUSED(T, piv_size); piv_size = 0; return *this;} \
|
||||
template<> inline PIVector<T> & PIVector<T>::assign(size_t new_size, const T & f) {_resizeRaw(new_size); return fill(f);}
|
||||
|
||||
|
||||
|
||||
@@ -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