version 1.22.0

source tree changed
detached PIConsole and PIScreen* in "pip_console" library
This commit is contained in:
2020-06-28 00:18:24 +03:00
parent 5de62b1c83
commit 42925122cb
231 changed files with 22981 additions and 22948 deletions

View File

@@ -0,0 +1,43 @@
/*
PIP - Platform Independent Primitives
Introspection module - base macros and types
Ivan Pelipenko peri4ko@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PIINTROSPECTION_BASE_H
#define PIINTROSPECTION_BASE_H
#include "pibase.h"
class PIString;
class PIMutex;
class PIThread;
class PITimer;
class PIPeer;
class PIIntrospection;
class PIIntrospectionServer;
#ifdef PIP_INTROSPECTION
#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 // PIP_INTROSPECTION
#endif // PIINTROSPECTION_BASE_H

View File

@@ -0,0 +1,67 @@
/*
PIP - Platform Independent Primitives
Introspection module - interface for containers
Ivan Pelipenko peri4ko@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "piintrospection_containers.h"
#include "piintrospection_containers_p.h"
#ifdef PIP_INTROSPECTION
__PIINTROSPECTION_SINGLETON_CPP__(Containers)
PIIntrospectionContainersInterface::PIIntrospectionContainersInterface() {
p = new PIIntrospectionContainers();
}
PIIntrospectionContainersInterface::~PIIntrospectionContainersInterface() {
delete p;
}
void PIIntrospectionContainersInterface::containerNew(const char * tn, uint isz) {
p->containerNew(tn, isz);
}
void PIIntrospectionContainersInterface::containerDelete(const char * tn) {
p->containerDelete(tn);
}
void PIIntrospectionContainersInterface::containerAlloc(const char * tn, ullong cnt) {
p->containerAlloc(tn, cnt);
}
void PIIntrospectionContainersInterface::containerFree(const char * tn, ullong cnt) {
p->containerFree(tn, cnt);
}
void PIIntrospectionContainersInterface::containerUsed(const char * tn, ullong cnt) {
p->containerUsed(tn, cnt);
}
void PIIntrospectionContainersInterface::containerUnused(const char * tn, ullong cnt) {
p->containerUnused(tn, cnt);
}
#endif

View File

@@ -0,0 +1,79 @@
/*
PIP - Platform Independent Primitives
Introspection module - interface for containers
Ivan Pelipenko peri4ko@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PIINTROSPECTION_CONTAINERS_H
#define PIINTROSPECTION_CONTAINERS_H
#include "piintrospection_base.h"
#if defined(PIP_INTROSPECTION) && !defined(PIP_FORCE_NO_PIINTROSPECTION)
class PIIntrospectionContainers;
#define PIINTROSPECTION_CONTAINERS (PIIntrospectionContainersInterface::instance())//(PIIntrospectionContainersInterface::instance())
#ifdef CC_GCC
# include <typeinfo>
# define _PIIS_TYPENAME_(t) typeid(t).name()
#else
# define _PIIS_TYPENAME_(t) ""
#endif
# define PIINTROSPECTION_CONTAINER_NEW(t, isz) PIINTROSPECTION_CONTAINERS->containerNew (_PIIS_TYPENAME_(t), isz);
# define PIINTROSPECTION_CONTAINER_DELETE(t) PIINTROSPECTION_CONTAINERS->containerDelete(_PIIS_TYPENAME_(t));
# define PIINTROSPECTION_CONTAINER_ALLOC(t, cnt) PIINTROSPECTION_CONTAINERS->containerAlloc (_PIIS_TYPENAME_(t), cnt);
# define PIINTROSPECTION_CONTAINER_FREE(t, cnt) PIINTROSPECTION_CONTAINERS->containerFree (_PIIS_TYPENAME_(t), cnt);
# define PIINTROSPECTION_CONTAINER_USED(t, cnt) PIINTROSPECTION_CONTAINERS->containerUsed (_PIIS_TYPENAME_(t), cnt);
# define PIINTROSPECTION_CONTAINER_UNUSED(t, cnt) PIINTROSPECTION_CONTAINERS->containerUnused(_PIIS_TYPENAME_(t), cnt);
class PIP_EXPORT PIIntrospectionContainersInterface {
friend class PIIntrospection;
friend class PIIntrospectionServer;
public:
__PIINTROSPECTION_SINGLETON_H__(Containers)
void containerNew (const char * tn, uint isz);
void containerDelete(const char * tn);
void containerAlloc (const char * tn, ullong cnt);
void containerFree (const char * tn, ullong cnt);
void containerUsed (const char * tn, ullong cnt);
void containerUnused(const char * tn, ullong cnt);
PIIntrospectionContainers * p;
private:
PIIntrospectionContainersInterface();
~PIIntrospectionContainersInterface();
};
#else
# define PIINTROSPECTION_CONTAINER_NEW(t, isz)
# define PIINTROSPECTION_CONTAINER_DELETE(t)
# define PIINTROSPECTION_CONTAINER_ALLOC(t, cnt)
# define PIINTROSPECTION_CONTAINER_FREE(t, cnt)
# define PIINTROSPECTION_CONTAINER_USED(t, cnt)
# define PIINTROSPECTION_CONTAINER_UNUSED(t, cnt)
#endif
#endif // PIINTROSPECTION_CONTAINERS_H

View File

@@ -0,0 +1,139 @@
/*
PIP - Platform Independent Primitives
Introspection module - implementation of containers
Ivan Pelipenko peri4ko@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "piintrospection_containers_p.h"
#include <stdio.h>
#ifdef CC_GCC
# include <cxxabi.h>
const PIString demangle(const char * name) {
int status = -4;
char * res = abi::__cxa_demangle(name, NULL, NULL, &status);
PIString ret((status == 0) ? res : name);
free(res);
return ret;
}
#else
const PIString demangle(const char * name) {return PIString(name);}
#endif
PIIntrospectionContainers::_Type::_Type() {
id = count = item_size = 0u;
allocated = used = 0U;
}
PIIntrospectionContainers::PIIntrospectionContainers() {
//printf("PIIntrospectionContainers %p\n", this);
}
void PIIntrospectionContainers::containerNew(const char * tn, uint isz) {
uint id = typeID(tn);
PIMutexLocker _ml(mutex);
//printf("containerNew lock\n");
std::string & n(typenames[id]);
_Type & d(data[id]);
if (n.empty()) {
n = tn;
d.id = id;
d.item_size = isz;
}
d.count++;
//printf("containerNew unlock\n");
}
void PIIntrospectionContainers::containerDelete(const char * tn) {
PIMutexLocker _ml(mutex);
data[typeID(tn)].count--;
}
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)].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)].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)].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)].used -= cnt;
}
uint PIIntrospectionContainers::typeID(const char * tn) {
if (!tn) return 0u;
size_t l = strlen(tn);
if (l == 0) return 0u;
return piHashData((const uchar*)tn, int(l));
}
PIVector<PIIntrospectionContainers::TypeInfo> PIIntrospectionContainers::getInfo() const {
PIVector<PIIntrospectionContainers::TypeInfo> ret;
mutex.lock();
std::map<uint, PIIntrospectionContainers::_Type> d = data;
std::map<uint, std::string> t = typenames;
mutex.unlock();
ret.reserve(t.size());
for (typename std::map<uint, std::string>::const_iterator i = t.begin(); i != t.end(); ++i) {
ret.push_back(TypeInfo());
TypeInfo & ti(ret.back());
_Type & _t(d[i->first]);
memcpy((void*)&ti, (const void*)&_t, sizeof(_t));
ti.name = demangle(i->second.c_str());
}
return ret;
}
PIByteArray & operator <<(PIByteArray & s, const PIIntrospectionContainers::TypeInfo & v) {
s << PIByteArray::RawData(&v, sizeof(PIIntrospectionContainers::_Type)) << v.name;
return s;
}
PIByteArray & operator >>(PIByteArray & s, PIIntrospectionContainers::TypeInfo & v) {
s >> PIByteArray::RawData(&v, sizeof(PIIntrospectionContainers::_Type)) >> v.name;
return s;
}

View File

@@ -0,0 +1,69 @@
/*
PIP - Platform Independent Primitives
Introspection module - implementation of containers
Ivan Pelipenko peri4ko@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PIINTROSPECTION_CONTAINERS_P_H
#define PIINTROSPECTION_CONTAINERS_P_H
#include "pimutex.h"
#include <map>
#include <string>
#include "picrc.h"
class PIP_EXPORT PIIntrospectionContainers {
public:
PIIntrospectionContainers();
struct TypeInfo;
void containerNew (const char * tn, uint isz);
void containerDelete(const char * tn);
void containerAlloc (const char * tn, ullong cnt);
void containerFree (const char * tn, ullong cnt);
void containerUsed (const char * tn, ullong cnt);
void containerUnused(const char * tn, ullong cnt);
uint typeID(const char * tn);
PIVector<TypeInfo> getInfo() const;
#pragma pack(push, 1)
struct _Type {
_Type();
uint id;
uint count;
uint item_size;
ullong allocated;
ullong used;
};
#pragma pack(pop)
struct TypeInfo: _Type {
PIString name;
};
std::map<uint, _Type> data;
std::map<uint, std::string> typenames;
mutable PIMutex mutex;
};
PIByteArray & operator <<(PIByteArray & s, const PIIntrospectionContainers::TypeInfo & v);
PIByteArray & operator >>(PIByteArray & s, PIIntrospectionContainers::TypeInfo & v);
#endif // PIINTROSPECTION_CONTAINERS_P_H

View File

@@ -0,0 +1,104 @@
/*
PIP - Platform Independent Primitives
Introspection module
Ivan Pelipenko peri4ko@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef PIP_INTROSPECTION
#include "piintrospection_server.h"
#include "piintrospection_server_p.h"
#include "piprocess.h"
#include "pichunkstream.h"
PRIVATE_DEFINITION_START(PIIntrospectionServer)
PIIntrospection::ProcessInfo process_info;
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();
}
PIString PIIntrospectionServer::genName() {
randomize();
return "__introspection__server_" + PIString::fromNumber(randomi() % 1000);
}
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;
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])
cs.add(PIIntrospection::itObjects, PIIntrospection::packObjects());
if (ri.types[PIIntrospection::itThreads])
cs.add(PIIntrospection::itThreads, PIIntrospection::packThreads());
PIByteArray ba;
ba << PIIntrospection::sign;
ba.append(cs.data());
send(from, ba);
}
void PIIntrospectionServer::sysmonDeleted() {
PIMutexLocker _ml(sysmon_mutex);
sysmon = 0;
}
#endif // PIP_INTROSPECTION

View File

@@ -0,0 +1,61 @@
/*
PIP - Platform Independent Primitives
Introspection module
Ivan Pelipenko peri4ko@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PIINTROSPECTION_SERVER_H
#define PIINTROSPECTION_SERVER_H
#include "pipeer.h"
#if defined(PIP_INTROSPECTION) && !defined(PIP_FORCE_NO_PIINTROSPECTION)
class PIIntrospectionServer;
class PISystemMonitor;
# define PIINTROSPECTION_SERVER (PIIntrospectionServer::instance())
# define PIINTROSPECTION_START PIINTROSPECTION_SERVER->start();
class PIP_EXPORT PIIntrospectionServer: public PIPeer {
PIOBJECT_SUBCLASS(PIIntrospectionServer, PIPeer)
public:
static PIIntrospectionServer * instance() {static PIIntrospectionServer ret; return &ret;}
void start();
private:
PIIntrospectionServer();
~PIIntrospectionServer();
NO_COPY_CLASS(PIIntrospectionServer)
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
# define PIINTROSPECTION_START
#endif
#endif // PIINTROSPECTION_SERVER_H

View File

@@ -0,0 +1,246 @@
/*
PIP - Platform Independent Primitives
Introspection module - Base server structs
Ivan Pelipenko peri4ko@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "piintrospection_server_p.h"
#include "pichunkstream.h"
#include "piinit.h"
#include "pisysteminfo.h"
#include "piobject.h"
const uint PIIntrospection::sign = 0x0F1C2B3A;
PIIntrospection::RequiredInfo::RequiredInfo() {
types = itInfo;
}
PIIntrospection::ProcessInfo::ProcessInfo() {
processorsCount = 0;
}
PIIntrospection::ObjectInfo::ObjectInfo() {
queued_events = 0;
}
PIIntrospection::ProcessInfo PIIntrospection::getInfo() {
PIIntrospection::ProcessInfo ret;
PISystemInfo * si = PISystemInfo::instance();
ret.architecture = si->architecture;
ret.execCommand = si->execCommand;
ret.execDateTime = si->execDateTime;
ret.hostname = si->hostname;
ret.OS_name = si->OS_name;
ret.OS_version = si->OS_version;
ret.processorsCount = si->processorsCount;
ret.user = si->user;
ret.build_options = PIInit::buildOptions();
return ret;
}
PIVector<PIIntrospection::ObjectInfo> PIIntrospection::getObjects() {
PIVector<PIIntrospection::ObjectInfo> ret;
PIObject::mutexObjects().lock();
const PIVector<PIObject * > & ao(PIObject::objects());
ret.resize(ao.size());
for (int i = 0; i < ao.size_s(); ++i) {
ret[i].classname = PIStringAscii(ao[i]->className());
ret[i].name = ao[i]->name();
ret[i].properties = ao[i]->properties();
ret[i].parents = ao[i]->scopeList();
ao[i]->mutex_queue.lock();
ret[i].queued_events = ao[i]->events_queue.size_s();
ao[i]->mutex_queue.unlock();
}
PIObject::mutexObjects().unlock();
return ret;
}
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)
.add(6, v.OS_version).add(7, v.processorsCount).add(8, v.user).add(9, v.build_options);
b << cs.data();
return b;
}
PIByteArray & operator >>(PIByteArray & b, PIIntrospection::ProcessInfo & v) {
PIByteArray csba; b >> csba;
PIChunkStream cs(csba);
while (!cs.atEnd()) {
switch (cs.read()) {
case 1: cs.get(v.architecture); break;
case 2: cs.get(v.execCommand); break;
case 3: cs.get(v.execDateTime); break;
case 4: cs.get(v.hostname); break;
case 5: cs.get(v.OS_name); break;
case 6: cs.get(v.OS_version); break;
case 7: cs.get(v.processorsCount); break;
case 8: cs.get(v.user); break;
case 9: cs.get(v.build_options); break;
default: break;
}
}
return b;
}
PIByteArray & operator <<(PIByteArray & b, const PIIntrospection::ObjectInfo & v) {
PIChunkStream cs;
cs.add(1, v.classname).add(2, v.name).add(3, v.parents).add(4, v.properties).add(5, v.queued_events);
b << cs.data();
return b;
}
PIByteArray & operator >>(PIByteArray & b, PIIntrospection::ObjectInfo & v) {
PIByteArray csba; b >> csba;
PIChunkStream cs(csba);
while (!cs.atEnd()) {
switch (cs.read()) {
case 1: cs.get(v.classname); break;
case 2: cs.get(v.name); break;
case 3: cs.get(v.parents); break;
case 4: cs.get(v.properties); break;
case 5: cs.get(v.queued_events); break;
default: break;
}
}
return b;
}
PIByteArray PIIntrospection::packInfo() {
PIByteArray ret;
ret << getInfo();
return ret;
}
void PIIntrospection::unpackInfo(PIByteArray & ba, PIIntrospection::ProcessInfo & info) {
ba >> info;
}
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;
PIVector<PIIntrospectionContainers::TypeInfo> data;
PIIntrospectionContainers * p = 0;
#ifdef PIP_INTROSPECTION
p = PIINTROSPECTION_CONTAINERS->p;
#endif
if (p) {
data = p->getInfo();
}
ret << data;
return ret;
}
void PIIntrospection::unpackContainers(PIByteArray & ba, PIVector<PIIntrospectionContainers::TypeInfo> & data) {
data.clear();
ba >> data;
}
PIByteArray PIIntrospection::packThreads() {
PIByteArray ret;
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>();
}
return ret;
}
void PIIntrospection::unpackThreads(PIByteArray & ba, PIVector<PIIntrospectionThreads::ThreadInfo> & threads) {
threads.clear();
ba >> threads;
}
PIByteArray PIIntrospection::packObjects() {
PIByteArray ret;
ret << getObjects();
return ret;
}
void PIIntrospection::unpackObjects(PIByteArray & ba, PIVector<PIIntrospection::ObjectInfo> & objects) {
objects.clear();
ba >> objects;
}

View File

@@ -0,0 +1,103 @@
/*
PIP - Platform Independent Primitives
Introspection module - Base server structs
Ivan Pelipenko peri4ko@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PIINTROSPECTION_SERVER_P_H
#define PIINTROSPECTION_SERVER_P_H
#include "piintrospection_containers.h"
#include "piintrospection_containers_p.h"
#include "piintrospection_threads.h"
#include "piintrospection_threads_p.h"
#include "pisystemmonitor.h"
class PIIntrospection {
public:
enum InfoTypes {
itInfo = 0x01,
itProcStat = 0x02,
itContainers = 0x04,
itObjects = 0x08,
itThreads = 0x10,
};
struct RequiredInfo {
RequiredInfo();
PIFlags<InfoTypes> types;
};
struct ProcessInfo {
ProcessInfo();
PIString execCommand, hostname, user, OS_name, OS_version, architecture;
PIDateTime execDateTime;
int processorsCount;
PIStringList build_options;
};
struct ProcessStat {
ProcessStat() {}
PISystemMonitor::ProcessStats proc;
PIVector<PISystemMonitor::ThreadStats> threads;
};
struct ObjectInfo {
ObjectInfo();
PIString classname, name;
PIStringList parents;
PIMap<PIString, PIVariant> properties;
int queued_events;
};
static const uint sign;
static ProcessInfo getInfo();
static PIVector<ObjectInfo> getObjects();
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, PIVector<PIIntrospectionContainers::TypeInfo> & data);
static PIByteArray packThreads();
static void unpackThreads(PIByteArray & ba, PIVector<PIIntrospectionThreads::ThreadInfo> & threads);
static PIByteArray packObjects();
static void unpackObjects(PIByteArray & ba, PIVector<PIIntrospection::ObjectInfo> & objects);
};
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);
PIByteArray & operator <<(PIByteArray & b, const PIIntrospection::ObjectInfo & v);
PIByteArray & operator >>(PIByteArray & b, PIIntrospection::ObjectInfo & v);
#endif // PIINTROSPECTION_SERVER_P_H

View File

@@ -0,0 +1,72 @@
/*
PIP - Platform Independent Primitives
Introspection module - interface for threads
Ivan Pelipenko peri4ko@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef PIP_INTROSPECTION
#include "piintrospection_threads.h"
#include "piintrospection_threads_p.h"
__PIINTROSPECTION_SINGLETON_CPP__(Threads)
PIIntrospectionThreadsInterface::PIIntrospectionThreadsInterface() {
p = new PIIntrospectionThreads();
}
PIIntrospectionThreadsInterface::~PIIntrospectionThreadsInterface() {
delete p;
}
void PIIntrospectionThreadsInterface::threadNew(PIThread * t) {
p->threadNew(t);
}
void PIIntrospectionThreadsInterface::threadDelete(PIThread * t) {
p->threadDelete(t);
}
void PIIntrospectionThreadsInterface::threadStart(PIThread * t) {
p->threadStart(t);
}
void PIIntrospectionThreadsInterface::threadRun(PIThread * t) {
p->threadRun(t);
}
void PIIntrospectionThreadsInterface::threadWait(PIThread * t) {
p->threadWait(t);
}
void PIIntrospectionThreadsInterface::threadStop(PIThread * t) {
p->threadStop(t);
}
void PIIntrospectionThreadsInterface::threadRunDone(PIThread * t, ullong us) {
p->threadRunDone(t, us);
}
#endif // PIP_INTROSPECTION

View File

@@ -0,0 +1,71 @@
/*
PIP - Platform Independent Primitives
Introspection module - interface for threads
Ivan Pelipenko peri4ko@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PIINTROSPECTION_THREADS_H
#define PIINTROSPECTION_THREADS_H
#include "piintrospection_base.h"
#if defined(PIP_INTROSPECTION) && !defined(PIP_FORCE_NO_PIINTROSPECTION)
class PIIntrospectionThreads;
#define PIINTROSPECTION_THREADS (PIIntrospectionThreadsInterface::instance())
# define PIINTROSPECTION_THREAD_NEW(t) PIINTROSPECTION_THREADS->threadNew (t);
# define PIINTROSPECTION_THREAD_DELETE(t) PIINTROSPECTION_THREADS->threadDelete (t);
# define PIINTROSPECTION_THREAD_START(t) PIINTROSPECTION_THREADS->threadStart (t);
# define PIINTROSPECTION_THREAD_RUN(t) PIINTROSPECTION_THREADS->threadRun (t);
# define PIINTROSPECTION_THREAD_WAIT(t) PIINTROSPECTION_THREADS->threadWait (t);
# define PIINTROSPECTION_THREAD_STOP(t) PIINTROSPECTION_THREADS->threadStop (t);
# define PIINTROSPECTION_THREAD_RUN_DONE(t,us) PIINTROSPECTION_THREADS->threadRunDone(t,us);
class PIP_EXPORT PIIntrospectionThreadsInterface {
friend class PIIntrospection;
public:
__PIINTROSPECTION_SINGLETON_H__(Threads)
void threadNew (PIThread * t);
void threadDelete (PIThread * t);
void threadStart (PIThread * t);
void threadRun (PIThread * t);
void threadWait (PIThread * t);
void threadStop (PIThread * t);
void threadRunDone(PIThread * t, ullong us);
private:
PIIntrospectionThreadsInterface();
~PIIntrospectionThreadsInterface();
PIIntrospectionThreads * p;
};
#else
# define PIINTROSPECTION_THREAD_NEW(t)
# define PIINTROSPECTION_THREAD_DELETE(t)
# define PIINTROSPECTION_THREAD_START(t)
# define PIINTROSPECTION_THREAD_RUN(t)
# define PIINTROSPECTION_THREAD_WAIT(t)
# define PIINTROSPECTION_THREAD_STOP(t)
# define PIINTROSPECTION_THREAD_RUN_DONE(t,us)
#endif
#endif // PIINTROSPECTION_THREADS_H

View File

@@ -0,0 +1,99 @@
/*
PIP - Platform Independent Primitives
Introspection module - implementation of threads
Ivan Pelipenko peri4ko@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "piintrospection_threads_p.h"
PIIntrospectionThreads::ThreadInfo::ThreadInfo() {
id = delay = 0;
state = sStopped;
priority = 0;
run_us = run_count = 0U;
}
PIIntrospectionThreads::PIIntrospectionThreads() {
}
void PIIntrospectionThreads::threadNew(PIThread * t) {
PIMutexLocker _ml(mutex);
threads.insert(t, ThreadInfo());
}
void PIIntrospectionThreads::threadDelete(PIThread * t) {
PIMutexLocker _ml(mutex);
threads.remove(t);
}
void PIIntrospectionThreads::threadStart(PIThread * t) {
PIMutexLocker _ml(mutex);
ThreadInfo & ti(threads[t]);
ti.id = t->tid();
ti.priority = t->priority();
ti.delay = t->delay_;
ti.state = sStarting;
}
void PIIntrospectionThreads::threadRun(PIThread * t) {
PIMutexLocker _ml(mutex);
ThreadInfo & ti(threads[t]);
ti.state = sRunning;
ti.run_count++;
}
void PIIntrospectionThreads::threadWait(PIThread * t) {
PIMutexLocker _ml(mutex);
threads[t].state = sWaiting;
}
void PIIntrospectionThreads::threadStop(PIThread * t) {
PIMutexLocker _ml(mutex);
threads[t].state = sStopped;
}
void PIIntrospectionThreads::threadRunDone(PIThread * t, ullong us) {
PIMutexLocker _ml(mutex);
ThreadInfo & ti(threads[t]);
ti.run_us = (ti.run_us * 0.8) + (us * 0.2); /// WARNING
}
PIByteArray & operator <<(PIByteArray & b, const PIIntrospectionThreads::ThreadInfo & v) {
b << v.classname << v.name << v.id << int(v.state) << v.priority << v.delay << v.run_us << v.run_count;
return b;
}
PIByteArray & operator >>(PIByteArray & b, PIIntrospectionThreads::ThreadInfo & v) {
int st(0);
b >> v.classname >> v.name >> v.id >> st >> v.priority >> v.delay >> v.run_us >> v.run_count;
v.state = (PIIntrospectionThreads::ThreadState)st;
return b;
}

View File

@@ -0,0 +1,63 @@
/*
PIP - Platform Independent Primitives
Introspection module - implementation of threads
Ivan Pelipenko peri4ko@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PIINTROSPECTION_THREADS_P_H
#define PIINTROSPECTION_THREADS_P_H
#include "pimap.h"
#include "pithread.h"
class PIP_EXPORT PIIntrospectionThreads {
public:
PIIntrospectionThreads();
enum ThreadState {
sStopped = 1,
sStarting,
sRunning,
sWaiting,
};
struct ThreadInfo {
ThreadInfo();
PIString classname, name;
int id, delay;
ThreadState state;
short priority;
ullong run_us, run_count;
};
void threadNew (PIThread * t);
void threadDelete (PIThread * t);
void threadStart (PIThread * t);
void threadRun (PIThread * t);
void threadWait (PIThread * t);
void threadStop (PIThread * t);
void threadRunDone(PIThread * t, ullong us);
PIMap<PIThread*, ThreadInfo> threads;
PIMutex mutex;
};
PIByteArray & operator <<(PIByteArray & b, const PIIntrospectionThreads::ThreadInfo & v);
PIByteArray & operator >>(PIByteArray & b, PIIntrospectionThreads::ThreadInfo & v);
#endif // PIINTROSPECTION_THREADS_P_H