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

This commit is contained in:
2017-06-21 18:23:53 +00:00
parent ed1a89508a
commit 96d67076dc
6 changed files with 62 additions and 47 deletions

View File

@@ -141,7 +141,7 @@ if(DEBUG)
message(STATUS "Building debug version") message(STATUS "Building debug version")
else() else()
set(CMAKE_BUILD_TYPE "Release") set(CMAKE_BUILD_TYPE "Release")
message(STATUS "Building relaese version") message(STATUS "Building release version")
endif() endif()

View File

@@ -103,7 +103,7 @@ bool PISystemMonitor::startOnSelf(int interval_ms) {
PIVector<PISystemMonitor::ThreadStats> PISystemMonitor::threadsStatistic() const { PIVector<PISystemMonitor::ThreadStats> PISystemMonitor::threadsStatistic() const {
mutex_.lock(); mutex_.lock();
PIVector<PISystemMonitor::ThreadStats> ret = cur_tm.values(); PIVector<PISystemMonitor::ThreadStats> ret = cur_ts;
mutex_.unlock(); mutex_.unlock();
return ret; return ret;
} }
@@ -122,6 +122,15 @@ void PISystemMonitor::stop() {
void PISystemMonitor::run() { void PISystemMonitor::run() {
cur_tm.clear();
tbid.clear();
__PIThreadCollection * pitc = __PIThreadCollection::instance();
pitc->lock();
PIVector<PIThread * > tv = pitc->threads();
piForeach (PIThread * t, tv)
if (t->isPIObject())
tbid[t->tid()] = t->name();
pitc->unlock();
#ifndef WINDOWS #ifndef WINDOWS
file.seekToBegin(); file.seekToBegin();
PIString str(file.readAll(true)); PIString str(file.readAll(true));
@@ -185,11 +194,16 @@ void PISystemMonitor::run() {
THREADENTRY32 thread; THREADENTRY32 thread;
thread.dwSize = sizeof(THREADENTRY32); thread.dwSize = sizeof(THREADENTRY32);
if (Thread32First(snap, &thread) == TRUE) { if (Thread32First(snap, &thread) == TRUE) {
if (thread.th32OwnerProcessID == DWORD(pID_)) if (thread.th32OwnerProcessID == DWORD(pID_)) {
++thcnt; ++thcnt;
gatherThread(thread.th32ThreadID);
}
while (Thread32Next(snap, &thread) == TRUE) { while (Thread32Next(snap, &thread) == TRUE) {
if (thread.th32OwnerProcessID == DWORD(pID_)) if (thread.th32OwnerProcessID == DWORD(pID_)) {
++thcnt; ++thcnt;
gatherThread(thread.th32ThreadID);
}
//piCout << thread.th32ThreadID;
} }
} }
stat.threads = thcnt; stat.threads = thcnt;
@@ -225,16 +239,15 @@ void PISystemMonitor::run() {
stat.cpu_load_system = piClampf(stat.cpu_load_system, 0.f, 100.f); stat.cpu_load_system = piClampf(stat.cpu_load_system, 0.f, 100.f);
stat.cpu_load_user = piClampf(stat.cpu_load_user, 0.f, 100.f); stat.cpu_load_user = piClampf(stat.cpu_load_user, 0.f, 100.f);
last_tm = cur_tm;
gatherThreadsStats();
//PISystemTime dt = PISystemTime::fromMilliseconds(delay_); //PISystemTime dt = PISystemTime::fromMilliseconds(delay_);
for (PIMap<const void*, ThreadStats>::iterator i = cur_tm.begin(); i != cur_tm.end(); ++i) { for (PIMap<llong, ThreadStats>::iterator i = cur_tm.begin(); i != cur_tm.end(); ++i) {
if (!last_tm.contains(i.key())) continue; if (!last_tm.contains(i.key())) continue;
ThreadStats & ts_new(i.value()); ThreadStats & ts_new(i.value());
ThreadStats & ts_old(last_tm[i.key()]); ThreadStats & ts_old(last_tm[i.key()]);
ts_new.cpu_load_kernel = calcThreadUsage(ts_new.kernel_time, ts_old.kernel_time); ts_new.cpu_load_kernel = calcThreadUsage(ts_new.kernel_time, ts_old.kernel_time);
ts_new.cpu_load_user = calcThreadUsage(ts_new.user_time, ts_old.user_time); ts_new.cpu_load_user = calcThreadUsage(ts_new.user_time, ts_old.user_time);
} }
last_tm = cur_tm;
lock(); lock();
cur_ts = cur_tm.values(); cur_ts = cur_tm.values();
unlock(); unlock();
@@ -252,35 +265,35 @@ void PISystemMonitor::makeStrings() {
} }
void PISystemMonitor::gatherThreadsStats() { void PISystemMonitor::gatherThread(llong id) {
cur_ts.clear(); PISystemMonitor::ThreadStats ts;
cur_tm.clear(); ts.id = id;
if (!self_) return; ts.name = tbid.value(id, "<non-PIThread>");
__PIThreadCollection * pitc = __PIThreadCollection::instance();
pitc->lock();
PIVector<PIThread*> tv = pitc->threads();
piForeachC (PIThread * t, tv) {
ThreadStats ts;
ts.name = t->name();
#ifdef WINDOWS #ifdef WINDOWS
FILETIME times[4]; FILETIME times[4];
PISystemTime ct = PISystemTime::current(); PISystemTime ct = PISystemTime::current();
if (GetThreadTimes(t->handle(), &(times[0]), &(times[1]), &(times[2]), &(times[3])) == 0) { HANDLE thdl = OpenThread(THREAD_QUERY_INFORMATION, FALSE, DWORD(id));
piCout << "[PISystemMonitor] threadsInfo():: GetThreadTimes() error:" << errorString(); if (thdl == NULL) {
continue; piCout << "[PISystemMonitor] gatherThread(" << id << "):: OpenThread() error:" << errorString();
return;
} }
if (GetThreadTimes(thdl, &(times[0]), &(times[1]), &(times[2]), &(times[3])) == 0) {
piCout << "[PISystemMonitor] gatherThread(" << id << "):: GetThreadTimes() error:" << errorString();
return;
}
CloseHandle(thdl);
ts.created = FILETIME2PIDateTime(times[0]); ts.created = FILETIME2PIDateTime(times[0]);
ts.work_time = ct - ts.created.toSystemTime(); ts.work_time = ct - ts.created.toSystemTime();
ts.kernel_time = FILETIME2PISystemTime(times[2]); ts.kernel_time = FILETIME2PISystemTime(times[2]);
ts.user_time = FILETIME2PISystemTime(times[3]); ts.user_time = FILETIME2PISystemTime(times[3]);
#else
#endif #endif
cur_ts << ts; //cur_ts << ts;
cur_tm[t] = ts; cur_tm[id] = ts;
}
pitc->unlock();
} }
float PISystemMonitor::calcThreadUsage(PISystemTime & t_new, PISystemTime & t_old) { float PISystemMonitor::calcThreadUsage(PISystemTime & t_new, PISystemTime & t_old) {
if (delay_ <= 0) return -1.; if (delay_ <= 0) return -1.;
return piClampf(100. * ((t_new - t_old).toMilliseconds() / delay_), 0.f, 100.f);} return piClampf(100. * ((t_new - t_old).toMilliseconds() / delay_), 0.f, 100.f);
}

View File

@@ -54,7 +54,8 @@ public:
float cpu_load_user; float cpu_load_user;
}; };
struct ThreadStats { struct ThreadStats {
ThreadStats() {cpu_load_kernel = cpu_load_user = -1.f;} ThreadStats() {id = 0; cpu_load_kernel = cpu_load_user = -1.f;}
llong id;
PIString name; PIString name;
PIDateTime created; PIDateTime created;
PISystemTime work_time; PISystemTime work_time;
@@ -81,13 +82,14 @@ public:
private: private:
void run(); void run();
void makeStrings(); void makeStrings();
void gatherThreadsStats(); void gatherThread(llong id);
float calcThreadUsage(PISystemTime & t_new, PISystemTime & t_old); float calcThreadUsage(PISystemTime & t_new, PISystemTime & t_old);
PIFile file, filem; PIFile file, filem;
ProcessStats stat; ProcessStats stat;
PIVector<ThreadStats> cur_ts; PIVector<ThreadStats> cur_ts;
PIMap<const void*, ThreadStats> last_tm, cur_tm; PIMap<llong, ThreadStats> last_tm, cur_tm;
PIMap<llong, PIString> tbid;
bool self_; bool self_;
int pID_, page_size, cpu_count, cycle; int pID_, page_size, cpu_count, cycle;
PRIVATE_DECLARATION PRIVATE_DECLARATION

View File

@@ -271,7 +271,7 @@ bool PIThread::startOnce() {
void PIThread::terminate() { void PIThread::terminate() {
if (PRIVATE->thread == 0) return; if (PRIVATE->thread == 0) return;
REGISTER_THREAD(this); UNREGISTER_THREAD(this);
PIINTROSPECTION_UNREGISTER_THREAD(tid()); PIINTROSPECTION_UNREGISTER_THREAD(tid());
terminating = running_ = false; terminating = running_ = false;
tid_ = -1; tid_ = -1;

View File

@@ -468,13 +468,6 @@ void Daemon::tileEvent(PIScreenTile * t, TileEvent e) {
void Daemon::keyEvent(PIKbdListener::KeyEvent key) { void Daemon::keyEvent(PIKbdListener::KeyEvent key) {
/*if (key.key == PIKbdListener::F2) {
PICout::setBufferActive(true, true);
piCout << sys_mon.threadsStatistic();
PIFile f("_.txt", PIIODevice::ReadWrite);
f.clear();
f << PICout::buffer(true);
}*/
if (!tile_root->visible) return; if (!tile_root->visible) return;
if (screen->dialogTile()) return; if (screen->dialogTile()) return;
switch (key.key) { switch (key.key) {

View File

@@ -78,9 +78,10 @@ public:
mt->hide(); mt->name() = "peer diag"; mt->hide(); mt->name() = "peer diag";
center->addTile(mt); mtiles << mt; center->addTile(mt); mtiles << mt;
TilePICout * outt = new TilePICout(); tpicout = new TilePICout();
outt->size_policy = PIScreenTypes::Expanding; tpicout->hide();
screen->rootTile()->addTile(outt); tpicout->size_policy = PIScreenTypes::Expanding;
screen->rootTile()->addTile(tpicout);
CONNECTU(screen, tileEvent, this, tileEvent) CONNECTU(screen, tileEvent, this, tileEvent)
CONNECTU(screen, keyPressed, this, keyEvent) CONNECTU(screen, keyPressed, this, keyEvent)
@@ -219,7 +220,7 @@ public:
piForeachC (PISystemMonitor::ThreadStats & t, ts) piForeachC (PISystemMonitor::ThreadStats & t, ts)
maxlen = piMaxi(maxlen, t.name.length()); maxlen = piMaxi(maxlen, t.name.length());
piForeachC (PISystemMonitor::ThreadStats & t, ts) { piForeachC (PISystemMonitor::ThreadStats & t, ts) {
PIString line = PIString(num++).expandLeftTo(2, ' ') + ": "; PIString line = PIString(++num).expandLeftTo(2, ' ') + ": ";
line += PIString(t.name).expandRightTo(maxlen, ' ') + ": k "; line += PIString(t.name).expandRightTo(maxlen, ' ') + ": k ";
PIString ns = PIString::fromNumber(t.cpu_load_kernel); ns = ns.left(ns.find('.') + 2); PIString ns = PIString::fromNumber(t.cpu_load_kernel); ns = ns.left(ns.find('.') + 2);
line += ns.expandLeftTo(5, ' ') + " %, u "; line += ns.expandLeftTo(5, ' ') + " %, u ";
@@ -280,6 +281,10 @@ public:
} }
} }
EVENT_HANDLER1(void, keyEvent, PIKbdListener::KeyEvent, e) { EVENT_HANDLER1(void, keyEvent, PIKbdListener::KeyEvent, e) {
if (e.key == PIKbdListener::F9) {
tpicout->visible = !tpicout->visible;
return;
}
if (e.key == PIKbdListener::Esc && e.modifiers[PIKbdListener::Shift]) { if (e.key == PIKbdListener::Esc && e.modifiers[PIKbdListener::Shift]) {
PIKbdListener::exiting = true; PIKbdListener::exiting = true;
return; return;
@@ -296,6 +301,7 @@ public:
Daemon & daemon_; Daemon & daemon_;
PIScreenTile * tmenu, * tinfo, * tfm, * tdaemon, * tpeer, * tpeerdiag; PIScreenTile * tmenu, * tinfo, * tfm, * tdaemon, * tpeer, * tpeerdiag;
TileList * peers_tl, * addrs_tl, * peermap_tl; TileList * peers_tl, * addrs_tl, * peermap_tl;
TilePICout * tpicout;
TileSimple * title; TileSimple * title;
TileSimple * peerinfo_tl, * peerinfo_header; TileSimple * peerinfo_tl, * peerinfo_header;
TileSimple * peerdiagdata_tl, * peerdiagservice_tl; TileSimple * peerdiagdata_tl, * peerdiagservice_tl;
@@ -380,6 +386,7 @@ int main(int argc, char * argv[]) {
Daemon * daemon = new Daemon(); Daemon * daemon = new Daemon();
if (!sip.isEmpty()) daemon->setTcpServerIP(sip); if (!sip.isEmpty()) daemon->setTcpServerIP(sip);
sys_mon.startOnSelf(); sys_mon.startOnSelf();
//sys_mon.startOnProcess(12404);
screen->enableExitCapture(PIKbdListener::F10); screen->enableExitCapture(PIKbdListener::F10);
if (!name.isEmpty()) if (!name.isEmpty())
daemon->changeName(pisd_prefix + name); daemon->changeName(pisd_prefix + name);