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

This commit is contained in:
2019-06-17 18:32:02 +00:00
parent 6812b645d9
commit 71128017dd
24 changed files with 904 additions and 547 deletions

View File

@@ -1,119 +0,0 @@
/*
PIP - Platform Independent Primitives
Introspection module
Copyright (C) 2019 Ivan Pelipenko peri4ko@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "piintrospection.h"
#include "piincludes.h"
#include "pisysteminfo.h"
PIIntrospectionContainers::PIIntrospectionContainers() {
count = 0;
bytes_allocated = bytes_used = 0;
}
PIIntrospectionThreads::PIIntrospectionThreads() {
}
PIIntrospectionContainers * __PIIntrospectionContainers__::p = 0;
PIIntrospectionThreads * __PIIntrospectionThreads__::p = 0;
PIIntrospectionServer * __PIIntrospectionServer__::p = 0;
void PIIntrospectionThreads::registerThread(int id, short prior, const PIString & name) {
mutex.lock();
ThreadInfo & ti(threads[id]);
ti.id = id;
ti.priority = prior;
ti.name = name;
//piCout << "register thread" << id << name;
mutex.unlock();
}
void PIIntrospectionThreads::unregisterThread(int id) {
mutex.lock();
threads.remove(id);
mutex.unlock();
}
void PIIntrospectionContainers::containerNew() {
mutex.lock();
count++;
mutex.unlock();
}
void PIIntrospectionContainers::containerDelete() {
mutex.lock();
count--;
mutex.unlock();
}
void PIIntrospectionContainers::containerAlloc(ullong cnt) {
mutex.lock();
bytes_allocated += cnt;
mutex.unlock();
}
void PIIntrospectionContainers::containerFree(ullong cnt) {
mutex.lock();
bytes_allocated -= cnt;
mutex.unlock();
}
void PIIntrospectionContainers::containerUsed(ullong cnt) {
mutex.lock();
bytes_used += cnt;
mutex.unlock();
}
void PIIntrospectionContainers::containerUnused(ullong cnt) {
mutex.lock();
bytes_used -= cnt;
mutex.unlock();
}
PIIntrospectionServer::PIIntrospectionServer(): PIPeer(genName()) {
CONNECTU(&itimer, tickEvent, this, timerEvent)
itimer.start(100);
}
PIString PIIntrospectionServer::genName() {
randomize();
return "__introspection__server_" + PIString::fromNumber(randomi() % 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

@@ -1,115 +0,0 @@
/*
PIP - Platform Independent Primitives
Introspection module
Copyright (C) 2019 Ivan Pelipenko peri4ko@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PIINTROSPECTION_H
#define PIINTROSPECTION_H
#include "pipeer.h"
#include "pimutex.h"
class PIP_EXPORT PIIntrospectionThreads
{
friend class __PIIntrospectionThreads__;
public:
PIIntrospectionThreads();
struct ThreadInfo {
ThreadInfo() {id = 0; priority = 0;}
PIString name;
int id;
short priority;
};
void registerThread(int id, short prior, const PIString & name);
void unregisterThread(int id);
PIMap<int, ThreadInfo> threads;
PIMutex mutex;
};
class PIP_EXPORT PIIntrospectionContainers
{
friend class __PIIntrospectionContainers__;
public:
PIIntrospectionContainers();
void containerNew();
void containerDelete();
void containerAlloc(ullong cnt);
void containerFree(ullong cnt);
void containerUsed(ullong cnt);
void containerUnused(ullong cnt);
uint count;
ullong bytes_allocated;
ullong bytes_used;
PIMutex mutex;
};
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 itimer;
};
class __PIIntrospectionContainers__ {
public:
__PIIntrospectionContainers__() {if (!p) p = new PIIntrospectionContainers();}
static PIIntrospectionContainers * get() {static __PIIntrospectionContainers__ * r = new __PIIntrospectionContainers__(); return r->p;}
static PIIntrospectionContainers * p;
};
class __PIIntrospectionThreads__ {
public:
__PIIntrospectionThreads__() {if (!p) p = new PIIntrospectionThreads();}
static PIIntrospectionThreads * get() {static __PIIntrospectionThreads__ * r = new __PIIntrospectionThreads__(); return r->p;}
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;}
inline PIByteArray & operator >>(PIByteArray & b, PIIntrospectionContainers & v) {b >> v.count >> v.bytes_allocated >> v.bytes_used; return b;}
inline PIByteArray & operator >>(PIByteArray & b, PIIntrospectionThreads::ThreadInfo & v) {b >> v.id >> v.priority >> v.name; return b;}
#define PIINTROSPECTION_CONTAINERS __PIIntrospectionContainers__::get()
#define PIINTROSPECTION_THREADS __PIIntrospectionThreads__::get()
#define PIINTROSPECTION_SERVER __PIIntrospectionServer__::get()
#endif // PIINTROSPECTION_H

View File

@@ -1,32 +0,0 @@
/*
PIP - Platform Independent Primitives
Introspection module
Copyright (C) 2019 Ivan Pelipenko peri4ko@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#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);}
void __PIIntrospection__containerNew() {PIINTROSPECTION_CONTAINERS->containerNew();}
void __PIIntrospection__containerDelete() {PIINTROSPECTION_CONTAINERS->containerDelete();}
void __PIIntrospection__containerAlloc(ullong cnt) {PIINTROSPECTION_CONTAINERS->containerAlloc(cnt);}
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

@@ -1,69 +0,0 @@
/*
PIP - Platform Independent Primitives
Introspection module
Copyright (C) 2019 Ivan Pelipenko peri4ko@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PIINTROSPECTION_PROXY_H
#define PIINTROSPECTION_PROXY_H
#include "pibase.h"
class PIString;
void __PIIntrospection__registerThread(int id, short prior, const PIString & name);
void __PIIntrospection__unregisterThread(int id);
void __PIIntrospection__containerNew();
void __PIIntrospection__containerDelete();
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_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);
#else
# define PIINTROSPECTION_CONTAINER_NEW()
# define PIINTROSPECTION_CONTAINER_DELETE()
# define PIINTROSPECTION_CONTAINER_USED(tcnt)
# 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