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

8
#include "../../commonderivedmetrics/DerivedMetrics.h"
9
#include "SMUCNGPerfOperator.h"
10

11
SMUCNGPerfOperator::SMUCNGPerfOperator(const std::string& name): OperatorTemplate(name) {
12 13 14

}

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

18
void SMUCNGPerfOperator::printConfig(LOG_LEVEL ll) {
19 20 21 22 23
    OperatorTemplate<SMUCSensorBase>::printConfig(ll);
    LOG_VAR(ll) << " metric to position map: ";
    for(auto &kv : _metricToPosition){
    	LOG_VAR(ll) << "Metric = " << kv.first << "Position = " << kv.second;
    }
24 25
}

26
void SMUCNGPerfOperator::compute(U_Ptr unit) {
27 28
	auto inputs = unit->getInputs();
	auto timestamp = getTimestamp(); //ToDo timestamp minus some time...
29 30
	auto outputs = unit->getOutputs();
	for(auto& outSensor : outputs){
31
		if( outSensor->getPosition() == _metricToPosition[SMUCSensorBase::CPI]) {
32 33 34 35 36
			vector<reading_t> * bufferInstructions = nullptr;
			bufferInstructions = _queryEngine.querySensor(inputs[_metricToPosition[SMUCSensorBase::INSTRUCTIONS]]->getName(), timestamp, timestamp, bufferInstructions, false); //use absolute timestamp
			vector<reading_t> * bufferClocks = nullptr;
			bufferClocks =	_queryEngine.querySensor(inputs[_metricToPosition[SMUCSensorBase::CLOCKS]]->getName(), timestamp, timestamp, bufferClocks, false); //use absolute timestamp
			reading_t clockspersecond;
37 38 39 40
			bool wascalced = false;
			if(bufferInstructions != nullptr && bufferClocks != nullptr && bufferInstructions->size() > 0 && bufferClocks->size() > 0) {
				wascalced = calculateMetricRatio(*(bufferClocks->begin()),*(bufferInstructions->begin()), outSensor->getScalingFactor(), clockspersecond);
			}
41 42 43 44 45
			delete bufferInstructions;
			delete bufferClocks;
			if(wascalced) {
				outSensor->storeReading(clockspersecond);
			}
46
		} else if (outSensor->getPosition() == _metricToPosition[SMUCSensorBase::FREQUENCY]) {
47 48 49
			const unsigned int MAX_FREQ_MHZ = 2700;
			const unsigned int MIN_FREQ_MHZ = 1200;
			vector<reading_t> * bufferClocks = nullptr;
Carla Guillen Carias's avatar
Carla Guillen Carias committed
50
			bufferClocks = _queryEngine.querySensor(inputs[_metricToPosition[SMUCSensorBase::CLOCKS]]->getName(), timestamp, timestamp, bufferClocks, false); //use absolute timestamp
51
			vector<reading_t> * bufferClockRef = nullptr;
52
			bufferClockRef = _queryEngine.querySensor(inputs[_metricToPosition[SMUCSensorBase::CLOCKS_REF]]->getName(), timestamp, timestamp, bufferClockRef, false); //use absolute timestamp
53
			reading_t frequency;
54 55 56 57
			bool wascalced = false;
			if( bufferClocks != nullptr && bufferClockRef != nullptr && bufferClocks->size() > 0 && bufferClockRef->size() > 0){
				wascalced = calculateFrequency(*(bufferClockRef->begin()),*(bufferClocks->begin()), MIN_FREQ_MHZ, MAX_FREQ_MHZ, frequency);
			}
58 59 60 61 62 63
			delete bufferClocks;
			delete bufferClockRef;
			if(wascalced) {
				outSensor->storeReading(frequency);
			}
		}
64 65
	}
}