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

View File

@@ -35,7 +35,8 @@ option(ICU "Unicode support" 1)
option(USB "USB support" 0) option(USB "USB support" 0)
option(STL "Building with STL containers" 0) option(STL "Building with STL containers" 0)
option(CRYPT "Crypt support" 0) option(CRYPT "Crypt support" 0)
option(INTROSPECTION "Build with introspection" 1) option(INTROSPECTION_CONTAINERS "Build with containers introspection" 0)
option(INTROSPECTION_THREADS "Build with threads introspection" 0)
option(LIB "System install" 1) option(LIB "System install" 1)
option(DEBUG "Build with -g3" 0) option(DEBUG "Build with -g3" 0)
set(CMAKE_BUILD_TYPE "Release") set(CMAKE_BUILD_TYPE "Release")
@@ -141,13 +142,21 @@ else ()
endif () endif ()
# Check if PIP should be built with introspection # Check if PIP should be built with containers introspection
if (INTROSPECTION) if (INTROSPECTION_CONTAINERS)
message(STATUS "Building with introspection") message(STATUS "Building with containers introspection")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DPIP_INTROSPECTION") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DPIP_INTROSPECTION_CONTAINERS")
list(APPEND LIBS sodium)
else () else ()
message(STATUS "Building without introspection") message(STATUS "Building without containers introspection")
endif ()
# Check if PIP should be built with threads introspection
if (INTROSPECTION_THREADS)
message(STATUS "Building with threads introspection")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DPIP_INTROSPECTION_THREADS")
else ()
message(STATUS "Building without threads introspection")
endif () endif ()

View File

