SMUCNGPerfOperator.cpp 2.37 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
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]) {
Carla Guillen Carias's avatar
Carla Guillen Carias committed
32 33 34 35
			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
36
			reading_t cpi;
37
			bool wascalced = false;
38 39 40
			if (instructions.size() > 0 && clocks.size() > 0 && calculateMetricRatio(clocks[0], instructions[0],
							outSensor->getScalingFactor(), cpi)) {
					outSensor->storeReading(cpi);
41
			}
42
		} else if (outSensor->getPosition() == _metricToPosition[SMUCSensorBase::FREQUENCY]) {
Carla Guillen Carias's avatar
Carla Guillen Carias committed
43 44 45 46
			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
47
			reading_t frequency;
48
			bool wascalced = false;
49
			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
50
					outSensor->storeReading(frequency);
51
			}
Carla Guillen Carias's avatar
Carla Guillen Carias committed
52

53
		}
Carla Guillen Carias's avatar
Carla Guillen Carias committed
54 55 56 57 58 59 60
		resetBuffers();
	}
}

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