git-svn-id: svn://db.shs.com.ru/pip@804 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5

This commit is contained in:
2019-06-22 20:37:09 +00:00
parent fb44b01c0f
commit 1f527d8e14
12 changed files with 110 additions and 42 deletions

View File

@@ -35,6 +35,7 @@ template <typename T>
class PIDeque {
public:
inline PIDeque(): pid_data(0), pid_size(0), pid_rsize(0), pid_start(0) {
//piCout << "PIDeque";
PIINTROSPECTION_CONTAINER_NEW(T)
}
inline PIDeque(const PIDeque<T> & other): pid_data(0), pid_size(0), pid_rsize(0), pid_start(0) {
@@ -52,6 +53,7 @@ public:
resize(pid_size, f);
}
inline virtual ~PIDeque() {
//piCout << "~PIDeque";
PIINTROSPECTION_CONTAINER_DELETE(T)
PIINTROSPECTION_CONTAINER_FREE(T, (pid_rsize)*sizeof(T))
deleteT(pid_data + pid_start, pid_size);

View File

@@ -26,6 +26,7 @@
#define PISTRING_H
#include "pibytearray.h"
#define PIStringAscii PIString::fromAscii
@@ -36,7 +37,7 @@ class PIP_EXPORT PIString: public PIDeque<PIChar>
friend PIByteArray & operator >>(PIByteArray & s, PIString & v);
public:
//! Contructs an empty string
PIString(): PIDeque<PIChar>() {/*reserve(4); */piMonitor.strings++; piMonitor.containers--;}
PIString(): PIDeque<PIChar>() {}
//inline PIString & operator +=(const char c) {push_back(c); return *this;}
PIString & operator +=(const PIChar & c) {push_back(c); return *this;}
@@ -46,55 +47,55 @@ public:
PIString & operator +=(const PIString & str);
//PIString(const char c) {*this += c;}
PIString(const PIString & o): PIDeque<PIChar>() {/*reserve(4); */piMonitor.strings++; piMonitor.containers--; *this += o;}
PIString(const PIString & o): PIDeque<PIChar>() {*this += o;}
//! Contructs string with single symbol "c"
PIString(const PIChar & c): PIDeque<PIChar>() {/*reserve(4); */piMonitor.strings++; piMonitor.containers--; *this += c;}
PIString(const char c): PIDeque<PIChar>() {/*reserve(4); */piMonitor.strings++; piMonitor.containers--; *this += PIChar(c);}
PIString(const PIChar & c): PIDeque<PIChar>() {*this += c;}
PIString(const char c): PIDeque<PIChar>() {*this += PIChar(c);}
/*! \brief Contructs string from c-string "str"
* \details "str" should be null-terminated\n
* Example: \snippet pistring.cpp PIString(char * ) */
PIString(const char * str): PIDeque<PIChar>() {/*reserve(4); */piMonitor.strings++; piMonitor.containers--; *this += str;}
PIString(const char * str): PIDeque<PIChar>() {*this += str;}
/*! \brief Contructs string from \c wchar_t c-string "str"
* \details "str" should be null-terminated\n
* Example: \snippet pistring.cpp PIString(wchar_t * ) */
PIString(const wchar_t * str): PIDeque<PIChar>() {/*reserve(4); */piMonitor.strings++; piMonitor.containers--; *this += str;}
PIString(const wchar_t * str): PIDeque<PIChar>() {*this += str;}
//! Contructs string from byte array "ba"
PIString(const PIByteArray & ba): PIDeque<PIChar>() {/*reserve(4); */piMonitor.strings++; piMonitor.containers--; *this += ba;}
PIString(const PIByteArray & ba): PIDeque<PIChar>() {*this += ba;}
//! \brief Contructs string from "len" characters of buffer "str"
PIString(const PIChar * str, const int len): PIDeque<PIChar>(str, size_t(len)) {/*reserve(4); */piMonitor.strings++; piMonitor.containers--;}
PIString(const PIChar * str, const int len): PIDeque<PIChar>(str, size_t(len)) {}
/*! \brief Contructs string from "len" characters of buffer "str"
* \details Example: \snippet pistring.cpp PIString(char * , int) */
PIString(const char * str, const int len): PIDeque<PIChar>() {/*reserve(4); */piMonitor.strings++; piMonitor.containers--; appendFromChars(str, len);}
PIString(const char * str, const int len): PIDeque<PIChar>() {appendFromChars(str, len);}
/*! \brief Contructs string as sequence of characters "c" of buffer with length "len"
* \details Example: \snippet pistring.cpp PIString(int, char) */
PIString(const int len, const char c): PIDeque<PIChar>() {/*reserve(4); */piMonitor.strings++; piMonitor.containers--; for (int i = 0; i < len; ++i) push_back(c);}
PIString(const int len, const char c): PIDeque<PIChar>() {for (int i = 0; i < len; ++i) push_back(c);}
/*! \brief Contructs string as sequence of symbols "c" of buffer with length "len"
* \details Example: \snippet pistring.cpp PIString(int, PIChar) */
PIString(const int len, const PIChar & c): PIDeque<PIChar>() {/*reserve(4); */piMonitor.strings++; piMonitor.containers--; for (int i = 0; i < len; ++i) push_back(c);}
PIString(const int len, const PIChar & c): PIDeque<PIChar>() {for (int i = 0; i < len; ++i) push_back(c);}
// PIString(const short & value): PIDeque<PIChar>() {/*reserve(4); */piMonitor.strings++; piMonitor.containers--; *this = fromNumber(value);}
// PIString(const ushort & value): PIDeque<PIChar>() {/*reserve(4); */piMonitor.strings++; piMonitor.containers--; *this = fromNumber(value);}
// PIString(const int & value): PIDeque<PIChar>() {/*reserve(4); */piMonitor.strings++; piMonitor.containers--; *this = fromNumber(value);}
// PIString(const uint & value): PIDeque<PIChar>() {/*reserve(4); */piMonitor.strings++; piMonitor.containers--; *this = fromNumber(value);}
// PIString(const long & value): PIDeque<PIChar>() {/*reserve(4); */piMonitor.strings++; piMonitor.containers--; *this = fromNumber(value);}
// PIString(const ulong & value): PIDeque<PIChar>() {/*reserve(4); */piMonitor.strings++; piMonitor.containers--; *this = fromNumber(value);}
// PIString(const llong & value): PIDeque<PIChar>() {/*reserve(4); */piMonitor.strings++; piMonitor.containers--; *this = fromNumber(value);}
// PIString(const ullong & value): PIDeque<PIChar>() {/*reserve(4); */piMonitor.strings++; piMonitor.containers--; *this = fromNumber(value);}
// PIString(const float & value): PIDeque<PIChar>() {/*reserve(4); */piMonitor.strings++; piMonitor.containers--; *this = fromNumber(value);}
// PIString(const double & value): PIDeque<PIChar>() {/*reserve(4); */piMonitor.strings++; piMonitor.containers--; *this = fromNumber(value);}
// PIString(const short & value): PIDeque<PIChar>() {*this = fromNumber(value);}
// PIString(const ushort & value): PIDeque<PIChar>() {*this = fromNumber(value);}
// PIString(const int & value): PIDeque<PIChar>() {*this = fromNumber(value);}
// PIString(const uint & value): PIDeque<PIChar>() {*this = fromNumber(value);}
// PIString(const long & value): PIDeque<PIChar>() {*this = fromNumber(value);}
// PIString(const ulong & value): PIDeque<PIChar>() {*this = fromNumber(value);}
// PIString(const llong & value): PIDeque<PIChar>() {*this = fromNumber(value);}
// PIString(const ullong & value): PIDeque<PIChar>() {*this = fromNumber(value);}
// PIString(const float & value): PIDeque<PIChar>() {*this = fromNumber(value);}
// PIString(const double & value): PIDeque<PIChar>() {*this = fromNumber(value);}
~PIString() {piMonitor.strings--; piMonitor.containers++;}
~PIString() {}
PIString & operator =(const PIString & o) {if (this == &o) return *this; clear(); *this += o; return *this;}

View File

@@ -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

View File

@@ -20,6 +20,8 @@
#include "piintrospection_containers.h"
#include "piintrospection_containers_p.h"
__PIINTROSPECTION_SINGLETON_CPP__(Containers)
PIIntrospectionContainersInterface::PIIntrospectionContainersInterface() {
p = new PIIntrospectionContainers();

View File

@@ -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

View File

@@ -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;
}

View File

@@ -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);
}

View File

@@ -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

View File

@@ -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)

View File

@@ -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);

View File

@@ -20,6 +20,8 @@
#include "piintrospection_threads.h"
#include "piintrospection_threads_p.h"
__PIINTROSPECTION_SINGLETON_CPP__(Threads)
PIIntrospectionThreadsInterface::PIIntrospectionThreadsInterface() {
p = new PIIntrospectionThreads();

View File

@@ -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);