-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from dpscience/dpscience-local
preparing release v1.11
- Loading branch information
Showing
105 changed files
with
7,968 additions
and
5,582 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
/**************************************************************************** | ||
** | ||
** DDRS4PALS, a software for the acquisition of lifetime spectra using the | ||
** DRS4 evaluation board of PSI: https://www.psi.ch/drs/evaluation-board | ||
** | ||
** Copyright (C) 2016-2020 Danny Petschke | ||
** | ||
** 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/. | ||
** | ||
***************************************************************************** | ||
** | ||
** @author: Danny Petschke | ||
** @contact: [email protected] | ||
** | ||
*****************************************************************************/ | ||
|
||
#include "drs4cpuusage.h" | ||
|
||
static DRS4CPUUsageManager *__sharedInstanceDRS4CPUUsageManager = nullptr; | ||
|
||
float DRS4CPUUsageManager::releaseCPULoad() | ||
{ | ||
FILETIME ftime, fsys, fuser; | ||
ULARGE_INTEGER now, sys, user; | ||
|
||
GetSystemTimeAsFileTime(&ftime); | ||
memcpy(&now, &ftime, sizeof(FILETIME)); | ||
|
||
GetProcessTimes(GetCurrentProcess(), &ftime, &ftime, &fsys, &fuser); | ||
|
||
memcpy(&sys, &fsys, sizeof(FILETIME)); | ||
memcpy(&user, &fuser, sizeof(FILETIME)); | ||
|
||
double percent = (sys.QuadPart - m_lastSysCPU.QuadPart) + (user.QuadPart - m_lastUserCPU.QuadPart); | ||
|
||
percent /= (now.QuadPart - m_lastCPU.QuadPart); | ||
percent /= m_sysInfo.dwNumberOfProcessors; | ||
|
||
m_lastCPU = now; | ||
m_lastUserCPU = user; | ||
m_lastSysCPU = sys; | ||
|
||
return percent * 100; | ||
} | ||
|
||
void DRS4CPUUsageManager::start(int intervalInMilliseconds) | ||
{ | ||
if (intervalInMilliseconds != -1) | ||
m_interval = intervalInMilliseconds; | ||
|
||
m_timer.setInterval(int(m_interval*0.2)); // averaging over 5 cycles | ||
m_timer.setSingleShot(false); | ||
|
||
connect(&m_timer, SIGNAL(timeout()), this, SLOT(cpuLoad())); | ||
|
||
m_avgCPUUsage = 0.0; | ||
m_avgCounter = 0; | ||
|
||
FILETIME ftime, fsys, fuser; | ||
|
||
GetSystemInfo(&m_sysInfo); | ||
|
||
GetSystemTimeAsFileTime(&ftime); | ||
memcpy(&m_lastCPU, &ftime, sizeof(FILETIME)); | ||
|
||
GetProcessTimes(GetCurrentProcess(), &ftime, &ftime, &fsys, &fuser); | ||
memcpy(&m_lastSysCPU, &fsys, sizeof(FILETIME)); | ||
memcpy(&m_lastUserCPU, &fuser, sizeof(FILETIME)); | ||
|
||
m_timer.start(); | ||
} | ||
|
||
void DRS4CPUUsageManager::stop() | ||
{ | ||
m_timer.stop(); | ||
|
||
m_avgCPUUsage = 0.0; | ||
m_avgCounter = 0; | ||
|
||
disconnect(&m_timer, SIGNAL(timeout()), this, SLOT(cpuLoad())); | ||
} | ||
|
||
void DRS4CPUUsageManager::setInterval(int intervalInMilliseconds) | ||
{ | ||
m_interval = intervalInMilliseconds; | ||
} | ||
|
||
void DRS4CPUUsageManager::cpuLoad() | ||
{ | ||
m_avgCPUUsage += releaseCPULoad(); | ||
m_avgCounter ++; | ||
|
||
if (m_avgCounter == 5) { | ||
m_avgCPUUsage /= (float)m_avgCounter; | ||
|
||
emit cpu((int)m_avgCPUUsage); | ||
|
||
m_avgCounter = 0; | ||
m_avgCPUUsage = 0.0; | ||
} | ||
} | ||
|
||
int DRS4CPUUsageManager::interval() const | ||
{ | ||
return m_interval; | ||
} | ||
|
||
DRS4CPUUsageManager *DRS4CPUUsageManager::sharedInstance() | ||
{ | ||
if (!__sharedInstanceDRS4CPUUsageManager) | ||
__sharedInstanceDRS4CPUUsageManager = new DRS4CPUUsageManager; | ||
|
||
return __sharedInstanceDRS4CPUUsageManager; | ||
} | ||
|
||
DRS4CPUUsageManager::DRS4CPUUsageManager(QObject *parent) : | ||
QObject(parent) | ||
{ | ||
m_avgCPUUsage = 0.0; | ||
m_avgCounter = 0; | ||
|
||
m_interval = 1000; | ||
} | ||
|
||
DRS4CPUUsageManager::~DRS4CPUUsageManager() | ||
{ | ||
m_timer.stop(); | ||
|
||
DDELETE_SAFETY(__sharedInstanceDRS4CPUUsageManager); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/**************************************************************************** | ||
** | ||
** DDRS4PALS, a software for the acquisition of lifetime spectra using the | ||
** DRS4 evaluation board of PSI: https://www.psi.ch/drs/evaluation-board | ||
** | ||
** Copyright (C) 2016-2020 Danny Petschke | ||
** | ||
** 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/. | ||
** | ||
***************************************************************************** | ||
** | ||
** @author: Danny Petschke | ||
** @contact: [email protected] | ||
** | ||
*****************************************************************************/ | ||
|
||
#ifndef DRS4CPUUSAGE_H | ||
#define DRS4CPUUSAGE_H | ||
|
||
#include <QObject> | ||
#include <QTimer> | ||
|
||
#include "dversion.h" | ||
#include "DLib.h" | ||
|
||
#include <Windows.h> | ||
|
||
class DRS4CPUUsageManager : public QObject | ||
{ | ||
Q_OBJECT | ||
public slots: | ||
void start(int intervalInMilliseconds = -1); | ||
void stop(); | ||
|
||
void setInterval(int intervalInMilliseconds); | ||
|
||
public: | ||
static DRS4CPUUsageManager *sharedInstance(); | ||
|
||
int interval() const; | ||
|
||
signals: | ||
void cpu(int); | ||
|
||
private slots: | ||
void cpuLoad(); | ||
|
||
private: | ||
DRS4CPUUsageManager(QObject *parent = nullptr); | ||
virtual ~DRS4CPUUsageManager(); | ||
|
||
float releaseCPULoad(); | ||
|
||
QTimer m_timer; | ||
int m_interval; | ||
|
||
float m_avgCPUUsage; | ||
int m_avgCounter; | ||
|
||
SYSTEM_INFO m_sysInfo; | ||
|
||
ULARGE_INTEGER m_lastCPU; | ||
ULARGE_INTEGER m_lastUserCPU; | ||
ULARGE_INTEGER m_lastSysCPU; | ||
}; | ||
|
||
#endif // DRS4CPUUSAGE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.