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

@@ -0,0 +1,34 @@
/*
PIP - Platform Independent Primitives
Introspection module - base macros and types
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_BASE_H
#define PIINTROSPECTION_BASE_H
#include "pibase.h"
class PIString;
class PIMutex;
class PIThread;
class PITimer;
class PIPeer;
#define __PIINTROSPECTION_SINGLETON__(T) \
static PIIntrospection##T##Interface * instance() {static PIIntrospection##T##Interface ret; return &ret;} \
#endif // PIINTROSPECTION_BASE_H

View File

@@ -0,0 +1,61 @@
/*
PIP - Platform Independent Primitives
Introspection module - interface for containers
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_containers.h"
#include "piintrospection_containers_p.h"
PIIntrospectionContainersInterface::PIIntrospectionContainersInterface() {
p = new PIIntrospectionContainers();
}
PIIntrospectionContainersInterface::~PIIntrospectionContainersInterface() {
delete p;
}
void PIIntrospectionContainersInterface::containerNew(const char * tn) {
p->containerNew(tn);
}
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);
}

View File

@@ -0,0 +1,77 @@
/*
PIP - Platform Independent Primitives
Introspection module - interface for containers
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_CONTAINERS_H
#define PIINTROSPECTION_CONTAINERS_H
#include "piintrospection_base.h"
class PIIntrospectionContainers;
#define PIINTROSPECTION_CONTAINERS (PIIntrospectionContainersInterface::instance())
//#if defined(__PIIS__)
//# undef __PIIS__
//#endif
//# if defined(PIP_INTROSPECTION) && !defined(PIP_FORCE_NO_PIINTROSPECTION)
//#endif
#ifdef CC_GCC
# include <typeinfo>
# define _PIIS_TYPENAME_(t) typeid(t).name()
#else
# define _PIIS_TYPENAME_(t) ""
#endif
#if defined(PIP_INTROSPECTION) && !defined(PIP_FORCE_NO_PIINTROSPECTION)
# define PIINTROSPECTION_CONTAINER_NEW(t) PIINTROSPECTION_CONTAINERS->containerNew (_PIIS_TYPENAME_(t));
# 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);
#else
# define PIINTROSPECTION_CONTAINER_NEW(t)
# 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
class PIP_EXPORT PIIntrospectionContainersInterface {
public:
__PIINTROSPECTION_SINGLETON__(Containers)
void containerNew (const char * tn);
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);
private:
PIIntrospectionContainersInterface();
~PIIntrospectionContainersInterface();
PIIntrospectionContainers * p;
};
#endif // PIINTROSPECTION_CONTAINERS_H

View File

@@ -0,0 +1,92 @@
/*
PIP - Platform Independent Primitives
Introspection module - implementation of containers
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_containers_p.h"
PIIntrospectionContainers::Type::Type() {
count = items = 0u;
bytes_allocated = bytes_used = 0U;
}
PIIntrospectionContainers::PIIntrospectionContainers() {
}
void PIIntrospectionContainers::containerNew(const char * tn) {
PIMutexLocker _ml(mutex);
uint id = typeID(tn);
typenames[id] = PIStringAscii(tn);
data[id].count++;
}
void PIIntrospectionContainers::containerDelete(const char * tn) {
PIMutexLocker _ml(mutex);
data[typeID(tn)].count--;
}
void PIIntrospectionContainers::containerAlloc(const char * tn, ullong cnt) {
PIMutexLocker _ml(mutex);
data[typeID(tn)].bytes_allocated += cnt;
}
void PIIntrospectionContainers::containerFree(const char * tn, ullong cnt) {
PIMutexLocker _ml(mutex);
data[typeID(tn)].bytes_allocated -= cnt;
}
void PIIntrospectionContainers::containerUsed(const char * tn, ullong cnt) {
PIMutexLocker _ml(mutex);
data[typeID(tn)].bytes_used += cnt;
}
void PIIntrospectionContainers::containerUnused(const char * tn, ullong cnt) {
PIMutexLocker _ml(mutex);
data[typeID(tn)].bytes_used -= cnt;
}
uint PIIntrospectionContainers::typeID(const char * tn) {
if (!tn) return 0u;
size_t l = strlen(tn);
if (l == 0) return 0u;
return crc.calculate(tn, l);
}
PIByteArray & operator <<(PIByteArray & s, const PIIntrospectionContainers::Type & v) {
s << v.count << v.items << v.bytes_allocated << v.bytes_used;
return s;
}
PIByteArray & operator >>(PIByteArray & s, PIIntrospectionContainers::Type & v) {
s >> v.count >> v.items >> v.bytes_allocated >> v.bytes_used;
return s;
}

View File

@@ -0,0 +1,62 @@
/*
PIP - Platform Independent Primitives
Introspection module - implementation of containers
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_CONTAINERS_P_H
#define PIINTROSPECTION_CONTAINERS_P_H
#define PIP_FORCE_NO_PIINTROSPECTION
#include "pimutex.h"
#include "pimap.h"
#include "picrc.h"
class PIP_EXPORT PIIntrospectionContainers {
public:
PIIntrospectionContainers();
void containerNew (const char * tn);
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);
struct Type {
Type();
uint count;
uint items;
ullong bytes_allocated;
ullong bytes_used;
};
PIMap<uint, Type> data;
PIMap<uint, PIString> typenames;
PIMutex mutex;
CRC_32 crc;
};
PIByteArray & operator <<(PIByteArray & s, const PIIntrospectionContainers::Type & v);
PIByteArray & operator >>(PIByteArray & s, PIIntrospectionContainers::Type & v);
#undef PIP_FORCE_NO_PIINTROSPECTION
#endif // PIINTROSPECTION_CONTAINERS_P_H

View File

@@ -0,0 +1,42 @@
/*
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_server.h"
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

@@ -0,0 +1,41 @@
/*
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_SERVER_H
#define PIINTROSPECTION_SERVER_H
#include "pipeer.h"
#include "pimutex.h"
class __PIIntrospectionServer__;
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;
};
#endif // PIINTROSPECTION_SERVER_H

View File

@@ -0,0 +1,66 @@
/*
PIP - Platform Independent Primitives
Introspection module - interface for threads
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_threads.h"
#include "piintrospection_threads_p.h"
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);
}

View File

@@ -0,0 +1,67 @@
/*
PIP - Platform Independent Primitives
Introspection module - interface for threads
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_THREADS_H
#define PIINTROSPECTION_THREADS_H
#include "piintrospection_base.h"
class PIIntrospectionThreads;
#define PIINTROSPECTION_THREADS (PIIntrospectionThreadsInterface::instance())
#if defined(PIP_INTROSPECTION) && !defined(PIP_FORCE_NO_PIINTROSPECTION)
# 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);
#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
class PIP_EXPORT PIIntrospectionThreadsInterface {
public:
__PIINTROSPECTION_SINGLETON__(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;
};
#endif // PIINTROSPECTION_THREADS_H

View File

@@ -0,0 +1,92 @@
/*
PIP - Platform Independent Primitives
Introspection module - implementation of threads
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_threads_p.h"
PIIntrospectionThreads::ThreadInfo::ThreadInfo() {
id = 0;
state = sStopped;
priority = 0;
}
PIIntrospectionThreads::PIIntrospectionThreads() {
}
void PIIntrospectionThreads::threadNew(PIThread * t) {
mutex.lock();
ThreadInfo & ti(threads[t]);
ti.id = t->tid();
ti.priority = t->priority();
ti.name = t->name();
//piCout << "register thread" << id << name;
mutex.unlock();
}
void PIIntrospectionThreads::threadDelete(PIThread * t) {
mutex.lock();
threads.remove(t);
mutex.unlock();
}
void PIIntrospectionThreads::threadStart(PIThread * t) {
}
void PIIntrospectionThreads::threadRun(PIThread * t) {
}
void PIIntrospectionThreads::threadWait(PIThread * t) {
}
void PIIntrospectionThreads::threadStop(PIThread * t) {
}
void PIIntrospectionThreads::threadRunDone(PIThread * t, ullong us) {
}
PIByteArray & operator <<(PIByteArray & b, const PIIntrospectionThreads::ThreadInfo & v) {
b << v.name << v.id << int(v.state) << v.priority;
return b;
}
PIByteArray & operator >>(PIByteArray & b, PIIntrospectionThreads::ThreadInfo & v) {
int st(0);
b >> v.id >> v.priority >> st >> v.name;
v.state = (PIIntrospectionThreads::ThreadState)st;
return b;
}

View File

@@ -0,0 +1,61 @@
/*
PIP - Platform Independent Primitives
Introspection module - implementation of threads
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_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 name;
int id;
ThreadState state;
short priority;
};
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