SMUCNGPerfOperator.cpp 2.39 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
    LOG_VAR(ll) << "           No  Window:          ";
20
	OperatorTemplate<SMUCSensorBase>::printConfig(ll);
21
22
}

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