/* PIP - Platform Independent Primitives Process resource monitor Copyright (C) 2017 Ivan Pelipenko peri4ko@yandex.ru This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef PISYSTEMMONITOR_H #define PISYSTEMMONITOR_H #include "pithread.h" #include "pifile.h" class PIP_EXPORT PISystemMonitor: public PIThread { PIOBJECT_SUBCLASS(PISystemMonitor, PIThread) public: PISystemMonitor(); ~PISystemMonitor(); struct ProcessStats { ProcessStats(); PIString exec_name; PIString state; int ID; int parent_ID; int group_ID; int session_ID; int priority; int threads; ulong physical_memsize; ulong resident_memsize; ulong share_memsize; ulong virtual_memsize; ulong data_memsize; 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;} 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;*/ }; bool startOnProcess(int pID, int interval_ms = 1000); bool startOnSelf(int interval_ms = 1000); void stop(); const ProcessStats & statistic() const {return stat;} PIVector threadsStatistic() const; void setStatistic(const ProcessStats & s) {stat = s; makeStrings();} private: void run(); void makeStrings(); void gatherThread(llong id); float calcThreadUsage(PISystemTime & t_new, PISystemTime & t_old); ProcessStats stat; PIVector cur_ts; PIMap last_tm, cur_tm; PIMap tbid; 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