-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStatReader.h
More file actions
79 lines (61 loc) · 2.61 KB
/
StatReader.h
File metadata and controls
79 lines (61 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#ifndef STATREADER_H
#define STATREADER_H
#include <thread>
#include <mutex>
#include <vector>
#include <QVector>
#include <deque>
#include <iostream>
template<typename T>
class StatReader {
public:
StatReader(std::string&& name) : m_name(name){} //!< cosntructor, intialises the class, should determine how many disk there are etc...
// virtual ~StatReader(){};
const T& getStatData(int DeviceIndex){
return m_DataVec.at(DeviceIndex);
} //!< gives a reference to the a specified device data entry
int getDeviceCount(){
return m_DataVec.size();
} //!< returns how many disks are monitored
virtual void measure_main_loop()=0; //!< collects data for all disk every 100ms, runs until m_quit ist true
void templateLoop(){
try {
measure_main_loop();
} catch (std::exception& e) {
std::cerr << "execption caught in measurment_main_loop of " <<m_name << " :" << e.what()<< std::endl;
} catch (...){
std::cerr << "unknown execption occured in measurment_main_loop of "<<m_name << std::endl;
}
}
//default filter algorhytm for all the used data
void filter_data_deque(std::deque<double>& data){
size_t k = data.size()-3;
for(int n=8; n>=0; n--){
//for(int k = +2; k < cpuYPlotData[i].size()-2; k++)
data[k] = (data[k-2] + data[k-1] + data[k] +data[k+1] +data[k+2] )/ 5.0;
k--;
}
}
void start(){
m_quit=false;
if(!m_measureT.joinable()){
m_measureT = std::thread([&](){
templateLoop();
});
}
} //!< starts the measurment thread
void stop(){ m_quit=false;} //!< stops the measurment thread
protected:
friend class LTM;
constexpr static int m_dataPointsPerMinute=600; //wir machen das abtastinterval nicht varibel, wir wollen alle 100ms eine Messung die 1 Minute ergibt
constexpr static int m_widgetDataModulus = 5;
constexpr static int m_staticDataModulus = 50;
constexpr static int m_intervallMs =100;
int m_cycleTimeMs=m_intervallMs;
QList<T> m_DataVec; //!< one element for each device monitored
std::mutex m_DataVecMutex;
bool m_quit=false; //!< once true, the measurement loop stops
std::thread m_measureT; //!< thread object that executes the measure_main_loop
const std::string m_name;
};
#endif // STATREADER_H