git-svn-id: svn://db.shs.com.ru/pip@819 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -26,14 +26,14 @@
|
||||
class PIP_EXPORT PISystemMonitor: public PIThread
|
||||
{
|
||||
PIOBJECT_SUBCLASS(PISystemMonitor, PIThread)
|
||||
friend class PIIntrospectionServer;
|
||||
public:
|
||||
PISystemMonitor();
|
||||
~PISystemMonitor();
|
||||
|
||||
struct ProcessStats {
|
||||
ProcessStats();
|
||||
PIString exec_name;
|
||||
PIString state;
|
||||
#pragma pack(push, 1)
|
||||
struct ProcessStatsFixed {
|
||||
ProcessStatsFixed();
|
||||
int ID;
|
||||
int parent_ID;
|
||||
int group_ID;
|
||||
@@ -48,40 +48,47 @@ public:
|
||||
ullong ram_total;
|
||||
ullong ram_free;
|
||||
ullong ram_used;
|
||||
PIString physical_memsize_readable;
|
||||
PIString resident_memsize_readable;
|
||||
PIString share_memsize_readable;
|
||||
PIString virtual_memsize_readable;
|
||||
PIString data_memsize_readable;
|
||||
float cpu_load_system;
|
||||
float cpu_load_user;
|
||||
};
|
||||
struct ThreadStats {
|
||||
ThreadStats() {id = 0; cpu_load_kernel = cpu_load_user = -1.f;}
|
||||
|
||||
struct ThreadStatsFixed {
|
||||
ThreadStatsFixed();
|
||||
llong id;
|
||||
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;*/
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
struct ProcessStats: ProcessStatsFixed {
|
||||
void makeStrings();
|
||||
PIString exec_name;
|
||||
PIString state;
|
||||
PIString physical_memsize_readable;
|
||||
PIString resident_memsize_readable;
|
||||
PIString share_memsize_readable;
|
||||
PIString virtual_memsize_readable;
|
||||
PIString data_memsize_readable;
|
||||
};
|
||||
|
||||
struct ThreadStats: ThreadStatsFixed {
|
||||
PIString name;
|
||||
PIDateTime created;
|
||||
};
|
||||
|
||||
#ifndef FREERTOS
|
||||
bool startOnProcess(int pID, int interval_ms = 1000);
|
||||
#endif
|
||||
bool startOnSelf(int interval_ms = 1000);
|
||||
void stop();
|
||||
|
||||
const ProcessStats & statistic() const {return stat;}
|
||||
int pID() const {return pID_;}
|
||||
ProcessStats statistic() const;
|
||||
PIVector<ThreadStats> threadsStatistic() const;
|
||||
void setStatistic(const ProcessStats & s) {stat = s; makeStrings();}
|
||||
void setStatistic(const ProcessStats & s);
|
||||
|
||||
static ullong totalRAM();
|
||||
static ullong freeRAM();
|
||||
@@ -90,19 +97,32 @@ public:
|
||||
|
||||
private:
|
||||
void run();
|
||||
void makeStrings();
|
||||
void gatherThread(llong id);
|
||||
float calcThreadUsage(PISystemTime & t_new, PISystemTime & t_old);
|
||||
|
||||
|
||||
ProcessStats stat;
|
||||
PIVector<ThreadStats> cur_ts;
|
||||
PIMap<llong, ThreadStats> last_tm, cur_tm;
|
||||
PIMap<llong, PIString> tbid;
|
||||
mutable PIMutex stat_mutex;
|
||||
int pID_, page_size, cpu_count, cycle;
|
||||
#ifndef FREERTOS
|
||||
PRIVATE_DECLARATION
|
||||
#endif
|
||||
|
||||
class Pool {
|
||||
friend class PISystemMonitor;
|
||||
public:
|
||||
static Pool * instance();
|
||||
PISystemMonitor * getByPID(int pID);
|
||||
private:
|
||||
void add(PISystemMonitor * sm);
|
||||
void remove(PISystemMonitor * sm);
|
||||
PIMap<int, PISystemMonitor*> sysmons;
|
||||
PIMutex mutex;
|
||||
};
|
||||
|
||||
|
||||
};
|
||||
|
||||
inline PICout operator <<(PICout s, const PISystemMonitor::ThreadStats & v) {
|
||||
@@ -118,4 +138,9 @@ inline PICout operator <<(PICout s, const PISystemMonitor::ThreadStats & v) {
|
||||
return s;
|
||||
}
|
||||
|
||||
PIByteArray & operator <<(PIByteArray & s, const PISystemMonitor::ProcessStats & v);
|
||||
PIByteArray & operator >>(PIByteArray & s, PISystemMonitor::ProcessStats & v);
|
||||
PIByteArray & operator <<(PIByteArray & s, const PISystemMonitor::ThreadStats & v);
|
||||
PIByteArray & operator >>(PIByteArray & s, PISystemMonitor::ThreadStats & v);
|
||||
|
||||
#endif // PISYSTEMMONITOR_H
|
||||
|
||||
Reference in New Issue
Block a user