git-svn-id: svn://db.shs.com.ru/pip@513 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5

This commit is contained in:
2017-06-21 14:00:45 +00:00
parent 6ac45691cc
commit ed1a89508a
7 changed files with 253 additions and 18 deletions

View File

@@ -21,7 +21,7 @@
#define PISYSTEMMONITOR_H
#include "pithread.h"
#include "piprocess.h"
#include "pifile.h"
class PIP_EXPORT PISystemMonitor: public PIThread
{
@@ -53,23 +53,58 @@ public:
float cpu_load_system;
float cpu_load_user;
};
struct ThreadStats {
ThreadStats() {cpu_load_kernel = cpu_load_user = -1.f;}
PIString name;
PIDateTime created;
PISystemTime work_time;
PISystemTime kernel_time;
PISystemTime user_time;
float cpu_load_kernel;
float cpu_load_user;
/*PIString device;
PIString filesystem;
PIString label;
ullong space_all;
ullong space_used;
ullong space_free;*/
};
bool startOnProcess(int pID);
bool startOnSelf() {return startOnProcess(PIProcess::currentPID());}
bool startOnProcess(int pID, int interval_ms = 1000);
bool startOnSelf(int interval_ms = 1000);
void stop();
const ProcessStats & statistic() const {return stat;}
PIVector<ThreadStats> threadsStatistic() const;
void setStatistic(const ProcessStats & s) {stat = s; makeStrings();}
private:
void stop();
void run();
void makeStrings();
void gatherThreadsStats();
float calcThreadUsage(PISystemTime & t_new, PISystemTime & t_old);
PIFile file, filem;
ProcessStats stat;
PIVector<ThreadStats> cur_ts;
PIMap<const void*, ThreadStats> last_tm, cur_tm;
bool self_;
int pID_, page_size, cpu_count, cycle;
PRIVATE_DECLARATION
};
inline PICout operator <<(PICout s, const PISystemMonitor::ThreadStats & v) {
s.setControl(0, true);
s << "ThreadInfo(\"" << v.name << "\", created " << v.created
<< ", work " << v.work_time.toMilliseconds() << " ms"
<< ", kernel " << v.kernel_time.toMilliseconds() << " ms"
<< ", user " << v.user_time.toMilliseconds() << " ms"
/*<< ", label \"" << v.label << "\", all " << PIString::readableSize(v.space_all)
<< ", used " << PIString::readableSize(v.space_used)
<< ", free " << PIString::readableSize(v.space_free)*/ << ")\n";
s.restoreControl();
return s;
}
#endif // PISYSTEMMONITOR_H