Skip to content

Commit 3b5ef20

Browse files
authored
Merge pull request #10 from dpscience/dpscience-local
preparing release v1.11
2 parents 52219aa + f13b4c6 commit 3b5ef20

File tree

105 files changed

+7968
-5582
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+7968
-5582
lines changed

CPUUsage/drs4cpuusage.cpp

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
/****************************************************************************
2+
**
3+
** DDRS4PALS, a software for the acquisition of lifetime spectra using the
4+
** DRS4 evaluation board of PSI: https://www.psi.ch/drs/evaluation-board
5+
**
6+
** Copyright (C) 2016-2020 Danny Petschke
7+
**
8+
** This program is free software: you can redistribute it and/or modify
9+
** it under the terms of the GNU General Public License as published by
10+
** the Free Software Foundation, either version 3 of the License, or
11+
** (at your option) any later version.
12+
**
13+
** This program is distributed in the hope that it will be useful,
14+
** but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
** GNU General Public License for more details.
17+
**
18+
** You should have received a copy of the GNU General Public License
19+
** along with this program. If not, see http://www.gnu.org/licenses/.
20+
**
21+
*****************************************************************************
22+
**
23+
** @author: Danny Petschke
24+
** @contact: [email protected]
25+
**
26+
*****************************************************************************/
27+
28+
#include "drs4cpuusage.h"
29+
30+
static DRS4CPUUsageManager *__sharedInstanceDRS4CPUUsageManager = nullptr;
31+
32+
float DRS4CPUUsageManager::releaseCPULoad()
33+
{
34+
FILETIME ftime, fsys, fuser;
35+
ULARGE_INTEGER now, sys, user;
36+
37+
GetSystemTimeAsFileTime(&ftime);
38+
memcpy(&now, &ftime, sizeof(FILETIME));
39+
40+
GetProcessTimes(GetCurrentProcess(), &ftime, &ftime, &fsys, &fuser);
41+
42+
memcpy(&sys, &fsys, sizeof(FILETIME));
43+
memcpy(&user, &fuser, sizeof(FILETIME));
44+
45+
double percent = (sys.QuadPart - m_lastSysCPU.QuadPart) + (user.QuadPart - m_lastUserCPU.QuadPart);
46+
47+
percent /= (now.QuadPart - m_lastCPU.QuadPart);
48+
percent /= m_sysInfo.dwNumberOfProcessors;
49+
50+
m_lastCPU = now;
51+
m_lastUserCPU = user;
52+
m_lastSysCPU = sys;
53+
54+
return percent * 100;
55+
}
56+
57+
void DRS4CPUUsageManager::start(int intervalInMilliseconds)
58+
{
59+
if (intervalInMilliseconds != -1)
60+
m_interval = intervalInMilliseconds;
61+
62+
m_timer.setInterval(int(m_interval*0.2)); // averaging over 5 cycles
63+
m_timer.setSingleShot(false);
64+
65+
connect(&m_timer, SIGNAL(timeout()), this, SLOT(cpuLoad()));
66+
67+
m_avgCPUUsage = 0.0;
68+
m_avgCounter = 0;
69+
70+
FILETIME ftime, fsys, fuser;
71+
72+
GetSystemInfo(&m_sysInfo);
73+
74+
GetSystemTimeAsFileTime(&ftime);
75+
memcpy(&m_lastCPU, &ftime, sizeof(FILETIME));
76+
77+
GetProcessTimes(GetCurrentProcess(), &ftime, &ftime, &fsys, &fuser);
78+
memcpy(&m_lastSysCPU, &fsys, sizeof(FILETIME));
79+
memcpy(&m_lastUserCPU, &fuser, sizeof(FILETIME));
80+
81+
m_timer.start();
82+
}
83+
84+
void DRS4CPUUsageManager::stop()
85+
{
86+
m_timer.stop();
87+
88+
m_avgCPUUsage = 0.0;
89+
m_avgCounter = 0;
90+
91+
disconnect(&m_timer, SIGNAL(timeout()), this, SLOT(cpuLoad()));
92+
}
93+
94+
void DRS4CPUUsageManager::setInterval(int intervalInMilliseconds)
95+
{
96+
m_interval = intervalInMilliseconds;
97+
}
98+
99+
void DRS4CPUUsageManager::cpuLoad()
100+
{
101+
m_avgCPUUsage += releaseCPULoad();
102+
m_avgCounter ++;
103+
104+
if (m_avgCounter == 5) {
105+
m_avgCPUUsage /= (float)m_avgCounter;
106+
107+
emit cpu((int)m_avgCPUUsage);
108+
109+
m_avgCounter = 0;
110+
m_avgCPUUsage = 0.0;
111+
}
112+
}
113+
114+
int DRS4CPUUsageManager::interval() const
115+
{
116+
return m_interval;
117+
}
118+
119+
DRS4CPUUsageManager *DRS4CPUUsageManager::sharedInstance()
120+
{
121+
if (!__sharedInstanceDRS4CPUUsageManager)
122+
__sharedInstanceDRS4CPUUsageManager = new DRS4CPUUsageManager;
123+
124+
return __sharedInstanceDRS4CPUUsageManager;
125+
}
126+
127+
DRS4CPUUsageManager::DRS4CPUUsageManager(QObject *parent) :
128+
QObject(parent)
129+
{
130+
m_avgCPUUsage = 0.0;
131+
m_avgCounter = 0;
132+
133+
m_interval = 1000;
134+
}
135+
136+
DRS4CPUUsageManager::~DRS4CPUUsageManager()
137+
{
138+
m_timer.stop();
139+
140+
DDELETE_SAFETY(__sharedInstanceDRS4CPUUsageManager);
141+
}

