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

This commit is contained in:
2016-03-02 08:09:01 +00:00
parent 0d77d3b425
commit 741615b9d3
11 changed files with 104 additions and 19 deletions

Binary file not shown.

View File

@@ -18,6 +18,7 @@
*/
#include "piintrospection.h"
#include "pisysteminfo.h"
PIIntrospectionContainers::PIIntrospectionContainers() {
@@ -32,6 +33,7 @@ PIIntrospectionThreads::PIIntrospectionThreads() {
PIIntrospectionContainers * __PIIntrospectionContainers__::p = 0;
PIIntrospectionThreads * __PIIntrospectionThreads__::p = 0;
PIIntrospectionServer * __PIIntrospectionServer__::p = 0;
void PIIntrospectionThreads::registerThread(int id, short prior, const PIString & name) {
@@ -92,3 +94,25 @@ void PIIntrospectionContainers::containerUnused(ullong cnt) {
bytes_used -= cnt;
mutex.unlock();
}
PIIntrospectionServer::PIIntrospectionServer(): PIPeer(genName()) {
CONNECTU(&timer, tickEvent, this, timerEvent)
timer.start(100);
}
PIString PIIntrospectionServer::genName() {
randomize();
return "__introspection__server_" + PIString::fromNumber(rand() % 1000);
}
void PIIntrospectionServer::timerEvent() {
PIByteArray ba;
PIINTROSPECTION_THREADS->mutex.lock();
ba << appname << *(PIINTROSPECTION_CONTAINERS) << PIINTROSPECTION_THREADS->threads.values();
PIINTROSPECTION_THREADS->mutex.unlock();
//piCout << "send" << appname;
send("__introspection_client__", ba);
}

View File

@@ -20,15 +20,16 @@
#ifndef PIINTROSPECTION_H
#define PIINTROSPECTION_H
#include "pistring.h"
#include "pipeer.h"
#include "pimutex.h"
class PIP_EXPORT PIIntrospectionThreads
{
friend class __PIIntrospectionThreads__;
PIIntrospectionThreads();
public:
PIIntrospectionThreads();
struct ThreadInfo {
ThreadInfo() {id = 0; priority = 0;}
PIString name;
@@ -47,8 +48,9 @@ public:
class PIP_EXPORT PIIntrospectionContainers
{
friend class __PIIntrospectionContainers__;
PIIntrospectionContainers();
public:
PIIntrospectionContainers();
void containerNew();
void containerDelete();
void containerAlloc(ullong cnt);
@@ -63,6 +65,20 @@ public:
};
class PIP_EXPORT PIIntrospectionServer: public PIPeer
{
PIOBJECT_SUBCLASS(PIIntrospectionServer, PIPeer)
friend class __PIIntrospectionServer__;
PIIntrospectionServer();
public:
PIString appname;
private:
EVENT_HANDLER(void, timerEvent);
PIString genName();
PITimer timer;
};
class __PIIntrospectionContainers__ {
public:
__PIIntrospectionContainers__() {if (!p) p = new PIIntrospectionContainers();}
@@ -70,7 +86,6 @@ public:
static PIIntrospectionContainers * p;
};
class __PIIntrospectionThreads__ {
public:
__PIIntrospectionThreads__() {if (!p) p = new PIIntrospectionThreads();}
@@ -78,6 +93,15 @@ public:
static PIIntrospectionThreads * p;
};
class __PIIntrospectionServer__ {
public:
__PIIntrospectionServer__() {if (!p) p = new PIIntrospectionServer();}
~__PIIntrospectionServer__() {if (!p) return; delete p; p = 0;}
static PIIntrospectionServer * get() {static __PIIntrospectionServer__ * r = new __PIIntrospectionServer__(); return r->p;}
static PIIntrospectionServer * p;
};
inline PIByteArray & operator <<(PIByteArray & b, const PIIntrospectionContainers & v) {b << v.count << v.bytes_allocated << v.bytes_used; return b;}
inline PIByteArray & operator <<(PIByteArray & b, const PIIntrospectionThreads::ThreadInfo & v) {b << v.id << v.priority << v.name; return b;}
@@ -86,5 +110,6 @@ inline PIByteArray & operator >>(PIByteArray & b, PIIntrospectionThreads::Thread
#define PIINTROSPECTION_CONTAINERS __PIIntrospectionContainers__::get()
#define PIINTROSPECTION_THREADS __PIIntrospectionThreads__::get()
#define PIINTROSPECTION_SERVER __PIIntrospectionServer__::get()
#endif // PIINTROSPECTION_H

View File

@@ -19,6 +19,7 @@
#include "piintrospection_proxy.h"
#include "piintrospection.h"
#include "pisysteminfo.h"
void __PIIntrospection__registerThread(int id, short prior, const PIString & name) {PIINTROSPECTION_THREADS->registerThread(id, prior, name);}
void __PIIntrospection__unregisterThread(int id) {PIINTROSPECTION_THREADS->unregisterThread(id);}
@@ -28,3 +29,4 @@ void __PIIntrospection__containerAlloc(ullong cnt) {PIINTROSPECTION_CONTAINERS->
void __PIIntrospection__containerFree(ullong cnt) {PIINTROSPECTION_CONTAINERS->containerFree(cnt);}
void __PIIntrospection__containerUsed(ullong cnt) {PIINTROSPECTION_CONTAINERS->containerUsed(cnt);}
void __PIIntrospection__containerUnused(ullong cnt) {PIINTROSPECTION_CONTAINERS->containerUnused(cnt);}
void __PIIntrospection__start() {PIINTROSPECTION_SERVER->appname = PISystemInfo::instance()->execCommand;}

View File

@@ -32,16 +32,15 @@ void __PIIntrospection__containerAlloc(ullong cnt);
void __PIIntrospection__containerFree(ullong cnt);
void __PIIntrospection__containerUsed(ullong cnt);
void __PIIntrospection__containerUnused(ullong cnt);
void __PIIntrospection__start();
#ifdef PIP_INTROSPECTION
#ifdef PIP_INTROSPECTION_CONTAINERS
# define PIINTROSPECTION_CONTAINER_NEW() __PIIntrospection__containerNew();
# define PIINTROSPECTION_CONTAINER_DELETE() __PIIntrospection__containerDelete();
# define PIINTROSPECTION_CONTAINER_USED(cnt) __PIIntrospection__containerUsed(cnt);
# define PIINTROSPECTION_CONTAINER_UNUSED(cnt) __PIIntrospection__containerUnused(cnt);
# define PIINTROSPECTION_CONTAINER_ALLOC(cnt) __PIIntrospection__containerAlloc(cnt);
# define PIINTROSPECTION_CONTAINER_FREE(cnt) __PIIntrospection__containerFree(cnt);
# define PIINTROSPECTION_REGISTER_THREAD(id, pr, name) __PIIntrospection__registerThread(id, pr, name);
# define PIINTROSPECTION_UNREGISTER_THREAD(id) __PIIntrospection__unregisterThread(id);
#else
# define PIINTROSPECTION_CONTAINER_NEW()
# define PIINTROSPECTION_CONTAINER_DELETE()
@@ -49,8 +48,22 @@ void __PIIntrospection__containerUnused(ullong cnt);
# define PIINTROSPECTION_CONTAINER_UNUSED(cnt)
# define PIINTROSPECTION_CONTAINER_ALLOC(cnt)
# define PIINTROSPECTION_CONTAINER_FREE(cnt)
#endif
#ifdef PIP_INTROSPECTION_THREADS
# define PIINTROSPECTION_REGISTER_THREAD(id, pr, name) __PIIntrospection__registerThread(id, pr, name);
# define PIINTROSPECTION_UNREGISTER_THREAD(id) __PIIntrospection__unregisterThread(id);
# define PIINTROSPECTION_START __PIIntrospection__start();
#else
# define PIINTROSPECTION_REGISTER_THREAD(id, pr, name)
# define PIINTROSPECTION_UNREGISTER_THREAD(id)
# define PIINTROSPECTION_START
#endif
#if defined(PIP_INTROSPECTION_CONTAINERS) || defined(PIP_INTROSPECTION_THREADS)
# define PIINTROSPECTION_START __PIIntrospection__start();
#else
# define PIINTROSPECTION_START
#endif
#endif // PIINTROSPECTION_PROXY_H