SMUCNGPerfOperator.cpp 2.44 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) {
Carla Guillen Carias's avatar
Carla Guillen Carias committed
12
	_buffers.resize(5);
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 clockspersecond;
37
			bool wascalced = false;
Carla Guillen Carias's avatar
Carla Guillen Carias committed
38
39
40
41
			if(instructions.size() > 0 && clocks.size() > 0) {
				if(calculateMetricRatio(clocks.begin(),instructions.begin(), outSensor->getScalingFactor(), clockspersecond)){
					outSensor->storeReading(clockspersecond);
				}
42
			}
43
		} else if (outSensor->getPosition() == _metricToPosition[SMUCSensorBase::FREQUENCY]) {
Carla Guillen Carias's avatar
Carla Guillen Carias committed
44
45
46
47
			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
48
			reading_t frequency;
49
			bool wascalced = false;
Carla Guillen Carias's avatar
Carla Guillen Carias committed
50
51
52
53
			if( clocks.size() > 0 && clocks_ref.size() > 0){
				if(calculateFrequency(clocks_ref.begin(),clocks.begin(), MIN_FREQ_MHZ, MAX_FREQ_MHZ, frequency)) {
					outSensor->storeReading(frequency);
				}
54
			}
Carla Guillen Carias's avatar
Carla Guillen Carias committed
55

56
		}
Carla Guillen Carias's avatar
Carla Guillen Carias committed
57
58
59
60
61
62
63
		resetBuffers();
	}
}

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