CPUUsage/drs4cpuusage.h

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/****************************************************************************
2+
**
3+
** DDRS4PALS, a software for the acquisition of lifetime spectra using the
4+
** DRS4 evaluation board of PSI: https://www.psi.ch/drs/evaluation-board
5+
**
6+
** Copyright (C) 2016-2020 Danny Petschke
7+
**
8+
** This program is free software: you can redistribute it and/or modify
9+
** it under the terms of the GNU General Public License as published by
10+
** the Free Software Foundation, either version 3 of the License, or
11+
** (at your option) any later version.
12+
**
13+
** This program is distributed in the hope that it will be useful,
14+
** but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
** GNU General Public License for more details.
17+
**
18+
** You should have received a copy of the GNU General Public License
19+
** along with this program. If not, see http://www.gnu.org/licenses/.
20+
**
21+
*****************************************************************************
22+
**
23+
** @author: Danny Petschke
24+
** @contact: [email protected]
25+
**
26+
*****************************************************************************/
27+
28+
#ifndef DRS4CPUUSAGE_H
29+
#define DRS4CPUUSAGE_H
30+
31+
#include <QObject>
32+
#include <QTimer>
33+
34+
#include "dversion.h"
35+
#include "DLib.h"
36+
37+
#include <Windows.h>
38+
39+
class DRS4CPUUsageManager : public QObject
40+
{
41+
Q_OBJECT
42+
public slots:
43+
void start(int intervalInMilliseconds = -1);
44+
void stop();
45+
46+
void setInterval(int intervalInMilliseconds);
47+
48+
public:
49+
static DRS4CPUUsageManager *sharedInstance();
50+
51+
int interval() const;
52+
53+
signals:
54+
void cpu(int);
55+
56+
private slots:
57+
void cpuLoad();
58+
59+
private:
60+
DRS4CPUUsageManager(QObject *parent = nullptr);
61+
virtual ~DRS4CPUUsageManager();
62+
63+
float releaseCPULoad();
64+
65+
QTimer m_timer;
66+
int m_interval;
67+
68+
float m_avgCPUUsage;
69+
int m_avgCounter;
70+
71+
SYSTEM_INFO m_sysInfo;
72+
73+
ULARGE_INTEGER m_lastCPU;
74+
ULARGE_INTEGER m_lastUserCPU;
75+
ULARGE_INTEGER m_lastSysCPU;
76+
};
77+
78+
#endif // DRS4CPUUSAGE_H

DDRS4PALS.pro

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
#
55
#-------------------------------------------------
66

7-
QT += core gui concurrent script printsupport
7+
QT += core gui concurrent script printsupport network
88

99
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
1010

11-
TARGET = DDRS4PALS_1_0_10
11+
TARGET = DDRS4PALS_1_0_11
1212
TEMPLATE = app
1313

1414
RC_FILE = softwareIcon.rc
@@ -53,7 +53,11 @@ SOURCES += main.cpp\
5353
GUI/drs4calculatordlg.cpp \
5454
GUI/drs4cfdalgorithmdlg.cpp \
5555
DQuickLTFit/settings.cpp \
56-
DQuickLTFit/projectmanager.cpp
56+
DQuickLTFit/projectmanager.cpp \
57+
UpdateNotifier/drs4updatenotifier.cpp \
58+
CPUUsage/drs4cpuusage.cpp \
59+
GUI/drs4doublespinbox.cpp \
60+
GUI/drs4spinbox.cpp
5761

