SMUCNGPerfOperator.cpp 2.68 KB
Newer Older
1
/*
2
 * SMUCNGPerfOperator.cpp
3 4 5 6 7
 *
 *  Created on: Jul 20, 2019
 *      Author: carla
 */

Carla Guillen Carias's avatar
Carla Guillen Carias committed
8
#include "../../includes/DerivedMetrics.h"
9
#include "SMUCNGPerfOperator.h"
10

11
SMUCNGPerfOperator::SMUCNGPerfOperator(const std::string& name): OperatorTemplate(name) {
12
	_buffers.resize(10);
13 14
}

15
SMUCNGPerfOperator::~SMUCNGPerfOperator() {
16 17
}

18 19 20 21 22 23 24 25 26 27
SMUCNGPerfOperator::SMUCNGPerfOperator(const SMUCNGPerfOperator& other) : OperatorTemplate(other){
	this->_buffers = other._buffers;
}

SMUCNGPerfOperator& SMUCNGPerfOperator::operator=(const SMUCNGPerfOperator& other){
	OperatorTemplate::operator =(other);
	this->_buffers = other._buffers;
	return *this;
}

28
void SMUCNGPerfOperator::printConfig(LOG_LEVEL ll) {
29 30 31 32 33
    OperatorTemplate<SMUCSensorBase>::printConfig(ll);
    LOG_VAR(ll) << " metric to position map: ";
    for(auto &kv : _metricToPosition){
    	LOG_VAR(ll) << "Metric = " << kv.first << "Position = " << kv.second;
    }
34 35
}

36
void SMUCNGPerfOperator::compute(U_Ptr unit) {
37 38
	auto inputs = unit->getInputs();
	auto timestamp = getTimestamp(); //ToDo timestamp minus some time...
39 40
	auto outputs = unit->getOutputs();
	for(auto& outSensor : outputs){
41
		if( outSensor->getPosition() == _metricToPosition[SMUCSensorBase::CPI]) {
Carla Guillen Carias's avatar
Carla Guillen Carias committed
42 43 44 45
			std::vector<reading_t> & instructions = _buffers[0];
			std::vector<reading_t> & clocks = _buffers[1];
			_queryEngine.querySensor(inputs[_metricToPosition[SMUCSensorBase::INSTRUCTIONS]]->getName(), timestamp, timestamp, &instructions, false); //use absolute timestamp
			_queryEngine.querySensor(inputs[_metricToPosition[SMUCSensorBase::CLOCKS]]->getName(), timestamp, timestamp, &clocks, false); //use absolute timestamp
46
			reading_t cpi;
47
			bool wascalced = false;
48 49 50
			if (instructions.size() > 0 && clocks.size() > 0 && calculateMetricRatio(clocks[0], instructions[0],
							outSensor->getScalingFactor(), cpi)) {
					outSensor->storeReading(cpi);
51
			}
52
		} else if (outSensor->getPosition() == _metricToPosition[SMUCSensorBase::FREQUENCY]) {
Carla Guillen Carias's avatar
Carla Guillen Carias committed
53 54 55 56
			std::vector<reading_t> & clocks = _buffers[0];
			std::vector<reading_t> & clocks_ref = _buffers[1];
			_queryEngine.querySensor(inputs[_metricToPosition[SMUCSensorBase::CLOCKS]]->getName(), timestamp, timestamp, &clocks, false); //use absolute timestamp
			_queryEngine.querySensor(inputs[_metricToPosition[SMUCSensorBase::CLOCKS_REF]]->getName(), timestamp, timestamp, &clocks_ref, false); //use absolute timestamp
57
			reading_t frequency;
58
			bool wascalced = false;
59
			if( clocks.size() > 0 && clocks_ref.size() > 0 && calculateFrequency(clocks_ref[0],clocks[0], MIN_FREQ_MHZ, MAX_FREQ_MHZ, frequency)) {
Carla Guillen Carias's avatar
Carla Guillen Carias committed
60
					outSensor->storeReading(frequency);
61
			}
Carla Guillen Carias's avatar
Carla Guillen Carias committed
62

63
		}
Carla Guillen Carias's avatar
Carla Guillen Carias committed
64 65 66 67 68 69 70
		resetBuffers();
	}
}

void SMUCNGPerfOperator::resetBuffers(){
	for(auto &buffer: _buffers){
		buffer.clear();
71 72
	}
}