git-svn-id: svn://db.shs.com.ru/pip@819 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -28,6 +28,7 @@ class PIThread;
|
||||
class PITimer;
|
||||
class PIPeer;
|
||||
class PIIntrospection;
|
||||
class PIIntrospectionServer;
|
||||
|
||||
#ifdef PIP_INTROSPECTION
|
||||
#define __PIINTROSPECTION_SINGLETON_H__(T) \
|
||||
|
||||
@@ -23,13 +23,6 @@
|
||||
#include "piintrospection_base.h"
|
||||
|
||||
|
||||
//#if defined(__PIIS__)
|
||||
//# undef __PIIS__
|
||||
//#endif
|
||||
//# if defined(PIP_INTROSPECTION) && !defined(PIP_FORCE_NO_PIINTROSPECTION)
|
||||
//#endif
|
||||
|
||||
|
||||
#if defined(PIP_INTROSPECTION) && !defined(PIP_FORCE_NO_PIINTROSPECTION)
|
||||
class PIIntrospectionContainers;
|
||||
|
||||
|
||||
@@ -17,8 +17,6 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef PIP_INTROSPECTION
|
||||
|
||||
#include "piintrospection_containers_p.h"
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -95,9 +93,9 @@ uint PIIntrospectionContainers::typeID(const char * tn) {
|
||||
|
||||
|
||||
|
||||
PIByteArray & operator <<(PIByteArray & s, const std::unordered_map<uint, std::string> & v) {
|
||||
PIByteArray & operator <<(PIByteArray & s, const std::map<uint, std::string> & v) {
|
||||
PIMap<uint, PIString> m;
|
||||
for (typename std::unordered_map<uint, std::string>::const_iterator i = v.cbegin(); i != v.cend(); ++i) {
|
||||
for (typename std::map<uint, std::string>::const_iterator i = v.cbegin(); i != v.cend(); ++i) {
|
||||
m[i->first] = PIStringAscii(i->second.c_str());
|
||||
}
|
||||
s << m;
|
||||
@@ -113,5 +111,3 @@ PIByteArray & operator >>(PIByteArray & s, PIIntrospectionContainers::Type & v)
|
||||
s >> v.count >> v.items >> v.bytes_allocated >> v.bytes_used;
|
||||
return s;
|
||||
}
|
||||
|
||||
#endif //PIP_INTROSPECTION
|
||||
|
||||
@@ -20,10 +20,8 @@
|
||||
#ifndef PIINTROSPECTION_CONTAINERS_P_H
|
||||
#define PIINTROSPECTION_CONTAINERS_P_H
|
||||
|
||||
#ifdef PIP_INTROSPECTION
|
||||
|
||||
#include "pimutex.h"
|
||||
#include <unordered_map>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include "picrc.h"
|
||||
|
||||
@@ -49,16 +47,15 @@ public:
|
||||
ullong bytes_used;
|
||||
};
|
||||
|
||||
std::unordered_map<uint, Type> data;
|
||||
std::unordered_map<uint, std::string> typenames;
|
||||
std::map<uint, Type> data;
|
||||
std::map<uint, std::string> typenames;
|
||||
PIMutex mutex;
|
||||
CRC_32 crc;
|
||||
};
|
||||
|
||||
PIByteArray & operator <<(PIByteArray & s, const std::unordered_map<uint, std::string> & v);
|
||||
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);
|
||||
|
||||
#endif // PIP_INTROSPECTION
|
||||
#endif // PIINTROSPECTION_CONTAINERS_P_H
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
|
||||
#include "piintrospection_server.h"
|
||||
#include "piintrospection_server_p.h"
|
||||
#include "piprocess.h"
|
||||
#include "pichunkstream.h"
|
||||
|
||||
|
||||
@@ -31,15 +32,32 @@ PRIVATE_DEFINITION_END(PIIntrospectionServer)
|
||||
|
||||
PIIntrospectionServer::PIIntrospectionServer(): PIPeer(genName()) {
|
||||
PRIVATE->process_info = PIIntrospection::getInfo();
|
||||
sysmon = 0;
|
||||
}
|
||||
|
||||
|
||||
PIIntrospectionServer::~PIIntrospectionServer() {
|
||||
PIPeer::stop();
|
||||
if (sysmon)
|
||||
if (sysmon->property("__iserver__").toBool())
|
||||
delete sysmon;
|
||||
sysmon = 0;
|
||||
}
|
||||
|
||||
|
||||
void PIIntrospectionServer::start() {
|
||||
if (!sysmon) {
|
||||
sysmon = PISystemMonitor::Pool::instance()->getByPID(PIProcess::currentPID());
|
||||
if (sysmon) {
|
||||
piCoutObj << "using existing sysmon";
|
||||
CONNECTU(sysmon, deleted, this, sysmonDeleted);
|
||||
} else {
|
||||
piCoutObj << "create own sysmon";
|
||||
sysmon = new PISystemMonitor();
|
||||
sysmon->setProperty("__iserver__", true);
|
||||
sysmon->startOnSelf();
|
||||
}
|
||||
}
|
||||
PIPeer::start();
|
||||
}
|
||||
|
||||
@@ -60,6 +78,11 @@ void PIIntrospectionServer::dataReceived(const PIString & from, const PIByteArra
|
||||
PIChunkStream cs;
|
||||
if (ri.types[PIIntrospection::itInfo])
|
||||
cs.add(PIIntrospection::itInfo, PIIntrospection::packInfo());
|
||||
if (ri.types[PIIntrospection::itProcStat]) {
|
||||
sysmon_mutex.lock();
|
||||
cs.add(PIIntrospection::itProcStat, PIIntrospection::packProcStat(sysmon));
|
||||
sysmon_mutex.unlock();
|
||||
}
|
||||
if (ri.types[PIIntrospection::itContainers])
|
||||
cs.add(PIIntrospection::itContainers, PIIntrospection::packContainers());
|
||||
if (ri.types[PIIntrospection::itObjects])
|
||||
@@ -72,5 +95,10 @@ void PIIntrospectionServer::dataReceived(const PIString & from, const PIByteArra
|
||||
send(from, ba);
|
||||
}
|
||||
|
||||
#endif // PIP_INTROSPECTION
|
||||
|
||||
void PIIntrospectionServer::sysmonDeleted() {
|
||||
PIMutexLocker _ml(sysmon_mutex);
|
||||
sysmon = 0;
|
||||
}
|
||||
|
||||
#endif // PIP_INTROSPECTION
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#if defined(PIP_INTROSPECTION) && !defined(PIP_FORCE_NO_PIINTROSPECTION)
|
||||
|
||||
class PIIntrospectionServer;
|
||||
class PISystemMonitor;
|
||||
|
||||
# define PIINTROSPECTION_SERVER (PIIntrospectionServer::instance())
|
||||
# define PIINTROSPECTION_START PIINTROSPECTION_SERVER->start();
|
||||
@@ -44,9 +45,13 @@ private:
|
||||
|
||||
PIString genName();
|
||||
virtual void dataReceived(const PIString & from, const PIByteArray & data);
|
||||
EVENT_HANDLER(void, sysmonDeleted);
|
||||
|
||||
PRIVATE_DECLARATION
|
||||
PITimer itimer;
|
||||
PISystemMonitor * sysmon;
|
||||
PIMutex sysmon_mutex;
|
||||
|
||||
};
|
||||
|
||||
#else
|
||||
|
||||
@@ -17,8 +17,6 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef PIP_INTROSPECTION
|
||||
|
||||
#include "piintrospection_server_p.h"
|
||||
#include "pichunkstream.h"
|
||||
#include "piinit.h"
|
||||
@@ -88,9 +86,9 @@ PIVector<PIIntrospection::ObjectInfo> PIIntrospection::getObjects() {
|
||||
}
|
||||
|
||||
|
||||
PIByteArray & operator <<(PIByteArray & s, const std::unordered_map<uint, PIIntrospectionContainers::Type> & v) {
|
||||
PIByteArray & operator <<(PIByteArray & s, const std::map<uint, PIIntrospectionContainers::Type> & v) {
|
||||
PIMap<uint, PIIntrospectionContainers::Type> m;
|
||||
for (typename std::unordered_map<uint, PIIntrospectionContainers::Type>::const_iterator i = v.cbegin(); i != v.cend(); ++i) {
|
||||
for (typename std::map<uint, PIIntrospectionContainers::Type>::const_iterator i = v.cbegin(); i != v.cend(); ++i) {
|
||||
m[i->first] = i->second;
|
||||
}
|
||||
s << m;
|
||||
@@ -188,13 +186,37 @@ void PIIntrospection::unpackInfo(PIByteArray & ba, PIIntrospection::ProcessInfo
|
||||
}
|
||||
|
||||
|
||||
PIByteArray PIIntrospection::packProcStat(PISystemMonitor * sm) {
|
||||
ProcessStat ps;
|
||||
if (sm) {
|
||||
ps.proc = sm->statistic();
|
||||
ps.threads = sm->threadsStatistic();
|
||||
}
|
||||
PIByteArray ret;
|
||||
ret << ps.proc << ps.threads;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void PIIntrospection::unpackProcStat(PIByteArray & ba, PIIntrospection::ProcessStat & info) {
|
||||
ba >> info.proc >> info.threads;
|
||||
}
|
||||
|
||||
|
||||
PIByteArray PIIntrospection::packContainers() {
|
||||
PIByteArray ret;
|
||||
PIIntrospectionContainers * p = PIINTROSPECTION_CONTAINERS->p;
|
||||
p->mutex.lock();
|
||||
std::unordered_map<uint, PIIntrospectionContainers::Type> data = p->data;
|
||||
std::unordered_map<uint, std::string> typenames = p->typenames;
|
||||
p->mutex.unlock();
|
||||
std::map<uint, PIIntrospectionContainers::Type> data;
|
||||
std::map<uint, std::string> typenames;
|
||||
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();
|
||||
}
|
||||
ret << data << typenames;
|
||||
return ret;
|
||||
}
|
||||
@@ -209,15 +231,22 @@ void PIIntrospection::unpackContainers(PIByteArray & ba, PIMap<uint, PIIntrospec
|
||||
|
||||
PIByteArray PIIntrospection::packThreads() {
|
||||
PIByteArray ret;
|
||||
PIIntrospectionThreads * p = PIINTROSPECTION_THREADS->p;
|
||||
p->mutex.lock();
|
||||
PIMap<PIThread*, PIIntrospectionThreads::ThreadInfo> & tm(p->threads);
|
||||
for (PIMap<PIThread*, PIIntrospectionThreads::ThreadInfo>::iterator i = tm.begin(); i != tm.end(); ++i) {
|
||||
i.value().classname = PIStringAscii(i.key()->className());
|
||||
i.value().name = i.key()->name();
|
||||
PIIntrospectionThreads * p = 0;
|
||||
#ifdef PIP_INTROSPECTION
|
||||
p = PIINTROSPECTION_THREADS->p;
|
||||
#endif
|
||||
if (p) {
|
||||
p->mutex.lock();
|
||||
PIMap<PIThread*, PIIntrospectionThreads::ThreadInfo> & tm(p->threads);
|
||||
for (PIMap<PIThread*, PIIntrospectionThreads::ThreadInfo>::iterator i = tm.begin(); i != tm.end(); ++i) {
|
||||
i.value().classname = PIStringAscii(i.key()->className());
|
||||
i.value().name = i.key()->name();
|
||||
}
|
||||
ret << tm.values();
|
||||
p->mutex.unlock();
|
||||
} else {
|
||||
ret << PIVector<PIIntrospectionThreads::ThreadInfo>();
|
||||
}
|
||||
ret << tm.values();
|
||||
p->mutex.unlock();
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -239,5 +268,3 @@ void PIIntrospection::unpackObjects(PIByteArray & ba, PIVector<PIIntrospection::
|
||||
objects.clear();
|
||||
ba >> objects;
|
||||
}
|
||||
|
||||
#endif // PIP_INTROSPECTION
|
||||
|
||||
@@ -20,13 +20,11 @@
|
||||
#ifndef PIINTROSPECTION_SERVER_P_H
|
||||
#define PIINTROSPECTION_SERVER_P_H
|
||||
|
||||
#ifdef PIP_INTROSPECTION
|
||||
|
||||
#include "piintrospection_containers.h"
|
||||
#include "piintrospection_containers_p.h"
|
||||
#include "piintrospection_threads.h"
|
||||
#include "piintrospection_threads_p.h"
|
||||
#include "pitime.h"
|
||||
#include "pisystemmonitor.h"
|
||||
|
||||
|
||||
class PIIntrospection {
|
||||
@@ -34,9 +32,10 @@ public:
|
||||
|
||||
enum InfoTypes {
|
||||
itInfo = 0x01,
|
||||
itContainers = 0x02,
|
||||
itObjects = 0x04,
|
||||
itThreads = 0x08,
|
||||
itProcStat = 0x02,
|
||||
itContainers = 0x04,
|
||||
itObjects = 0x08,
|
||||
itThreads = 0x10,
|
||||
};
|
||||
|
||||
struct RequiredInfo {
|
||||
@@ -54,6 +53,13 @@ public:
|
||||
PIStringList build_options;
|
||||
};
|
||||
|
||||
struct ProcessStat {
|
||||
ProcessStat() {}
|
||||
|
||||
PISystemMonitor::ProcessStats proc;
|
||||
PIVector<PISystemMonitor::ThreadStats> threads;
|
||||
};
|
||||
|
||||
struct ObjectInfo {
|
||||
ObjectInfo();
|
||||
|
||||
@@ -71,6 +77,9 @@ public:
|
||||
static PIByteArray packInfo();
|
||||
static void unpackInfo(PIByteArray & ba, ProcessInfo & info);
|
||||
|
||||
static PIByteArray packProcStat(PISystemMonitor * sm);
|
||||
static void unpackProcStat(PIByteArray & ba, ProcessStat & info);
|
||||
|
||||
static PIByteArray packContainers();
|
||||
static void unpackContainers(PIByteArray & ba, PIMap<uint, PIIntrospectionContainers::Type> & data, PIMap<uint, PIString> & typenames);
|
||||
|
||||
@@ -82,7 +91,7 @@ public:
|
||||
|
||||
};
|
||||
|
||||
PIByteArray & operator <<(PIByteArray & s, const std::unordered_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);
|
||||
@@ -93,5 +102,4 @@ PIByteArray & operator >>(PIByteArray & b, PIIntrospection::ProcessInfo & v);
|
||||
PIByteArray & operator <<(PIByteArray & b, const PIIntrospection::ObjectInfo & v);
|
||||
PIByteArray & operator >>(PIByteArray & b, PIIntrospection::ObjectInfo & v);
|
||||
|
||||
#endif // PIP_INTROSPECTION
|
||||
#endif // PIINTROSPECTION_SERVER_P_H
|
||||
|
||||
@@ -17,8 +17,6 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef PIP_INTROSPECTION
|
||||
|
||||
#include "piintrospection_threads_p.h"
|
||||
|
||||
|
||||
@@ -100,5 +98,3 @@ PIByteArray & operator >>(PIByteArray & b, PIIntrospectionThreads::ThreadInfo &
|
||||
v.state = (PIIntrospectionThreads::ThreadState)st;
|
||||
return b;
|
||||
}
|
||||
|
||||
#endif // PIP_INTROSPECTION
|
||||
|
||||
@@ -20,8 +20,6 @@
|
||||
#ifndef PIINTROSPECTION_THREADS_P_H
|
||||
#define PIINTROSPECTION_THREADS_P_H
|
||||
|
||||
#ifdef PIP_INTROSPECTION
|
||||
|
||||
#include "pimap.h"
|
||||
#include "pithread.h"
|
||||
|
||||
@@ -62,5 +60,4 @@ public:
|
||||
PIByteArray & operator <<(PIByteArray & b, const PIIntrospectionThreads::ThreadInfo & v);
|
||||
PIByteArray & operator >>(PIByteArray & b, PIIntrospectionThreads::ThreadInfo & v);
|
||||
|
||||
#endif // PIP_INTROSPECTION
|
||||
#endif // PIINTROSPECTION_THREADS_P_H
|
||||
|
||||
Reference in New Issue
Block a user