git-svn-id: svn://db.shs.com.ru/pip@804 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -29,7 +29,13 @@ class PITimer;
|
||||
class PIPeer;
|
||||
class PIIntrospection;
|
||||
|
||||
#define __PIINTROSPECTION_SINGLETON__(T) \
|
||||
static PIIntrospection##T##Interface * instance() {static PIIntrospection##T##Interface ret; return &ret;} \
|
||||
#define __PIINTROSPECTION_SINGLETON_H__(T) \
|
||||
static PIIntrospection##T##Interface * instance();
|
||||
|
||||
#define __PIINTROSPECTION_SINGLETON_CPP__(T) \
|
||||
PIIntrospection##T##Interface * PIIntrospection##T##Interface::instance() {\
|
||||
static PIIntrospection##T##Interface ret;\
|
||||
return &ret;\
|
||||
}
|
||||
|
||||
#endif // PIINTROSPECTION_BASE_H
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
#include "piintrospection_containers.h"
|
||||
#include "piintrospection_containers_p.h"
|
||||
|
||||
__PIINTROSPECTION_SINGLETON_CPP__(Containers)
|
||||
|
||||
|
||||
PIIntrospectionContainersInterface::PIIntrospectionContainersInterface() {
|
||||
p = new PIIntrospectionContainers();
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
class PIIntrospectionContainers;
|
||||
|
||||
#define PIINTROSPECTION_CONTAINERS (PIIntrospectionContainersInterface::instance())
|
||||
#define PIINTROSPECTION_CONTAINERS (PIIntrospectionContainersInterface::instance())//(PIIntrospectionContainersInterface::instance())
|
||||
|
||||
//#if defined(__PIIS__)
|
||||
//# undef __PIIS__
|
||||
@@ -55,11 +55,12 @@ class PIIntrospectionContainers;
|
||||
# define PIINTROSPECTION_CONTAINER_UNUSED(t, cnt)
|
||||
#endif
|
||||
|
||||
|
||||
class PIP_EXPORT PIIntrospectionContainersInterface {
|
||||
friend class PIIntrospection;
|
||||
friend class PIIntrospectionServer;
|
||||
public:
|
||||
__PIINTROSPECTION_SINGLETON__(Containers)
|
||||
__PIINTROSPECTION_SINGLETON_H__(Containers)
|
||||
|
||||
void containerNew (const char * tn);
|
||||
void containerDelete(const char * tn);
|
||||
@@ -68,12 +69,13 @@ public:
|
||||
void containerUsed (const char * tn, ullong cnt);
|
||||
void containerUnused(const char * tn, ullong cnt);
|
||||
|
||||
PIIntrospectionContainers * p;
|
||||
private:
|
||||
PIIntrospectionContainersInterface();
|
||||
~PIIntrospectionContainersInterface();
|
||||
|
||||
PIIntrospectionContainers * p;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif // PIINTROSPECTION_CONTAINERS_H
|
||||
|
||||
@@ -30,6 +30,7 @@ PIIntrospectionContainers::Type::Type() {
|
||||
|
||||
|
||||
PIIntrospectionContainers::PIIntrospectionContainers() {
|
||||
//printf("PIIntrospectionContainers %p\n", this);
|
||||
crc = standardCRC_32();
|
||||
}
|
||||
|
||||
@@ -51,24 +52,32 @@ void PIIntrospectionContainers::containerDelete(const char * tn) {
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -29,21 +29,15 @@ PRIVATE_DEFINITION_END(PIIntrospectionServer)
|
||||
|
||||
PIIntrospectionServer::PIIntrospectionServer(): PIPeer(genName()) {
|
||||
PRIVATE->process_info = PIIntrospection::getInfo();
|
||||
CONNECTU(&itimer, tickEvent, this, timerEvent);
|
||||
}
|
||||
|
||||
|
||||
PIIntrospectionServer::~PIIntrospectionServer() {
|
||||
itimer.stop(false);
|
||||
if (!itimer.waitForFinish(1000)) {
|
||||
PIINTROSPECTION_CONTAINERS->p->mutex.unlock();
|
||||
}
|
||||
PIPeer::stop();
|
||||
}
|
||||
|
||||
|
||||
void PIIntrospectionServer::start() {
|
||||
itimer.start(1000);
|
||||
PIPeer::start();
|
||||
}
|
||||
|
||||
@@ -54,14 +48,24 @@ PIString PIIntrospectionServer::genName() {
|
||||
}
|
||||
|
||||
|
||||
void PIIntrospectionServer::timerEvent() {
|
||||
void PIIntrospectionServer::dataReceived(const PIString & from, const PIByteArray & data) {
|
||||
if (data.size() < 8) return;
|
||||
PIByteArray rba(data);
|
||||
uint _sign(0); rba >> _sign;
|
||||
if (_sign != PIIntrospection::sign) return;
|
||||
PIIntrospection::RequiredInfo ri;
|
||||
rba >> ri;
|
||||
PIChunkStream cs;
|
||||
cs.add(1, PIIntrospection::packInfo())
|
||||
.add(2, PIIntrospection::packContainers())
|
||||
.add(3, PIIntrospection::packThreads())
|
||||
.add(4, PIIntrospection::packObjects());
|
||||
if (ri.types[PIIntrospection::itInfo])
|
||||
cs.add(PIIntrospection::itInfo, PIIntrospection::packInfo());
|
||||
if (ri.types[PIIntrospection::itContainers])
|
||||
cs.add(PIIntrospection::itContainers, PIIntrospection::packContainers());
|
||||
if (ri.types[PIIntrospection::itThreads])
|
||||
cs.add(PIIntrospection::itThreads, PIIntrospection::packThreads());
|
||||
if (ri.types[PIIntrospection::itObjects])
|
||||
cs.add(PIIntrospection::itObjects, PIIntrospection::packObjects());
|
||||
PIByteArray ba;
|
||||
ba << PIIntrospection::sign;
|
||||
ba.append(cs.data());
|
||||
send("__introspection_client__", ba);
|
||||
send(from, ba);
|
||||
}
|
||||
|
||||
@@ -44,12 +44,11 @@ private:
|
||||
~PIIntrospectionServer();
|
||||
NO_COPY_CLASS(PIIntrospectionServer)
|
||||
|
||||
EVENT_HANDLER(void, timerEvent);
|
||||
PIString genName();
|
||||
virtual void dataReceived(const PIString & from, const PIByteArray & data);
|
||||
|
||||
PRIVATE_DECLARATION
|
||||
PITimer itimer;
|
||||
|
||||
};
|
||||
|
||||
#endif // PIINTROSPECTION_SERVER_H
|
||||
|
||||
@@ -29,6 +29,11 @@ const uint PIIntrospection::sign = 0x0F1C2B3A;
|
||||
|
||||
|
||||
|
||||
PIIntrospection::RequiredInfo::RequiredInfo() {
|
||||
types = itInfo;
|
||||
}
|
||||
|
||||
|
||||
PIIntrospection::ProcessInfo::ProcessInfo() {
|
||||
processorsCount = 0;
|
||||
}
|
||||
@@ -91,6 +96,27 @@ PIByteArray & operator <<(PIByteArray & s, const std::unordered_map<uint, PIIntr
|
||||
}
|
||||
|
||||
|
||||
PIByteArray & operator <<(PIByteArray & b, const PIIntrospection::RequiredInfo & v) {
|
||||
PIChunkStream cs;
|
||||
cs.add(1, v.types);
|
||||
b << cs.data();
|
||||
return b;
|
||||
}
|
||||
|
||||
|
||||
PIByteArray & operator >>(PIByteArray & b, PIIntrospection::RequiredInfo & v) {
|
||||
PIByteArray csba; b >> csba;
|
||||
PIChunkStream cs(csba);
|
||||
while (!cs.atEnd()) {
|
||||
switch (cs.read()) {
|
||||
case 1: cs.get(v.types); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
|
||||
PIByteArray & operator <<(PIByteArray & b, const PIIntrospection::ProcessInfo & v) {
|
||||
PIChunkStream cs;
|
||||
cs.add(1, v.architecture).add(2, v.execCommand).add(3, v.execDateTime).add(4, v.hostname).add(5, v.OS_name)
|
||||
|
||||
@@ -30,6 +30,18 @@
|
||||
class PIIntrospection {
|
||||
public:
|
||||
|
||||
enum InfoTypes {
|
||||
itInfo = 0x01,
|
||||
itContainers = 0x02,
|
||||
itObjects = 0x04,
|
||||
itThreads = 0x08,
|
||||
};
|
||||
|
||||
struct RequiredInfo {
|
||||
RequiredInfo();
|
||||
PIFlags<InfoTypes> types;
|
||||
};
|
||||
|
||||
struct ProcessInfo {
|
||||
ProcessInfo();
|
||||
|
||||
@@ -70,6 +82,9 @@ public:
|
||||
|
||||
PIByteArray & operator <<(PIByteArray & s, const std::unordered_map<uint, PIIntrospectionContainers::Type> & v);
|
||||
|
||||
PIByteArray & operator <<(PIByteArray & b, const PIIntrospection::RequiredInfo & v);
|
||||
PIByteArray & operator >>(PIByteArray & b, PIIntrospection::RequiredInfo & v);
|
||||
|
||||
PIByteArray & operator <<(PIByteArray & b, const PIIntrospection::ProcessInfo & v);
|
||||
PIByteArray & operator >>(PIByteArray & b, PIIntrospection::ProcessInfo & v);
|
||||
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
#include "piintrospection_threads.h"
|
||||
#include "piintrospection_threads_p.h"
|
||||
|
||||
__PIINTROSPECTION_SINGLETON_CPP__(Threads)
|
||||
|
||||
|
||||
PIIntrospectionThreadsInterface::PIIntrospectionThreadsInterface() {
|
||||
p = new PIIntrospectionThreads();
|
||||
|
||||
@@ -47,7 +47,7 @@ class PIIntrospectionThreads;
|
||||
class PIP_EXPORT PIIntrospectionThreadsInterface {
|
||||
friend class PIIntrospection;
|
||||
public:
|
||||
__PIINTROSPECTION_SINGLETON__(Threads)
|
||||
__PIINTROSPECTION_SINGLETON_H__(Threads)
|
||||
|
||||
void threadNew (PIThread * t);
|
||||
void threadDelete (PIThread * t);
|
||||
|
||||
Reference in New Issue
Block a user