5862
HEADERS += DRS/DRS.h \
5963
DRS/averager.h\
@@ -88,7 +92,11 @@ HEADERS += DRS/DRS.h \
8892
GUI/drs4calculatordlg.h \
8993
GUI/drs4cfdalgorithmdlg.h \
9094
DQuickLTFit/settings.h \
91-
DQuickLTFit/projectmanager.h
95+
DQuickLTFit/projectmanager.h \
96+
UpdateNotifier/drs4updatenotifier.h \
97+
CPUUsage/drs4cpuusage.h \
98+
GUI/drs4doublespinbox.h \
99+
GUI/drs4spinbox.h
92100

93101
FORMS += GUI/drs4scopedlg.ui \
94102
GUI/drs4addinfodlg.ui \

DLib.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
** DDRS4PALS, a software for the acquisition of lifetime spectra using the
44
** DRS4 evaluation board of PSI: https://www.psi.ch/drs/evaluation-board
55
**
6-
** Copyright (C) 2016-2019 Danny Petschke
6+
** Copyright (C) 2016-2020 Danny Petschke
77
**
88
** This program is free software: you can redistribute it and/or modify
99
** it under the terms of the GNU General Public License as published by

DLib/DGUI/horizontalrangedoubleslider.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
** DDRS4PALS, a software for the acquisition of lifetime spectra using the
44
** DRS4 evaluation board of PSI: https://www.psi.ch/drs/evaluation-board
55
**
6-
** Copyright (C) 2016-2019 Danny Petschke
6+
** Copyright (C) 2016-2020 Danny Petschke
77
**
88
** This program is free software: you can redistribute it and/or modify
99
** it under the terms of the GNU General Public License as published by

DLib/DGUI/horizontalrangedoubleslider.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
** DDRS4PALS, a software for the acquisition of lifetime spectra using the
44
** DRS4 evaluation board of PSI: https://www.psi.ch/drs/evaluation-board
55
**
6-
** Copyright (C) 2016-2019 Danny Petschke
6+
** Copyright (C) 2016-2020 Danny Petschke
77
**
88
** This program is free software: you can redistribute it and/or modify
99
** it under the terms of the GNU General Public License as published by

DLib/DGUI/mathconsoletextbox.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
** DDRS4PALS, a software for the acquisition of lifetime spectra using the
44
** DRS4 evaluation board of PSI: https://www.psi.ch/drs/evaluation-board
55
**
6-
** Copyright (C) 2016-2019 Danny Petschke
6+
** Copyright (C) 2016-2020 Danny Petschke
77
**
88
** This program is free software: you can redistribute it and/or modify
99
** it under the terms of the GNU General Public License as published by

DLib/DGUI/mathconsoletextbox.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
** DDRS4PALS, a software for the acquisition of lifetime spectra using the
44
** DRS4 evaluation board of PSI: https://www.psi.ch/drs/evaluation-board
55
**
6-
** Copyright (C) 2016-2019 Danny Petschke
6+
** Copyright (C) 2016-2020 Danny Petschke
77
**
88
** This program is free software: you can redistribute it and/or modify
99
** it under the terms of the GNU General Public License as published by

DLib/DGUI/slider.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
** DDRS4PALS, a software for the acquisition of lifetime spectra using the
44
** DRS4 evaluation board of PSI: https://www.psi.ch/drs/evaluation-board
55
**
6-
** Copyright (C) 2016-2019 Danny Petschke
6+
** Copyright (C) 2016-2020 Danny Petschke
77
**
88
** This program is free software: you can redistribute it and/or modify
99
** it under the terms of the GNU General Public License as published by

DLib/DGUI/slider.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
** DDRS4PALS, a software for the acquisition of lifetime spectra using the
44
** DRS4 evaluation board of PSI: https://www.psi.ch/drs/evaluation-board
55
**
6-
** Copyright (C) 2016-2019 Danny Petschke
6+
** Copyright (C) 2016-2020 Danny Petschke
77
**
88
** This program is free software: you can redistribute it and/or modify
99
** it under the terms of the GNU General Public License as published by

0 commit comments

Comments
 (0)