Commit 40a2bd54 authored by Carla Guillen's avatar Carla Guillen
Browse files

Adding copy constructor for sensorbase

parent 2bf0c81f
......@@ -75,7 +75,7 @@ void JobTSAggregatorOperator::compute(U_Ptr unit, qeJobData& jobData) {
void JobTSAggregatorOperator::compute_internal(U_Ptr unit, vector<reading_t> buffer) {
reading_t reading;
AggregatorSensorBase::aggregationOps_t op;
reading.timestamp = getTimestamp();
reading.timestamp = getTimestamp() - 10e9;
// Performing the actual aggregation operation
for(const auto& out : unit->getOutputs()) {
op = out->getOperation();
......
......@@ -44,14 +44,19 @@ void SMUCNGPerfConfigurator::sensorBase(SMUCSensorBase& s, CFG_VAL config) {
std::string name = s.getName();
if(name.compare("instructions")==0){
_metricToPosition[SMUCSensorBase::INSTRUCTIONS] = position;
s.setMetric(SMUCSensorBase::INSTRUCTIONS);
} else if(name.compare("clocks") == 0){
_metricToPosition[SMUCSensorBase::CLOCKS] = position;
s.setMetric(SMUCSensorBase::CLOCKS);
} else if(name.compare("ref_clocks") == 0){
_metricToPosition[SMUCSensorBase::CLOCKS_REF] = position;
s.setMetric(SMUCSensorBase::CLOCKS_REF);
} else if(name.compare("cpi") == 0){
_metricToPosition[SMUCSensorBase::CPI] = position;
s.setMetric(SMUCSensorBase::CPI);
} else if(name.compare("frequency") == 0){
_metricToPosition[SMUCSensorBase::FREQUENCY] = position;
s.setMetric(SMUCSensorBase::FREQUENCY);
}
} else if (boost::iequals(val.first, "scaling_factor")){
unsigned int scaling_factor = std::stoul(val.second.data());
......
......@@ -39,7 +39,7 @@ private:
void sensorBase(SMUCSensorBase& s, CFG_VAL config) override;
void operatorAttributes(SMUCNGPerfOperator& op, CFG_VAL config) override;
bool unit(UnitTemplate<SMUCSensorBase>& u) override;
std::map<SMUCSensorBase::Metrics, unsigned int> _metricToPosition;
std::map<SMUCSensorBase::Metric_t, unsigned int> _metricToPosition;
};
extern "C" OperatorConfiguratorInterface* create() {
......
......@@ -55,9 +55,19 @@ void SMUCNGPerfOperator::printConfig(LOG_LEVEL ll) {
void SMUCNGPerfOperator::compute(U_Ptr unit) {
auto inputs = unit->getInputs();
auto timestamp = getTimestamp(); //ToDo timestamp minus some time...
auto timestamp = getTimestamp() - 10e9 ; //ToDo timestamp minus some time...
if (_metricToPosition.size() <3) {
for (auto& inSensor:unit->getInputs()){
_metricToPosition[inSensor->getMetric()] = inSensor->getPosition();
}
for (auto& outSensor:unit->getOutputs()){
_metricToPosition[outSensor->getMetric()] = outSensor->getPosition();
}
}
for(auto& outSensor : unit->getOutputs()){
if( outSensor->getPosition() == _metricToPosition[SMUCSensorBase::CPI]) {
if( outSensor->getMetric() == SMUCSensorBase::CPI) {
std::cout << "CPI found!";
std::vector<reading_t> & instructions = _buffers[0];
std::vector<reading_t> & clocks = _buffers[1];
query(inputs[_metricToPosition[SMUCSensorBase::INSTRUCTIONS]]->getName(), timestamp, instructions);
......@@ -65,16 +75,17 @@ void SMUCNGPerfOperator::compute(U_Ptr unit) {
bool wascalced = false;
reading_t cpi;
if (instructions.size() > 0 && clocks.size() > 0 && calculateMetricRatio(clocks[0], instructions[0], outSensor->getScalingFactor(), cpi)) {
outSensor->storeReading(cpi);
outSensor->storeReading(cpi);
}
} else if (outSensor->getPosition() == _metricToPosition[SMUCSensorBase::FREQUENCY]) {
} else if (outSensor->getMetric() == SMUCSensorBase::FREQUENCY) {
std::cout << "Frequency found!";
std::vector<reading_t> & clocks = _buffers[0];
std::vector<reading_t> & clocks_ref = _buffers[1];
query(inputs[_metricToPosition[SMUCSensorBase::CLOCKS]]->getName(), timestamp, clocks);
query(inputs[_metricToPosition[SMUCSensorBase::CLOCKS_REF]]->getName(), timestamp, clocks_ref);
reading_t frequency;
if( clocks.size() > 0 && clocks_ref.size() > 0 && calculateFrequency(clocks_ref[0],clocks[0], MIN_FREQ_MHZ, MAX_FREQ_MHZ, frequency)) {
outSensor->storeReading(frequency);
outSensor->storeReading(frequency);
}
}
resetBuffers();
......
......@@ -34,7 +34,7 @@
class SMUCNGPerfOperator: virtual public OperatorTemplate<SMUCSensorBase>{
private:
std::map<SMUCSensorBase::Metrics, unsigned int> _metricToPosition;
std::map<SMUCSensorBase::Metric_t, unsigned int> _metricToPosition;
public:
SMUCNGPerfOperator(const std::string& name);
......@@ -43,7 +43,7 @@ public:
SMUCNGPerfOperator& operator=(const SMUCNGPerfOperator& other);
void printConfig(LOG_LEVEL ll) override;
void setMetricToPosition(const std::map<SMUCSensorBase::Metrics,unsigned int>&metricToPosition) {
void setMetricToPosition(const std::map<SMUCSensorBase::Metric_t,unsigned int>&metricToPosition) {
_metricToPosition = metricToPosition;
}
......
......@@ -32,17 +32,26 @@
class SMUCSensorBase : public SensorBase {
public:
enum Metrics {
enum Metric_t {
INSTRUCTIONS,
CLOCKS,
CLOCKS_REF,
CPI,
FREQUENCY
FREQUENCY,
NONE
};
public:
SMUCSensorBase(const std::string& name): SensorBase(name), _scaling_factor(1), _position(0) {}
SMUCSensorBase(const std::string& name): SensorBase(name), _scaling_factor(1), _position(0), _metric(NONE) {}
SMUCSensorBase(const SMUCSensorBase& other): SensorBase(other){
copy(other);
}
SMUCSensorBase& operator=(const SMUCSensorBase& other){
SensorBase::operator=(other);
copy(other);
}
virtual ~SMUCSensorBase(){}
unsigned int getScalingFactor() const {
return _scaling_factor;
}
......@@ -50,6 +59,14 @@ public:
void setScalingFactor(unsigned int scalingFactor) {
_scaling_factor = scalingFactor;
}
void setMetric(Metric_t metric){
_metric = metric;
}
Metric_t getMetric(){
return _metric;
}
unsigned int getPosition(){
return _position;
......@@ -62,6 +79,13 @@ public:
private:
unsigned int _scaling_factor;
unsigned int _position;
Metric_t _metric;
void copy(const SMUCSensorBase & other){
_scaling_factor = other._scaling_factor;
_position = other._position;
_metric = other._metric;
}
};
using SMUCNGPtr = std::shared_ptr<SMUCSensorBase>;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment