From 6da4f268d22de937701ea37dbb1b66f4460b0008 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B5=D0=BB=D0=B8=D0=BF=D0=B5=D0=BD=D0=BA=D0=BE=20?= =?UTF-8?q?=D0=98=D0=B2=D0=B0=D0=BD?= Date: Sun, 23 Jun 2019 13:39:55 +0000 Subject: [PATCH] git-svn-id: svn://db.shs.com.ru/pip@807 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5 --- .../introspection/piintrospection_server.cpp | 4 +- .../piintrospection_server_p.cpp | 7 +++- .../piintrospection_threads_p.cpp | 38 +++++++++++-------- .../introspection/piintrospection_threads_p.h | 6 ++- src_main/thread/pithread.cpp | 6 +++ src_main/thread/pithread.h | 2 + 6 files changed, 43 insertions(+), 20 deletions(-) diff --git a/src_main/introspection/piintrospection_server.cpp b/src_main/introspection/piintrospection_server.cpp index eb77d4e1..f6b54ce8 100644 --- a/src_main/introspection/piintrospection_server.cpp +++ b/src_main/introspection/piintrospection_server.cpp @@ -60,10 +60,10 @@ void PIIntrospectionServer::dataReceived(const PIString & from, const PIByteArra cs.add(PIIntrospection::itInfo, PIIntrospection::packInfo()); if (ri.types[PIIntrospection::itContainers]) cs.add(PIIntrospection::itContainers, PIIntrospection::packContainers()); - if (ri.types[PIIntrospection::itThreads]) - cs.add(PIIntrospection::itThreads, PIIntrospection::packThreads()); 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()); diff --git a/src_main/introspection/piintrospection_server_p.cpp b/src_main/introspection/piintrospection_server_p.cpp index c73b54cf..ac829941 100644 --- a/src_main/introspection/piintrospection_server_p.cpp +++ b/src_main/introspection/piintrospection_server_p.cpp @@ -209,7 +209,12 @@ PIByteArray PIIntrospection::packThreads() { PIByteArray ret; PIIntrospectionThreads * p = PIINTROSPECTION_THREADS->p; p->mutex.lock(); - ret << p->threads.values(); + PIMap & tm(p->threads); + for (PIMap::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(); return ret; } diff --git a/src_main/introspection/piintrospection_threads_p.cpp b/src_main/introspection/piintrospection_threads_p.cpp index 84010b0e..52083cd0 100644 --- a/src_main/introspection/piintrospection_threads_p.cpp +++ b/src_main/introspection/piintrospection_threads_p.cpp @@ -21,9 +21,10 @@ PIIntrospectionThreads::ThreadInfo::ThreadInfo() { - id = 0; + id = delay = 0; state = sStopped; priority = 0; + run_us = run_count = 0U; } @@ -34,59 +35,66 @@ PIIntrospectionThreads::PIIntrospectionThreads() { void PIIntrospectionThreads::threadNew(PIThread * t) { - mutex.lock(); + PIMutexLocker _ml(mutex); 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(); + PIMutexLocker _ml(mutex); threads.remove(t); - mutex.unlock(); } 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.name << v.id << int(v.state) << v.priority; + 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.id >> v.priority >> st >> v.name; + 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; } diff --git a/src_main/introspection/piintrospection_threads_p.h b/src_main/introspection/piintrospection_threads_p.h index 8566c1e9..b63e199e 100644 --- a/src_main/introspection/piintrospection_threads_p.h +++ b/src_main/introspection/piintrospection_threads_p.h @@ -34,12 +34,14 @@ public: sRunning, sWaiting, }; + struct ThreadInfo { ThreadInfo(); - PIString name; - int id; + PIString classname, name; + int id, delay; ThreadState state; short priority; + ullong run_us, run_count; }; void threadNew (PIThread * t); diff --git a/src_main/thread/pithread.cpp b/src_main/thread/pithread.cpp index 7d0a346b..24b25289 100755 --- a/src_main/thread/pithread.cpp +++ b/src_main/thread/pithread.cpp @@ -453,7 +453,13 @@ void PIThread::_runThread() { if (lockRun) mutex_.lock(); //PICout(PICoutManipulators::DefaultControls) << "thread" << this << "lock" << "ok"; //PICout(PICoutManipulators::DefaultControls) << "thread" << this << "run" << "..."; +#ifdef PIP_INTROSPECTION + PITimeMeasurer _tm; +#endif run(); +#ifdef PIP_INTROSPECTION + PIINTROSPECTION_THREAD_RUN_DONE(this, ullong(_tm.elapsed_u())); +#endif //PICout(PICoutManipulators::DefaultControls) << "thread" << this << "run" << "ok"; //printf("thread %p tick\n", this); //PICout(PICoutManipulators::DefaultControls) << "thread" << this << "ret_func" << "..."; diff --git a/src_main/thread/pithread.h b/src_main/thread/pithread.h index 542c2ad0..7b8a5142 100755 --- a/src_main/thread/pithread.h +++ b/src_main/thread/pithread.h @@ -30,6 +30,7 @@ #include "piobject.h" class PIThread; +class PIIntrospectionThreads; class PIP_EXPORT __PIThreadCollection { public: @@ -61,6 +62,7 @@ typedef void (*ThreadFunc)(void * ); class PIP_EXPORT PIThread: public PIObject { PIOBJECT_SUBCLASS(PIThread, PIObject) + friend class PIIntrospectionThreads; public: //! Contructs thread with custom data "data", external function "func" and main loop delay "loop_delay".