git-svn-id: svn://db.shs.com.ru/pip@370 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -44,6 +44,7 @@ option(DEBUG "Build with -g3" 0)
|
|||||||
set(CMAKE_BUILD_TYPE "Release")
|
set(CMAKE_BUILD_TYPE "Release")
|
||||||
set(LIBS)
|
set(LIBS)
|
||||||
if(DEBUG)
|
if(DEBUG)
|
||||||
|
add_definitions(-DPIP_DEBUG)
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|||||||
@@ -107,12 +107,13 @@ PIConsole::PIConsole(bool startNow, PIKbdListener::KBFunc slot): PIThread() {
|
|||||||
tabs.reserve(16);
|
tabs.reserve(16);
|
||||||
addTab("main");
|
addTab("main");
|
||||||
listener = new PIKbdListener(key_event, this);
|
listener = new PIKbdListener(key_event, this);
|
||||||
|
peer_timer = new PITimer();
|
||||||
peer = 0;
|
peer = 0;
|
||||||
server_mode = pause_ = false;
|
server_mode = pause_ = false;
|
||||||
state = Disconnected;
|
state = Disconnected;
|
||||||
peer_timer.addDelimiter(20);
|
peer_timer->addDelimiter(20);
|
||||||
peer_timer.setName("__S__PIConsole::peer_timer");
|
peer_timer->setName("__S__PIConsole::peer_timer");
|
||||||
CONNECT2(void, void * , int, &peer_timer, tickEvent, this, peerTimer);
|
CONNECT2(void, void * , int, peer_timer, tickEvent, this, peerTimer);
|
||||||
if (startNow) start();
|
if (startNow) start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,6 +124,7 @@ PIConsole::~PIConsole() {
|
|||||||
stop();
|
stop();
|
||||||
clearTabs(false);
|
clearTabs(false);
|
||||||
delete listener;
|
delete listener;
|
||||||
|
delete peer_timer;
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
SetConsoleMode(PRIVATE->hOut, PRIVATE->smode);
|
SetConsoleMode(PRIVATE->hOut, PRIVATE->smode);
|
||||||
SetConsoleTextAttribute(PRIVATE->hOut, PRIVATE->dattr);
|
SetConsoleTextAttribute(PRIVATE->hOut, PRIVATE->dattr);
|
||||||
@@ -882,14 +884,14 @@ void PIConsole::startServer(const PIString & name) {
|
|||||||
peer = new PIPeer("_rcs_:" + name);
|
peer = new PIPeer("_rcs_:" + name);
|
||||||
CONNECT2(void, const PIString & , const PIByteArray &, peer, dataReceivedEvent, this, peerReceived);
|
CONNECT2(void, const PIString & , const PIByteArray &, peer, dataReceivedEvent, this, peerReceived);
|
||||||
CONNECT1(void, const PIString & , peer, peerDisconnectedEvent, this, peerDisconnectedEvent);
|
CONNECT1(void, const PIString & , peer, peerDisconnectedEvent, this, peerDisconnectedEvent);
|
||||||
peer_timer.start(50.);
|
peer_timer->start(50.);
|
||||||
serverSendInfo();
|
serverSendInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PIConsole::stopPeer() {
|
void PIConsole::stopPeer() {
|
||||||
remote_clients.clear();
|
remote_clients.clear();
|
||||||
peer_timer.stop();
|
peer_timer->stop();
|
||||||
if (peer != 0) delete peer;
|
if (peer != 0) delete peer;
|
||||||
peer = 0;
|
peer = 0;
|
||||||
state = Disconnected;
|
state = Disconnected;
|
||||||
@@ -914,7 +916,7 @@ void PIConsole::listenServers() {
|
|||||||
srand(PISystemTime::current().nanoseconds);
|
srand(PISystemTime::current().nanoseconds);
|
||||||
peer = new PIPeer("_rcc_:" + PIDateTime::current().toString("hhmmssddMMyy_") + PIString::fromNumber(rand()));
|
peer = new PIPeer("_rcc_:" + PIDateTime::current().toString("hhmmssddMMyy_") + PIString::fromNumber(rand()));
|
||||||
CONNECT2(void, const PIString & , const PIByteArray &, peer, dataReceivedEvent, this, peerReceived);
|
CONNECT2(void, const PIString & , const PIByteArray &, peer, dataReceivedEvent, this, peerReceived);
|
||||||
peer_timer.start(100.);
|
peer_timer->start(100.);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -24,12 +24,12 @@
|
|||||||
#define PICONSOLE_H
|
#define PICONSOLE_H
|
||||||
|
|
||||||
#include "pikbdlistener.h"
|
#include "pikbdlistener.h"
|
||||||
#include "pitimer.h"
|
|
||||||
|
|
||||||
class PIProtocol;
|
class PIProtocol;
|
||||||
class PIDiagnostics;
|
class PIDiagnostics;
|
||||||
class PISystemMonitor;
|
class PISystemMonitor;
|
||||||
class PIPeer;
|
class PIPeer;
|
||||||
|
class PITimer;
|
||||||
|
|
||||||
class PIP_EXPORT PIConsole: public PIThread
|
class PIP_EXPORT PIConsole: public PIThread
|
||||||
{
|
{
|
||||||
@@ -444,7 +444,7 @@ public:
|
|||||||
uint cur_tab, col_cnt;
|
uint cur_tab, col_cnt;
|
||||||
|
|
||||||
PIPeer * peer;
|
PIPeer * peer;
|
||||||
PITimer peer_timer;
|
PITimer * peer_timer;
|
||||||
PITimeMeasurer peer_tm;
|
PITimeMeasurer peer_tm;
|
||||||
PIString server_name;
|
PIString server_name;
|
||||||
bool server_mode, pause_;
|
bool server_mode, pause_;
|
||||||
|
|||||||
@@ -23,7 +23,6 @@
|
|||||||
#ifndef PITERMINAL_H
|
#ifndef PITERMINAL_H
|
||||||
#define PITERMINAL_H
|
#define PITERMINAL_H
|
||||||
|
|
||||||
#include "pithread.h"
|
|
||||||
#include "pikbdlistener.h"
|
#include "pikbdlistener.h"
|
||||||
#include "piscreentypes.h"
|
#include "piscreentypes.h"
|
||||||
|
|
||||||
|
|||||||
@@ -27,8 +27,14 @@
|
|||||||
#define PICONTAINERS_H
|
#define PICONTAINERS_H
|
||||||
|
|
||||||
#include "picout.h"
|
#include "picout.h"
|
||||||
#include <cassert>
|
#ifdef PIP_DEBUG
|
||||||
|
# include <cassert>
|
||||||
|
#endif
|
||||||
|
#ifndef assert
|
||||||
|
# define assert(x)
|
||||||
|
#endif
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
|
#include <string.h>
|
||||||
#ifndef PIP_MEMALIGN_BYTES
|
#ifndef PIP_MEMALIGN_BYTES
|
||||||
# define PIP_MEMALIGN_BYTES (sizeof(void*)*4)
|
# define PIP_MEMALIGN_BYTES (sizeof(void*)*4)
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#ifndef PILIST_H
|
#ifndef PILIST_H
|
||||||
#define PILIST_H
|
#define PILIST_H
|
||||||
#include "pivector.h"
|
#include "pibase.h"
|
||||||
#include <list>
|
#include <list>
|
||||||
|
|
||||||
template<typename Type, typename Allocator = std::allocator<Type> >
|
template<typename Type, typename Allocator = std::allocator<Type> >
|
||||||
|
|||||||
@@ -25,7 +25,6 @@
|
|||||||
#ifndef PIVECTOR_H
|
#ifndef PIVECTOR_H
|
||||||
#define PIVECTOR_H
|
#define PIVECTOR_H
|
||||||
|
|
||||||
#include "piincludes.h"
|
|
||||||
#include "picontainers.h"
|
#include "picontainers.h"
|
||||||
|
|
||||||
#if !defined(PIP_CONTAINERS_STL) || defined(DOXYGEN)
|
#if !defined(PIP_CONTAINERS_STL) || defined(DOXYGEN)
|
||||||
|
|||||||
@@ -91,9 +91,7 @@
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stdarg.h>
|
#include <cstddef>
|
||||||
#include <stddef.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
# ifdef CC_VC
|
# ifdef CC_VC
|
||||||
# define SHUT_RDWR 2
|
# define SHUT_RDWR 2
|
||||||
@@ -105,7 +103,6 @@
|
|||||||
# endif
|
# endif
|
||||||
typedef int socklen_t;
|
typedef int socklen_t;
|
||||||
extern long long __pi_perf_freq;
|
extern long long __pi_perf_freq;
|
||||||
inline int random() {return rand();}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ANDROID
|
#ifdef ANDROID
|
||||||
|
|||||||
@@ -20,12 +20,10 @@
|
|||||||
#ifndef PICOREMODULE_H
|
#ifndef PICOREMODULE_H
|
||||||
#define PICOREMODULE_H
|
#define PICOREMODULE_H
|
||||||
|
|
||||||
#include "pistring.h"
|
|
||||||
#include "picollection.h"
|
#include "picollection.h"
|
||||||
#include "piobject.h"
|
#include "piobject.h"
|
||||||
#include "pistatemachine.h"
|
#include "pistatemachine.h"
|
||||||
#include "pitime.h"
|
#include "pitime.h"
|
||||||
#include "pivariant.h"
|
|
||||||
#include "picli.h"
|
#include "picli.h"
|
||||||
#include "pichunkstream.h"
|
#include "pichunkstream.h"
|
||||||
#include "pipropertystorage.h"
|
#include "pipropertystorage.h"
|
||||||
|
|||||||
@@ -16,10 +16,8 @@
|
|||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
#include "piincludes_p.h"
|
||||||
#include "pistring.h"
|
#include "pistring.h"
|
||||||
#include <iostream>
|
|
||||||
#include <string.h>
|
|
||||||
#ifdef PIP_ICU
|
#ifdef PIP_ICU
|
||||||
# include "unicode/ucnv.h"
|
# include "unicode/ucnv.h"
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -24,7 +24,6 @@
|
|||||||
#define PIBASETRANSFER_H
|
#define PIBASETRANSFER_H
|
||||||
|
|
||||||
#include "picrc.h"
|
#include "picrc.h"
|
||||||
#include "pitimer.h"
|
|
||||||
#include "pidiagnostics.h"
|
#include "pidiagnostics.h"
|
||||||
|
|
||||||
class PIBaseTransfer: public PIObject
|
class PIBaseTransfer: public PIObject
|
||||||
|
|||||||
@@ -29,7 +29,6 @@
|
|||||||
#include "pitimer.h"
|
#include "pitimer.h"
|
||||||
#include "piconfig.h"
|
#include "piconfig.h"
|
||||||
#include "pifile.h"
|
#include "pifile.h"
|
||||||
#include "math.h"
|
|
||||||
|
|
||||||
class PIProtocol; /// DEPRECATED
|
class PIProtocol; /// DEPRECATED
|
||||||
|
|
||||||
|
|||||||
@@ -1,30 +0,0 @@
|
|||||||
/*! \file pimath.h
|
|
||||||
* \brief Many mathematical functions and classes
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
PIP - Platform Independent Primitives
|
|
||||||
Many mathematical functions and classes
|
|
||||||
Copyright (C) 2016 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 <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef PIMATH_H
|
|
||||||
#define PIMATH_H
|
|
||||||
|
|
||||||
#include "pimathsolver.h"
|
|
||||||
#include "pistatistic.h"
|
|
||||||
#include "pifft.h"
|
|
||||||
|
|
||||||
#endif // PIMATH_H
|
|
||||||
@@ -89,6 +89,9 @@
|
|||||||
#ifndef M_GRAVITY_CONST
|
#ifndef M_GRAVITY_CONST
|
||||||
# define M_GRAVITY_CONST 398600.4418e9;
|
# define M_GRAVITY_CONST 398600.4418e9;
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef WINDOWS
|
||||||
|
inline int random() {return rand();}
|
||||||
|
#endif
|
||||||
|
|
||||||
using std::complex;
|
using std::complex;
|
||||||
|
|
||||||
@@ -163,7 +166,6 @@ inline PIByteArray & operator >>(PIByteArray & s, complexd & v) {double t0, t1;
|
|||||||
inline PIByteArray & operator >>(PIByteArray & s, complexld & v) {ldouble t0, t1; s >> t0; s >> t1; v = complexld(t0, t1); return s;}
|
inline PIByteArray & operator >>(PIByteArray & s, complexld & v) {ldouble t0, t1; s >> t0; s >> t1; v = complexld(t0, t1); return s;}
|
||||||
|
|
||||||
void randomize();
|
void randomize();
|
||||||
|
|
||||||
// [-1 ; 1]
|
// [-1 ; 1]
|
||||||
inline double randomd() {return (double)
|
inline double randomd() {return (double)
|
||||||
#ifdef QNX
|
#ifdef QNX
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
#define PIMATHVECTOR_H
|
#define PIMATHVECTOR_H
|
||||||
|
|
||||||
#include "pimathbase.h"
|
#include "pimathbase.h"
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
template<uint Cols, uint Rows, typename Type>
|
template<uint Cols, uint Rows, typename Type>
|
||||||
class PIMathMatrixT;
|
class PIMathMatrixT;
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "piincludes.h"
|
||||||
#include "pisignals.h"
|
#include "pisignals.h"
|
||||||
#ifdef BLACKBERRY
|
#ifdef BLACKBERRY
|
||||||
# include <signal.h>
|
# include <signal.h>
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
#ifndef PISIGNALS_H
|
#ifndef PISIGNALS_H
|
||||||
#define PISIGNALS_H
|
#define PISIGNALS_H
|
||||||
|
|
||||||
#include "piincludes.h"
|
#include "piflags.h"
|
||||||
|
|
||||||
class PIP_EXPORT PISignals
|
class PIP_EXPORT PISignals
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -21,10 +21,23 @@
|
|||||||
#include "pisystemmonitor.h"
|
#include "pisystemmonitor.h"
|
||||||
#include "pisysteminfo.h"
|
#include "pisysteminfo.h"
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
|
# include <psapi.h>
|
||||||
# include <tlhelp32.h>
|
# include <tlhelp32.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
PRIVATE_DEFINITION_START(PISystemMonitor)
|
||||||
|
#ifndef WINDOWS
|
||||||
|
llong cpu_u_cur, cpu_u_prev, cpu_s_cur, cpu_s_prev;
|
||||||
|
#else
|
||||||
|
HANDLE hProc;
|
||||||
|
PROCESS_MEMORY_COUNTERS mem_cnt;
|
||||||
|
PISystemTime tm_kernel, tm_user;
|
||||||
|
PITimeMeasurer tm;
|
||||||
|
#endif
|
||||||
|
PRIVATE_DEFINITION_END(PISystemMonitor)
|
||||||
|
|
||||||
|
|
||||||
PISystemMonitor::PISystemMonitor(): PIThread() {
|
PISystemMonitor::PISystemMonitor(): PIThread() {
|
||||||
pID_ = cycle = 0;
|
pID_ = cycle = 0;
|
||||||
cpu_count = PISystemInfo::instance()->processorsCount;
|
cpu_count = PISystemInfo::instance()->processorsCount;
|
||||||
@@ -35,8 +48,8 @@ PISystemMonitor::PISystemMonitor(): PIThread() {
|
|||||||
page_size = getpagesize();
|
page_size = getpagesize();
|
||||||
# endif
|
# endif
|
||||||
#else
|
#else
|
||||||
hProc = 0;
|
PRIVATE->hProc = 0;
|
||||||
mem_cnt.cb = sizeof(mem_cnt);
|
PRIVATE->mem_cnt.cb = sizeof(PRIVATE->mem_cnt);
|
||||||
#endif
|
#endif
|
||||||
setName("system_monitor");
|
setName("system_monitor");
|
||||||
}
|
}
|
||||||
@@ -66,12 +79,12 @@ bool PISystemMonitor::startOnProcess(int pID) {
|
|||||||
}
|
}
|
||||||
cycle = -1;
|
cycle = -1;
|
||||||
#else
|
#else
|
||||||
hProc = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pID_);
|
PRIVATE->hProc = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pID_);
|
||||||
if (hProc == 0) {
|
if (PRIVATE->hProc == 0) {
|
||||||
piCoutObj << "Can`t open process with ID = " << pID_ << "," << errorString();
|
piCoutObj << "Can`t open process with ID = " << pID_ << "," << errorString();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
tm.reset();
|
PRIVATE->tm.reset();
|
||||||
#endif
|
#endif
|
||||||
return start(1000);
|
return start(1000);
|
||||||
}
|
}
|
||||||
@@ -80,9 +93,9 @@ bool PISystemMonitor::startOnProcess(int pID) {
|
|||||||
void PISystemMonitor::stop() {
|
void PISystemMonitor::stop() {
|
||||||
PIThread::stop();
|
PIThread::stop();
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
if (hProc != 0) {
|
if (PRIVATE->hProc != 0) {
|
||||||
CloseHandle(hProc);
|
CloseHandle(PRIVATE->hProc);
|
||||||
hProc = 0;
|
PRIVATE->hProc = 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -112,17 +125,17 @@ void PISystemMonitor::run() {
|
|||||||
stat.group_ID = sl[3].toInt();
|
stat.group_ID = sl[3].toInt();
|
||||||
stat.session_ID = sl[4].toInt();
|
stat.session_ID = sl[4].toInt();
|
||||||
if (cycle < 0) {
|
if (cycle < 0) {
|
||||||
cpu_u_prev = cpu_u_cur = sl[12].toLLong();
|
PRIVATE->cpu_u_prev = PRIVATE->cpu_u_cur = sl[12].toLLong();
|
||||||
cpu_s_prev = cpu_s_cur = sl[13].toLLong();
|
PRIVATE->cpu_s_prev = PRIVATE->cpu_s_cur = sl[13].toLLong();
|
||||||
}
|
}
|
||||||
cycle++;
|
cycle++;
|
||||||
//if (cycle >= 4) {
|
//if (cycle >= 4) {
|
||||||
cpu_u_prev = cpu_u_cur;
|
PRIVATE->cpu_u_prev = PRIVATE->cpu_u_cur;
|
||||||
cpu_s_prev = cpu_s_cur;
|
PRIVATE->cpu_s_prev = PRIVATE->cpu_s_cur;
|
||||||
cpu_u_cur = sl[12].toLLong();
|
PRIVATE->cpu_u_cur = sl[12].toLLong();
|
||||||
cpu_s_cur = sl[13].toLLong();
|
PRIVATE->cpu_s_cur = sl[13].toLLong();
|
||||||
stat.cpu_load_system = cpu_s_cur - cpu_s_prev;
|
stat.cpu_load_system = PRIVATE->cpu_s_cur - PRIVATE->cpu_s_prev;
|
||||||
stat.cpu_load_user = cpu_u_cur - cpu_u_prev;
|
stat.cpu_load_user = PRIVATE->cpu_u_cur - PRIVATE->cpu_u_prev;
|
||||||
stat.cpu_load_system /= cpu_count;
|
stat.cpu_load_system /= cpu_count;
|
||||||
stat.cpu_load_user /= cpu_count;
|
stat.cpu_load_user /= cpu_count;
|
||||||
cycle = 0;
|
cycle = 0;
|
||||||
@@ -143,10 +156,10 @@ void PISystemMonitor::run() {
|
|||||||
stat.ID = pID_;
|
stat.ID = pID_;
|
||||||
// HMODULE hMod;
|
// HMODULE hMod;
|
||||||
// DWORD cbNeeded;
|
// DWORD cbNeeded;
|
||||||
if (GetProcessMemoryInfo(hProc, &mem_cnt, sizeof(mem_cnt)) != 0) {
|
if (GetProcessMemoryInfo(PRIVATE->hProc, &PRIVATE->mem_cnt, sizeof(PRIVATE->mem_cnt)) != 0) {
|
||||||
stat.physical_memsize = mem_cnt.WorkingSetSize;
|
stat.physical_memsize = PRIVATE->mem_cnt.WorkingSetSize;
|
||||||
}
|
}
|
||||||
stat.priority = GetPriorityClass(hProc);
|
stat.priority = GetPriorityClass(PRIVATE->hProc);
|
||||||
HANDLE snap = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, pID_);
|
HANDLE snap = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, pID_);
|
||||||
int thcnt = 0;
|
int thcnt = 0;
|
||||||
if (snap != 0) {
|
if (snap != 0) {
|
||||||
@@ -164,12 +177,12 @@ void PISystemMonitor::run() {
|
|||||||
CloseHandle(snap);
|
CloseHandle(snap);
|
||||||
}
|
}
|
||||||
FILETIME ft0, ft1, ft_kernel, ft_user;
|
FILETIME ft0, ft1, ft_kernel, ft_user;
|
||||||
double el_s = tm.elapsed_s() * cpu_count / 100.;
|
double el_s = PRIVATE->tm.elapsed_s() * cpu_count / 100.;
|
||||||
if (GetProcessTimes(hProc, &ft0, &ft1, &ft_kernel, &ft_user) != 0) {
|
if (GetProcessTimes(PRIVATE->hProc, &ft0, &ft1, &ft_kernel, &ft_user) != 0) {
|
||||||
PISystemTime tm_kernel_c(ft_kernel), tm_user_c(ft_user);
|
PISystemTime tm_kernel_c(ft_kernel), tm_user_c(ft_user);
|
||||||
if (cycle < 0) {
|
if (cycle < 0) {
|
||||||
tm_kernel = tm_kernel_c;
|
PRIVATE->tm_kernel = tm_kernel_c;
|
||||||
tm_user = tm_user_c;
|
PRIVATE->tm_user = tm_user_c;
|
||||||
}
|
}
|
||||||
//cycle++;
|
//cycle++;
|
||||||
cycle = 0;
|
cycle = 0;
|
||||||
@@ -177,16 +190,16 @@ void PISystemMonitor::run() {
|
|||||||
stat.cpu_load_system = 0.f;
|
stat.cpu_load_system = 0.f;
|
||||||
stat.cpu_load_user = 0.f;
|
stat.cpu_load_user = 0.f;
|
||||||
} else {
|
} else {
|
||||||
stat.cpu_load_system = (tm_kernel_c - tm_kernel).toSeconds() / el_s;
|
stat.cpu_load_system = (tm_kernel_c - PRIVATE->tm_kernel).toSeconds() / el_s;
|
||||||
stat.cpu_load_user = (tm_user_c - tm_user).toSeconds() / el_s;
|
stat.cpu_load_user = (tm_user_c - PRIVATE->tm_user).toSeconds() / el_s;
|
||||||
}
|
}
|
||||||
tm_kernel = tm_kernel_c;
|
PRIVATE->tm_kernel = tm_kernel_c;
|
||||||
tm_user = tm_user_c;
|
PRIVATE->tm_user = tm_user_c;
|
||||||
} else {
|
} else {
|
||||||
stat.cpu_load_system = 0.f;
|
stat.cpu_load_system = 0.f;
|
||||||
stat.cpu_load_user = 0.f;
|
stat.cpu_load_user = 0.f;
|
||||||
}
|
}
|
||||||
tm.reset();
|
PRIVATE->tm.reset();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
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);
|
||||||
|
|||||||
@@ -22,9 +22,6 @@
|
|||||||
|
|
||||||
#include "pithread.h"
|
#include "pithread.h"
|
||||||
#include "piprocess.h"
|
#include "piprocess.h"
|
||||||
#ifdef WINDOWS
|
|
||||||
# include <psapi.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
class PIP_EXPORT PISystemMonitor: public PIThread
|
class PIP_EXPORT PISystemMonitor: public PIThread
|
||||||
{
|
{
|
||||||
@@ -71,14 +68,7 @@ private:
|
|||||||
PIFile file, filem;
|
PIFile file, filem;
|
||||||
ProcessStats stat;
|
ProcessStats stat;
|
||||||
int pID_, page_size, cpu_count, cycle;
|
int pID_, page_size, cpu_count, cycle;
|
||||||
#ifndef WINDOWS
|
PRIVATE_DECLARATION
|
||||||
llong cpu_u_cur, cpu_u_prev, cpu_s_cur, cpu_s_prev;
|
|
||||||
#else
|
|
||||||
HANDLE hProc;
|
|
||||||
PROCESS_MEMORY_COUNTERS mem_cnt;
|
|
||||||
PISystemTime tm_kernel, tm_user;
|
|
||||||
PITimeMeasurer tm;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -17,12 +17,6 @@
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "pimutex.h"
|
|
||||||
#ifdef WINDOWS
|
|
||||||
# include <windef.h>
|
|
||||||
# include <winbase.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/** \class PIMutex
|
/** \class PIMutex
|
||||||
* \brief Mutex
|
* \brief Mutex
|
||||||
* \details
|
* \details
|
||||||
@@ -40,6 +34,25 @@
|
|||||||
*
|
*
|
||||||
* */
|
* */
|
||||||
|
|
||||||
|
#include "pimutex.h"
|
||||||
|
#ifdef WINDOWS
|
||||||
|
# include <windef.h>
|
||||||
|
# include <winbase.h>
|
||||||
|
#endif
|
||||||
|
#ifdef BLACKBERRY
|
||||||
|
# include <pthread.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
PRIVATE_DEFINITION_START(PIMutex)
|
||||||
|
#ifdef WINDOWS
|
||||||
|
void *
|
||||||
|
#else
|
||||||
|
pthread_mutex_t
|
||||||
|
#endif
|
||||||
|
mutex;
|
||||||
|
PRIVATE_DEFINITION_END(PIMutex)
|
||||||
|
|
||||||
|
|
||||||
PIMutex::PIMutex(): inited_(false) {
|
PIMutex::PIMutex(): inited_(false) {
|
||||||
init();
|
init();
|
||||||
@@ -53,9 +66,9 @@ PIMutex::~PIMutex() {
|
|||||||
|
|
||||||
void PIMutex::lock() {
|
void PIMutex::lock() {
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
WaitForSingleObject(mutex, INFINITE);
|
WaitForSingleObject(PRIVATE->mutex, INFINITE);
|
||||||
#else
|
#else
|
||||||
pthread_mutex_lock(&mutex);
|
pthread_mutex_lock(&(PRIVATE->mutex));
|
||||||
#endif
|
#endif
|
||||||
locked = true;
|
locked = true;
|
||||||
}
|
}
|
||||||
@@ -63,9 +76,9 @@ void PIMutex::lock() {
|
|||||||
|
|
||||||
void PIMutex::unlock() {
|
void PIMutex::unlock() {
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
ReleaseMutex(mutex);
|
ReleaseMutex(PRIVATE->mutex);
|
||||||
#else
|
#else
|
||||||
pthread_mutex_unlock(&mutex);
|
pthread_mutex_unlock(&(PRIVATE->mutex));
|
||||||
#endif
|
#endif
|
||||||
locked = false;
|
locked = false;
|
||||||
}
|
}
|
||||||
@@ -74,9 +87,9 @@ void PIMutex::unlock() {
|
|||||||
bool PIMutex::tryLock() {
|
bool PIMutex::tryLock() {
|
||||||
bool ret =
|
bool ret =
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
(WaitForSingleObject(mutex, 0) == WAIT_OBJECT_0);
|
(WaitForSingleObject(PRIVATE->mutex, 0) == WAIT_OBJECT_0);
|
||||||
#else
|
#else
|
||||||
(pthread_mutex_trylock(&mutex) == 0);
|
(pthread_mutex_trylock(&(PRIVATE->mutex)) == 0);
|
||||||
#endif
|
#endif
|
||||||
locked = true;
|
locked = true;
|
||||||
return ret;
|
return ret;
|
||||||
@@ -91,14 +104,14 @@ bool PIMutex::isLocked() const {
|
|||||||
void PIMutex::init() {
|
void PIMutex::init() {
|
||||||
if (inited_) destroy();
|
if (inited_) destroy();
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
mutex = CreateMutex(0, false, 0);
|
PRIVATE->mutex = CreateMutex(0, false, 0);
|
||||||
#else
|
#else
|
||||||
pthread_mutexattr_t attr;
|
pthread_mutexattr_t attr;
|
||||||
memset(&attr, 0, sizeof(attr));
|
memset(&attr, 0, sizeof(attr));
|
||||||
pthread_mutexattr_init(&attr);
|
pthread_mutexattr_init(&attr);
|
||||||
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_NORMAL);
|
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_NORMAL);
|
||||||
memset(&mutex, 0, sizeof(mutex));
|
memset(&(PRIVATE->mutex), 0, sizeof(PRIVATE->mutex));
|
||||||
pthread_mutex_init(&mutex, &attr);
|
pthread_mutex_init(&(PRIVATE->mutex), &attr);
|
||||||
pthread_mutexattr_destroy(&attr);
|
pthread_mutexattr_destroy(&attr);
|
||||||
#endif
|
#endif
|
||||||
locked = false;
|
locked = false;
|
||||||
@@ -109,10 +122,10 @@ void PIMutex::init() {
|
|||||||
void PIMutex::destroy() {
|
void PIMutex::destroy() {
|
||||||
if (inited_) {
|
if (inited_) {
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
if (mutex) CloseHandle(mutex);
|
if (PRIVATE->mutex) CloseHandle(PRIVATE->mutex);
|
||||||
mutex = 0;
|
PRIVATE->mutex = 0;
|
||||||
#else
|
#else
|
||||||
pthread_mutex_destroy(&mutex);
|
pthread_mutex_destroy(&(PRIVATE->mutex));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
locked = inited_ = false;
|
locked = inited_ = false;
|
||||||
|
|||||||
@@ -24,9 +24,6 @@
|
|||||||
#define PIMUTEX_H
|
#define PIMUTEX_H
|
||||||
|
|
||||||
#include "piinit.h"
|
#include "piinit.h"
|
||||||
#ifdef BLACKBERRY
|
|
||||||
# include <pthread.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
class PIP_EXPORT PIMutex
|
class PIP_EXPORT PIMutex
|
||||||
{
|
{
|
||||||
@@ -62,13 +59,7 @@ private:
|
|||||||
|
|
||||||
void init();
|
void init();
|
||||||
void destroy();
|
void destroy();
|
||||||
|
PRIVATE_DECLARATION
|
||||||
#ifdef WINDOWS
|
|
||||||
void *
|
|
||||||
#else
|
|
||||||
pthread_mutex_t
|
|
||||||
#endif
|
|
||||||
mutex;
|
|
||||||
bool inited_;
|
bool inited_;
|
||||||
volatile bool locked;
|
volatile bool locked;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user