@@ -9,8 +9,13 @@
int main (int argc, char * argv[]) { int main (int argc, char * argv[]) {
//PIByteArray ba; //PIByteArray ba;
PIKbdListener kbd;
kbd.enableExitCapture();
PIString str; PIString str;
piCout << PIINTROSPECTION_CONTAINERS->count; str.reserve(1024*1024);
PIINTROSPECTION_START
//piCout << PIINTROSPECTION_CONTAINERS->count;
WAIT_FOR_EXIT
/*PIVector<PIVariant> vl; /*PIVector<PIVariant> vl;
vl << PIVariant('2') << PIVariant(-5.5) << PIVariant(10) << PIVariant(complexd(2,3)) << PIVariant("text") << PIVariant(PIByteArray("bytearray", 9)) << PIVariant(PIDateTime::current()); vl << PIVariant('2') << PIVariant(-5.5) << PIVariant(10) << PIVariant(complexd(2,3)) << PIVariant("text") << PIVariant(PIByteArray("bytearray", 9)) << PIVariant(PIDateTime::current());
piForeachC (PIVariant v, vl) piForeachC (PIVariant v, vl)

View File

@@ -295,7 +295,7 @@ public:
PIDeque<T> & removeOne(const T & v) {for (size_t i = 0; i < pid_size; ++i) if (pid_data[i + pid_start] == v) {remove(i); return *this;} return *this;} PIDeque<T> & removeOne(const T & v) {for (size_t i = 0; i < pid_size; ++i) if (pid_data[i + pid_start] == v) {remove(i); return *this;} return *this;}
PIDeque<T> & removeAll(const T & v) {for (llong i = 0; i < pid_size; ++i) if (pid_data[i + pid_start] == v) {remove(i); --i;} return *this;} PIDeque<T> & removeAll(const T & v) {for (llong i = 0; i < pid_size; ++i) if (pid_data[i + pid_start] == v) {remove(i); --i;} return *this;}
PIDeque<T> & push_back(const T & v) {alloc(pid_size + 1, true); elementNew(pid_data + pid_start + pid_size - 1, v); return *this;} PIDeque<T> & push_back(const T & v) {alloc(pid_size + 1, true); PIINTROSPECTION_CONTAINER_USED(sizeof(T)); elementNew(pid_data + pid_start + pid_size - 1, v); return *this;}
PIDeque<T> & append(const T & v) {return push_back(v);} PIDeque<T> & append(const T & v) {return push_back(v);}
PIDeque<T> & operator <<(const T & v) {return push_back(v);} PIDeque<T> & operator <<(const T & v) {return push_back(v);}
PIDeque<T> & operator <<(const PIDeque<T> & t) { PIDeque<T> & operator <<(const PIDeque<T> & t) {
@@ -462,8 +462,8 @@ private:
}; };
#define __PIDEQUE_SIMPLE_TYPE__(T) \ #define __PIDEQUE_SIMPLE_TYPE__(T) \
template<> inline void PIDeque<T>::newT(T * dst, const T * src, size_t s) {memcpy(dst, src, s * sizeof(T));} \ template<> inline void PIDeque<T>::newT(T * dst, const T * src, size_t s) {PIINTROSPECTION_CONTAINER_USED(s*sizeof(T)); memcpy(dst, src, s * sizeof(T));} \
template<> inline void PIDeque<T>::deleteT(T * d, size_t sz) {;} \ template<> inline void PIDeque<T>::deleteT(T * d, size_t sz) {PIINTROSPECTION_CONTAINER_UNUSED(sz*sizeof(T));} \
template<> inline void PIDeque<T>::elementNew(T * to, const T & from) {(*to) = from;} \ template<> inline void PIDeque<T>::elementNew(T * to, const T & from) {(*to) = from;} \
template<> inline void PIDeque<T>::elementDelete(T & from) {;} template<> inline void PIDeque<T>::elementDelete(T & from) {;}

View File

@@ -28,6 +28,7 @@
#include "pivector.h" #include "pivector.h"
#include "pideque.h" #include "pideque.h"
class PIByteArray;
#if !defined(PIP_CONTAINERS_STL) || defined(DOXYGEN) #if !defined(PIP_CONTAINERS_STL) || defined(DOXYGEN)
@@ -53,6 +54,8 @@ void piQuickSort(T * a, ssize_t N) {
template <typename Key, typename T> template <typename Key, typename T>
class PIMap { class PIMap {
template <typename Key1, typename T1> friend PIByteArray & operator >>(PIByteArray & s, PIMap<Key1, T1> & v);
template <typename Key1, typename T1> friend PIByteArray & operator <<(PIByteArray & s, const PIMap<Key1, T1> & v);
public: public:
PIMap() {;} PIMap() {;}
PIMap(const PIMap<Key, T> & other) {*this = other;} PIMap(const PIMap<Key, T> & other) {*this = other;}
@@ -244,7 +247,9 @@ protected:
bool operator <(const MapIndex & s) const {return key < s.key;} bool operator <(const MapIndex & s) const {return key < s.key;}
bool operator >(const MapIndex & s) const {return key > s.key;} bool operator >(const MapIndex & s) const {return key > s.key;}
}; };
template <typename Key1, typename T1> friend PIByteArray & operator >>(PIByteArray & s, typename PIMap<Key1, T1>::MapIndex & v);
template <typename Key1, typename T1> friend PIByteArray & operator <<(PIByteArray & s, const typename PIMap<Key1, T1>::MapIndex & v);
ssize_t binarySearch(ssize_t first, ssize_t last, const Key & key, bool & found) const { ssize_t binarySearch(ssize_t first, ssize_t last, const Key & key, bool & found) const {
ssize_t mid; ssize_t mid;
while (first <= last) { while (first <= last) {

Binary file not shown.

View File

@@ -18,6 +18,7 @@
*/ */
#include "piintrospection.h" #include "piintrospection.h"
#include "pisysteminfo.h"
PIIntrospectionContainers::PIIntrospectionContainers() { PIIntrospectionContainers::PIIntrospectionContainers() {
@@ -32,6 +33,7 @@ PIIntrospectionThreads::PIIntrospectionThreads() {
PIIntrospectionContainers * __PIIntrospectionContainers__::p = 0; PIIntrospectionContainers * __PIIntrospectionContainers__::p = 0;
PIIntrospectionThreads * __PIIntrospectionThreads__::p = 0; PIIntrospectionThreads * __PIIntrospectionThreads__::p = 0;
PIIntrospectionServer * __PIIntrospectionServer__::p = 0;
void PIIntrospectionThreads::registerThread(int id, short prior, const PIString & name) { void PIIntrospectionThreads::registerThread(int id, short prior, const PIString & name) {
@@ -92,3 +94,25 @@ void PIIntrospectionContainers::containerUnused(ullong cnt) {
bytes_used -= cnt; bytes_used -= cnt;
mutex.unlock(); 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 #ifndef PIINTROSPECTION_H
#define PIINTROSPECTION_H #define PIINTROSPECTION_H
#include "pistring.h" #include "pipeer.h"
#include "pimutex.h" #include "pimutex.h"
class PIP_EXPORT PIIntrospectionThreads class PIP_EXPORT PIIntrospectionThreads
{ {
friend class __PIIntrospectionThreads__; friend class __PIIntrospectionThreads__;
PIIntrospectionThreads();
public: public:
PIIntrospectionThreads();
struct ThreadInfo { struct ThreadInfo {
ThreadInfo() {id = 0; priority = 0;} ThreadInfo() {id = 0; priority = 0;}
PIString name; PIString name;
@@ -47,8 +48,9 @@ public:
class PIP_EXPORT PIIntrospectionContainers class PIP_EXPORT PIIntrospectionContainers
{ {
friend class __PIIntrospectionContainers__; friend class __PIIntrospectionContainers__;
PIIntrospectionContainers();
public: public:
PIIntrospectionContainers();
void containerNew(); void containerNew();
void containerDelete(); void containerDelete();
void containerAlloc(ullong cnt); 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__ { class __PIIntrospectionContainers__ {
public: public:
__PIIntrospectionContainers__() {if (!p) p = new PIIntrospectionContainers();} __PIIntrospectionContainers__() {if (!p) p = new PIIntrospectionContainers();}
@@ -70,7 +86,6 @@ public:
static PIIntrospectionContainers * p; static PIIntrospectionContainers * p;
}; };
class __PIIntrospectionThreads__ { class __PIIntrospectionThreads__ {
public: public:
__PIIntrospectionThreads__() {if (!p) p = new PIIntrospectionThreads();} __PIIntrospectionThreads__() {if (!p) p = new PIIntrospectionThreads();}
@@ -78,6 +93,15 @@ public:
static PIIntrospectionThreads * 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 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, 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_CONTAINERS __PIIntrospectionContainers__::get()
#define PIINTROSPECTION_THREADS __PIIntrospectionThreads__::get() #define PIINTROSPECTION_THREADS __PIIntrospectionThreads__::get()
#define PIINTROSPECTION_SERVER __PIIntrospectionServer__::get()
#endif // PIINTROSPECTION_H #endif // PIINTROSPECTION_H

View File

@@ -19,6 +19,7 @@
#include "piintrospection_proxy.h" #include "piintrospection_proxy.h"
#include "piintrospection.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__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__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__containerFree(ullong cnt) {PIINTROSPECTION_CONTAINERS->containerFree(cnt);}
void __PIIntrospection__containerUsed(ullong cnt) {PIINTROSPECTION_CONTAINERS->containerUsed(cnt);} void __PIIntrospection__containerUsed(ullong cnt) {PIINTROSPECTION_CONTAINERS->containerUsed(cnt);}
void __PIIntrospection__containerUnused(ullong cnt) {PIINTROSPECTION_CONTAINERS->containerUnused(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__containerFree(ullong cnt);
void __PIIntrospection__containerUsed(ullong cnt); void __PIIntrospection__containerUsed(ullong cnt);
void __PIIntrospection__containerUnused(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_NEW() __PIIntrospection__containerNew();
# define PIINTROSPECTION_CONTAINER_DELETE() __PIIntrospection__containerDelete(); # define PIINTROSPECTION_CONTAINER_DELETE() __PIIntrospection__containerDelete();
# define PIINTROSPECTION_CONTAINER_USED(cnt) __PIIntrospection__containerUsed(cnt); # define PIINTROSPECTION_CONTAINER_USED(cnt) __PIIntrospection__containerUsed(cnt);
# define PIINTROSPECTION_CONTAINER_UNUSED(cnt) __PIIntrospection__containerUnused(cnt); # define PIINTROSPECTION_CONTAINER_UNUSED(cnt) __PIIntrospection__containerUnused(cnt);
# define PIINTROSPECTION_CONTAINER_ALLOC(cnt) __PIIntrospection__containerAlloc(cnt); # define PIINTROSPECTION_CONTAINER_ALLOC(cnt) __PIIntrospection__containerAlloc(cnt);
# define PIINTROSPECTION_CONTAINER_FREE(cnt) __PIIntrospection__containerFree(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 #else
# define PIINTROSPECTION_CONTAINER_NEW() # define PIINTROSPECTION_CONTAINER_NEW()
# define PIINTROSPECTION_CONTAINER_DELETE() # define PIINTROSPECTION_CONTAINER_DELETE()
@@ -49,8 +48,22 @@ void __PIIntrospection__containerUnused(ullong cnt);
# define PIINTROSPECTION_CONTAINER_UNUSED(cnt) # define PIINTROSPECTION_CONTAINER_UNUSED(cnt)
# define PIINTROSPECTION_CONTAINER_ALLOC(cnt) # define PIINTROSPECTION_CONTAINER_ALLOC(cnt)
# define PIINTROSPECTION_CONTAINER_FREE(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_REGISTER_THREAD(id, pr, name)
# define PIINTROSPECTION_UNREGISTER_THREAD(id) # 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
#endif // PIINTROSPECTION_PROXY_H #endif // PIINTROSPECTION_PROXY_H

View File

@@ -213,6 +213,7 @@ public:
int main(int argc, char * argv[]) { int main(int argc, char * argv[]) {
//piDebug = false; //piDebug = false;
PICLI cli(argc, argv); PICLI cli(argc, argv);
PIINTROSPECTION_START
//cli.addArgument(""); //cli.addArgument("");
sys_mon.startOnSelf(); sys_mon.startOnSelf();
screen.enableExitCapture(PIKbdListener::F10); screen.enableExitCapture(PIKbdListener::F10);

View File

@@ -100,6 +100,7 @@ void usage() {
int main (int argc, char * argv[]) { int main (int argc, char * argv[]) {
PICLI cli(argc, argv); PICLI cli(argc, argv);
PIINTROSPECTION_START
cli.setOptionalArgumentsCount(-1); cli.setOptionalArgumentsCount(-1);
cli.addArgument("send", true); cli.addArgument("send", true);
cli.addArgument("receive", true); cli.addArgument("receive", true);