Merge pull request 'introspection' (#75) from introspection into master

Reviewed-on: https://git.shs.tools/SHS/pip/pulls/75
This commit was merged in pull request #75.
This commit is contained in:
2021-06-11 21:02:56 +03:00
8 changed files with 1622 additions and 1578 deletions

View File

@@ -297,7 +297,10 @@ inline PIByteArray & operator >>(PIByteArray & s, uchar & v) {assert(s.size() >=
//! \relatesalso PIByteArray \brief Restore operator for any trivial copyable type
template<typename T, typename std::enable_if< std::is_trivially_copyable<T>::value, int>::type = 0>
inline PIByteArray::StreamRef operator >>(PIByteArray & s, T & v) {
if (s.size() < sizeof(v)) {
printf("error with %s\n", typeid(T).name());
assert(s.size() >= sizeof(v));
}
memcpy((void*)(&v), s.data(), sizeof(v));
s.remove(0, sizeof(v));
return s;
@@ -308,7 +311,10 @@ PIP_EXPORT PIByteArray & operator >>(PIByteArray & s, PIByteArray & v);
//! \relatesalso PIByteArray \brief Restore operator, see \ref PIByteArray_sec1 for details
inline PIByteArray & operator >>(PIByteArray & s, PIByteArray::RawData v) {
if (s.size_s() < v.s) {
printf("error with RawData %d < %d\n", (int)s.size_s(), v.s);
assert(s.size_s() >= v.s);
}
if (v.s > 0) {
memcpy((void*)(v.d), s.data(), v.s);
s.remove(0, v.s);
@@ -321,7 +327,10 @@ template<typename T,
typename std::enable_if< std::is_trivially_copyable<T>::value, int>::type = 0,
typename std::enable_if< std::is_same<decltype(std::declval<PIByteArray&>() << std::declval<const T &>()), PIByteArray::StreamRef>::value, int>::type = 0>
inline PIByteArray & operator >>(PIByteArray & s, PIVector<T> & v) {
if (s.size_s() < 4) {
printf("error with PIVector<%s>\n", typeid(T).name());
assert(s.size_s() >= 4);
}
int sz; s >> sz;
v._resizeRaw(sz);
if (sz > 0) {
@@ -334,7 +343,10 @@ template<typename T,
typename std::enable_if< std::is_trivially_copyable<T>::value, int>::type = 0,
typename std::enable_if<!std::is_same<decltype(std::declval<PIByteArray&>() << std::declval<const T &>()), PIByteArray::StreamRef>::value, int>::type = 0>
inline PIByteArray & operator >>(PIByteArray & s, PIVector<T> & v) {
if (s.size_s() < 4) {
printf("error with PIVector<%s>\n", typeid(T).name());
assert(s.size_s() >= 4);
}
int sz; s >> sz;
v.resize(sz);
for (int i = 0; i < sz; ++i) s >> v[i];
@@ -346,7 +358,10 @@ template<typename T,
typename std::enable_if< std::is_trivially_copyable<T>::value, int>::type = 0,
typename std::enable_if< std::is_same<decltype(std::declval<PIByteArray&>() << std::declval<const T &>()), PIByteArray::StreamRef>::value, int>::type = 0>
inline PIByteArray & operator >>(PIByteArray & s, PIDeque<T> & v) {
if (s.size_s() < 4) {
printf("error with PIDeque<%s>\n", typeid(T).name());
assert(s.size_s() >= 4);
}
int sz; s >> sz;
v._resizeRaw(sz);
if (sz > 0) {
@@ -359,7 +374,10 @@ template<typename T,
typename std::enable_if< std::is_trivially_copyable<T>::value, int>::type = 0,
typename std::enable_if<!std::is_same<decltype(std::declval<PIByteArray&>() << std::declval<const T &>()), PIByteArray::StreamRef>::value, int>::type = 0>
inline PIByteArray & operator >>(PIByteArray & s, PIDeque<T> & v) {
if (s.size_s() < 4) {
printf("error with PIDeque<%s>\n", typeid(T).name());
assert(s.size_s() >= 4);
}
int sz; s >> sz;
v.resize(sz);
for (int i = 0; i < sz; ++i) s >> v[i];
@@ -371,7 +389,10 @@ template<typename T,
typename std::enable_if< std::is_trivially_copyable<T>::value, int>::type = 0,
typename std::enable_if< std::is_same<decltype(std::declval<PIByteArray&>() << std::declval<const T &>()), PIByteArray::StreamRef>::value, int>::type = 0>
inline PIByteArray & operator >>(PIByteArray & s, PIVector2D<T> & v) {
if (s.size_s() < 8) {
printf("error with PIVecto2Dr<%s>\n", typeid(T).name());
assert(s.size_s() >= 8);
}
int r, c; s >> r >> c;
v._resizeRaw(r, c);
int sz = r*c;
@@ -385,7 +406,10 @@ template<typename T,
typename std::enable_if< std::is_trivially_copyable<T>::value, int>::type = 0,
typename std::enable_if<!std::is_same<decltype(std::declval<PIByteArray&>() << std::declval<const T &>()), PIByteArray::StreamRef>::value, int>::type = 0>
inline PIByteArray & operator >>(PIByteArray & s, PIVector2D<T> & v) {
if (s.size_s() < 8) {
printf("error with PIVecto2Dr<%s>\n", typeid(T).name());
assert(s.size_s() >= 8);
}
int r,c;
PIVector<T> tmp;
s >> r >> c >> tmp;
@@ -438,7 +462,10 @@ inline PIByteArray & operator <<(PIByteArray & s, const PIVector2D<T> & v) {
//! \relatesalso PIByteArray \brief Restore operator for PIVector of any compound type
template<typename T, typename std::enable_if<!std::is_trivially_copyable<T>::value, int>::type = 0>
inline PIByteArray & operator >>(PIByteArray & s, PIVector<T> & v) {
if (s.size_s() < 4) {
printf("error with PIVector<%s>\n", typeid(T).name());
assert(s.size_s() >= 4);
}
int sz; s >> sz;
v.resize(sz);
for (int i = 0; i < sz; ++i) s >> v[i];
@@ -448,7 +475,10 @@ inline PIByteArray & operator >>(PIByteArray & s, PIVector<T> & v) {
//! \relatesalso PIByteArray \brief Restore operator for PIDeque of any compound type
template<typename T, typename std::enable_if<!std::is_trivially_copyable<T>::value, int>::type = 0>
inline PIByteArray & operator >>(PIByteArray & s, PIDeque<T> & v) {
if (s.size_s() < 4) {
printf("error with PIDeque<%s>\n", typeid(T).name());
assert(s.size_s() >= 4);
}
int sz; s >> sz;
v.resize(sz);
for (int i = 0; i < sz; ++i) s >> v[i];
@@ -458,7 +488,10 @@ inline PIByteArray & operator >>(PIByteArray & s, PIDeque<T> & v) {
//! \relatesalso PIByteArray \brief Restore operator for PIVector2D of any compound type
template<typename T, typename std::enable_if<!std::is_trivially_copyable<T>::value, int>::type = 0>
inline PIByteArray & operator >>(PIByteArray & s, PIVector2D<T> & v) {
if (s.size_s() < 8) {
printf("error with PIVecto2Dr<%s>\n", typeid(T).name());
assert(s.size_s() >= 8);
}
int r,c;
PIVector<T> tmp;
s >> r >> c >> tmp;
@@ -484,7 +517,10 @@ inline PIByteArray & operator <<(PIByteArray & s, const PIMap<Key, T> & v) {
template <typename Key, typename T>
inline PIByteArray & operator >>(PIByteArray & s, PIMap<Key, T> & v) {
if (s.size_s() < 4) {
printf("error with PIMap<%s, %s>\n", typeid(Key).name(), typeid(T).name());
assert(s.size_s() >= 4);
}
int sz; s >> sz; v.pim_index.resize(sz);
int ind = 0;
for (int i = 0; i < sz; ++i) {

View File

@@ -45,7 +45,13 @@ PIIntrospectionServer::~PIIntrospectionServer() {
}
void PIIntrospectionServer::start() {
PIIntrospectionServer * PIIntrospectionServer::instance() {
static PIIntrospectionServer ret;
return &ret;
}
void PIIntrospectionServer::start(const PIString & server_name) {
if (!sysmon) {
sysmon = PISystemMonitor::Pool::instance()->getByPID(PIProcess::currentPID());
if (sysmon) {
@@ -58,6 +64,7 @@ void PIIntrospectionServer::start() {
sysmon->startOnSelf();
}
}
changeName(server_name + genName());
PIPeer::start();
}

View File

@@ -29,14 +29,14 @@ class PIIntrospectionServer;
class PISystemMonitor;
# define PIINTROSPECTION_SERVER (PIIntrospectionServer::instance())
# define PIINTROSPECTION_START PIINTROSPECTION_SERVER->start();
# define PIINTROSPECTION_START(name) PIINTROSPECTION_SERVER->start(#name);
class PIP_EXPORT PIIntrospectionServer: public PIPeer {
PIOBJECT_SUBCLASS(PIIntrospectionServer, PIPeer)
public:
static PIIntrospectionServer * instance() {static PIIntrospectionServer ret; return &ret;}
static PIIntrospectionServer * instance();
void start();
void start(const PIString & server_name);
private:
PIIntrospectionServer();
@@ -47,7 +47,7 @@ private:
virtual void dataReceived(const PIString & from, const PIByteArray & data);
EVENT_HANDLER(void, sysmonDeleted);
PRIVATE_DECLARATION
PRIVATE_DECLARATION(PIP_EXPORT)
PITimer itimer;
PISystemMonitor * sysmon;
PIMutex sysmon_mutex;
@@ -55,7 +55,7 @@ private:
};
#else
# define PIINTROSPECTION_START
# define PIINTROSPECTION_START(name)
#endif
#endif // PIINTROSPECTION_SERVER_H

View File

@@ -153,6 +153,7 @@ bool PIBinaryLog::openDevice() {
bool PIBinaryLog::closeDevice() {
stopThreadedRead();
pausemutex.unlock();
logmutex.unlock();
moveIndex(-1);
is_indexed = false;
index.clear();

View File

@@ -341,9 +341,9 @@ void PISystemMonitor::run() {
//piCout << ts_new.cpu_load_user;
}
last_tm = cur_tm;
lock();
mutex_.lock();
cur_ts = cur_tm.values();
unlock();
mutex_.unlock();
tstat.ram_total = totalRAM();
tstat.ram_used = usedRAM();
tstat.ram_free = freeRAM();
@@ -489,13 +489,13 @@ PIByteArray & operator >>(PIByteArray & s, PISystemMonitor::ProcessStats & v) {
PIByteArray & operator <<(PIByteArray & s, const PISystemMonitor::ThreadStats & v) {
s << PIByteArray::RawData(&v, sizeof(PISystemMonitor::ThreadStatsFixed))
<< v.name << v.created;
<< v.name;
return s;
}
PIByteArray & operator >>(PIByteArray & s, PISystemMonitor::ThreadStats & v) {
s >> PIByteArray::RawData(&v, sizeof(PISystemMonitor::ThreadStatsFixed))
>> v.name >> v.created;
>> v.name;
return s;
}

View File

@@ -60,6 +60,7 @@ public:
PISystemTime user_time;
float cpu_load_kernel;
float cpu_load_user;
PIDateTime created;
};
#pragma pack(pop)
@@ -76,7 +77,6 @@ public:
struct PIP_EXPORT ThreadStats: ThreadStatsFixed {
PIString name;
PIDateTime created;
};
#ifndef FREERTOS

View File

@@ -332,7 +332,7 @@ void usage() {
int main(int argc, char * argv[]) {
sys_mon.startOnSelf();
PIINTROSPECTION_START
PIINTROSPECTION_START(pisd)
//piDebug = false;
PICLI cli(argc, argv);
cli.addArgument("help");