diff --git a/CMakeLists.txt b/CMakeLists.txt index a0b51dbb..d0cdf49b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,7 +35,8 @@ option(ICU "Unicode support" 1) option(USB "USB support" 0) option(STL "Building with STL containers" 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(DEBUG "Build with -g3" 0) set(CMAKE_BUILD_TYPE "Release") @@ -141,13 +142,21 @@ else () endif () -# Check if PIP should be built with introspection -if (INTROSPECTION) - message(STATUS "Building with introspection") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DPIP_INTROSPECTION") - list(APPEND LIBS sodium) +# Check if PIP should be built with containers introspection +if (INTROSPECTION_CONTAINERS) + message(STATUS "Building with containers introspection") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DPIP_INTROSPECTION_CONTAINERS") 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 () diff --git a/main.cpp b/main.cpp index 0869f0d6..2f6df3d3 100644 --- a/main.cpp +++ b/main.cpp @@ -9,8 +9,13 @@ int main (int argc, char * argv[]) { //PIByteArray ba; + PIKbdListener kbd; + kbd.enableExitCapture(); PIString str; - piCout << PIINTROSPECTION_CONTAINERS->count; + str.reserve(1024*1024); + PIINTROSPECTION_START + //piCout << PIINTROSPECTION_CONTAINERS->count; + WAIT_FOR_EXIT /*PIVector vl; 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) diff --git a/src/containers/pideque.h b/src/containers/pideque.h index 6008415f..688f6036 100755 --- a/src/containers/pideque.h +++ b/src/containers/pideque.h @@ -295,7 +295,7 @@ public: PIDeque & 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 & 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 & push_back(const T & v) {alloc(pid_size + 1, true); elementNew(pid_data + pid_start + pid_size - 1, v); return *this;} + PIDeque & 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 & append(const T & v) {return push_back(v);} PIDeque & operator <<(const T & v) {return push_back(v);} PIDeque & operator <<(const PIDeque & t) { @@ -462,8 +462,8 @@ private: }; #define __PIDEQUE_SIMPLE_TYPE__(T) \ - template<> inline void PIDeque::newT(T * dst, const T * src, size_t s) {memcpy(dst, src, s * sizeof(T));} \ - template<> inline void PIDeque::deleteT(T * d, size_t sz) {;} \ + template<> inline void PIDeque::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::deleteT(T * d, size_t sz) {PIINTROSPECTION_CONTAINER_UNUSED(sz*sizeof(T));} \ template<> inline void PIDeque::elementNew(T * to, const T & from) {(*to) = from;} \ template<> inline void PIDeque::elementDelete(T & from) {;} diff --git a/src/containers/pimap.h b/src/containers/pimap.h index a373b5a2..6b8421e3 100644 --- a/src/containers/pimap.h +++ b/src/containers/pimap.h @@ -28,6 +28,7 @@ #include "pivector.h" #include "pideque.h" +class PIByteArray; #if !defined(PIP_CONTAINERS_STL) || defined(DOXYGEN) @@ -53,6 +54,8 @@ void piQuickSort(T * a, ssize_t N) { template class PIMap { + template friend PIByteArray & operator >>(PIByteArray & s, PIMap & v); + template friend PIByteArray & operator <<(PIByteArray & s, const PIMap & v); public: PIMap() {;} PIMap(const PIMap & 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;} }; - + template friend PIByteArray & operator >>(PIByteArray & s, typename PIMap::MapIndex & v); + template friend PIByteArray & operator <<(PIByteArray & s, const typename PIMap::MapIndex & v); + ssize_t binarySearch(ssize_t first, ssize_t last, const Key & key, bool & found) const { ssize_t mid; while (first <= last) { diff --git a/src/system/.piscreen.cpp.kate-swp b/src/system/.piscreen.cpp.kate-swp deleted file mode 100644 index 3b43720c..00000000 Binary files a/src/system/.piscreen.cpp.kate-swp and /dev/null differ diff --git a/src/system/piintrospection.cpp b/src/system/piintrospection.cpp index fa7dd49c..324aff9d 100644 --- a/src/system/piintrospection.cpp +++ b/src/system/piintrospection.cpp @@ -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); +} diff --git a/src/system/piintrospection.h b/src/system/piintrospection.h index 31f32a12..b1cb38f1 100644 --- a/src/system/piintrospection.h +++ b/src/system/piintrospection.h @@ -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 diff --git a/src/system/piintrospection_proxy.cpp b/src/system/piintrospection_proxy.cpp index 163a90a3..9296e0d9 100644 --- a/src/system/piintrospection_proxy.cpp +++ b/src/system/piintrospection_proxy.cpp @@ -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;} diff --git a/src/system/piintrospection_proxy.h b/src/system/piintrospection_proxy.h index fca81f4c..d7b839d4 100644 --- a/src/system/piintrospection_proxy.h +++ b/src/system/piintrospection_proxy.h @@ -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 diff --git a/utils/system_daemon/main.cpp b/utils/system_daemon/main.cpp index 9f404a7a..0417423a 100755 --- a/utils/system_daemon/main.cpp +++ b/utils/system_daemon/main.cpp @@ -213,6 +213,7 @@ public: int main(int argc, char * argv[]) { //piDebug = false; PICLI cli(argc, argv); + PIINTROSPECTION_START //cli.addArgument(""); sys_mon.startOnSelf(); screen.enableExitCapture(PIKbdListener::F10); diff --git a/utils/udp_file_transfer/main.cpp b/utils/udp_file_transfer/main.cpp index fbbe8b3a..7cef756a 100644 --- a/utils/udp_file_transfer/main.cpp +++ b/utils/udp_file_transfer/main.cpp @@ -100,6 +100,7 @@ void usage() { int main (int argc, char * argv[]) { PICLI cli(argc, argv); + PIINTROSPECTION_START cli.setOptionalArgumentsCount(-1); cli.addArgument("send", true); cli.addArgument("receive", true);