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

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

11
SMUCNGPerfAnalyzer::SMUCNGPerfAnalyzer(const std::string& name): AnalyzerTemplate(name) {
12
13
14
15
16
17

}

SMUCNGPerfAnalyzer::~SMUCNGPerfAnalyzer() {
}

18
19
20
void SMUCNGPerfAnalyzer::printConfig(LOG_LEVEL ll) {
    LOG_VAR(ll) << "           No  Window:          ";
    AnalyzerTemplate<SMUCSensorBase>::printConfig(ll);
21
22
23
24
25
}

void SMUCNGPerfAnalyzer::compute(U_Ptr unit) {
	auto inputs = unit->getInputs();
	auto timestamp = getTimestamp(); //ToDo timestamp minus some time...
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
	auto outputs = unit->getOutputs();
	for(auto& outSensor : outputs){
		if(outSensor->getName().find('cpi') != std::string::npos){
			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);
			}
		} else if(outSensor->getName().find('frequency') != std::string::npos){
			const unsigned int MAX_FREQ_MHZ = 2700;
			const unsigned int MIN_FREQ_MHZ = 1200;
			vector<reading_t> * bufferClocks = nullptr;
			bufferClocks = _queryEngine.querySensor(inputs[_metricToPosition[SMUCSensorBase::INSTRUCTIONS]]->getName(), timestamp, timestamp, bufferClocks, false); //use absolute timestamp
			vector<reading_t> * bufferClockRef = nullptr;
			bufferClockRef =	_queryEngine.querySensor(inputs[_metricToPosition[SMUCSensorBase::CLOCKS]]->getName(), timestamp, timestamp, bufferClockRef, false); //use absolute timestamp
			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
	}
}