Skip to content

Commit

Permalink
Merge pull request #10 from dpscience/dpscience-local
Browse files Browse the repository at this point in the history
preparing release v1.11
  • Loading branch information
dpscience authored Apr 16, 2020
2 parents 52219aa + f13b4c6 commit 3b5ef20
Show file tree
Hide file tree
Showing 105 changed files with 7,968 additions and 5,582 deletions.
141 changes: 141 additions & 0 deletions CPUUsage/drs4cpuusage.cpp
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);
}
78 changes: 78 additions & 0 deletions CPUUsage/drs4cpuusage.h
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
16 changes: 12 additions & 4 deletions DDRS4PALS.pro
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
#
#-------------------------------------------------

QT += core gui concurrent script printsupport
QT += core gui concurrent script printsupport network

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = DDRS4PALS_1_0_10
TARGET = DDRS4PALS_1_0_11
TEMPLATE = app

RC_FILE = softwareIcon.rc
Expand Down Expand Up @@ -53,7 +53,11 @@ SOURCES += main.cpp\
GUI/drs4calculatordlg.cpp \
GUI/drs4cfdalgorithmdlg.cpp \
DQuickLTFit/settings.cpp \
DQuickLTFit/projectmanager.cpp
DQuickLTFit/projectmanager.cpp \
UpdateNotifier/drs4updatenotifier.cpp \
CPUUsage/drs4cpuusage.cpp \
GUI/drs4doublespinbox.cpp \
GUI/drs4spinbox.cpp

HEADERS += DRS/DRS.h \
DRS/averager.h\
Expand Down Expand Up @@ -88,7 +92,11 @@ HEADERS += DRS/DRS.h \
GUI/drs4calculatordlg.h \
GUI/drs4cfdalgorithmdlg.h \
DQuickLTFit/settings.h \
DQuickLTFit/projectmanager.h
DQuickLTFit/projectmanager.h \
UpdateNotifier/drs4updatenotifier.h \
CPUUsage/drs4cpuusage.h \
GUI/drs4doublespinbox.h \
GUI/drs4spinbox.h

FORMS += GUI/drs4scopedlg.ui \
GUI/drs4addinfodlg.ui \
Expand Down
2 changes: 1 addition & 1 deletion DLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
** 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-2019 Danny Petschke
** 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
Expand Down
2 changes: 1 addition & 1 deletion DLib/DGUI/horizontalrangedoubleslider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
** 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-2019 Danny Petschke
** 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
Expand Down
2 changes: 1 addition & 1 deletion DLib/DGUI/horizontalrangedoubleslider.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
** 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-2019 Danny Petschke
** 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
Expand Down
2 changes: 1 addition & 1 deletion DLib/DGUI/mathconsoletextbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
** 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-2019 Danny Petschke
** 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
Expand Down
2 changes: 1 addition & 1 deletion DLib/DGUI/mathconsoletextbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
** 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-2019 Danny Petschke
** 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
Expand Down
2 changes: 1 addition & 1 deletion DLib/DGUI/slider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
** 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-2019 Danny Petschke
** 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
Expand Down
2 changes: 1 addition & 1 deletion DLib/DGUI/slider.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
** 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-2019 Danny Petschke
** 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
Expand Down
2 changes: 1 addition & 1 deletion DLib/DGUI/svgbutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
** 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-2019 Danny Petschke
** 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
Expand Down
2 changes: 1 addition & 1 deletion DLib/DGUI/svgbutton.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
** 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-2019 Danny Petschke
** 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
Expand Down
2 changes: 1 addition & 1 deletion DLib/DGUI/verticalrangedoubleslider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
** 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-2019 Danny Petschke
** 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
Expand Down
2 changes: 1 addition & 1 deletion DLib/DGUI/verticalrangedoubleslider.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
** 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-2019 Danny Petschke
** 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
Expand Down
2 changes: 1 addition & 1 deletion DLib/DMath/constantexplanations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
** 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-2019 Danny Petschke
** 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
Expand Down
2 changes: 1 addition & 1 deletion DLib/DMath/constantexplanations.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
** 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-2019 Danny Petschke
** 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
Expand Down
2 changes: 1 addition & 1 deletion DLib/DPlot/plot2DXAxis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
** 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-2019 Danny Petschke
** 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
Expand Down
2 changes: 1 addition & 1 deletion DLib/DPlot/plot2DXAxis.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
** 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-2019 Danny Petschke
** 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
Expand Down
Loading

0 comments on commit 3b5ef20

Please sign in to comment.