SMUCNGPerfOperator.cpp 4.18 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
//================================================================================
// Name        : SMUCNGPerfOperator.cpp
// Author      : Carla Guillen
// Contact     : info@dcdb.it
// Copyright   : Leibniz Supercomputing Centre
// Description : Template implementing features to use Units in Operators.
//================================================================================

//================================================================================
// This file is part of DCDB (DataCenter DataBase)
// Copyright (C) 2018-2019 Leibniz Supercomputing Centre
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
//================================================================================
27

Carla Guillen Carias's avatar
Carla Guillen Carias committed
28
#include "../../includes/DerivedMetrics.h"
29
#include "SMUCNGPerfOperator.h"
30

31
SMUCNGPerfOperator::SMUCNGPerfOperator(const std::string& name): OperatorTemplate(name) {
32
	_buffers.resize(10);
33 34
}

35
SMUCNGPerfOperator::~SMUCNGPerfOperator() {
36 37
}

38 39 40 41 42 43 44 45 46 47
SMUCNGPerfOperator::SMUCNGPerfOperator(const SMUCNGPerfOperator& other) : OperatorTemplate(other){
	this->_buffers = other._buffers;
}

SMUCNGPerfOperator& SMUCNGPerfOperator::operator=(const SMUCNGPerfOperator& other){
	OperatorTemplate::operator =(other);
	this->_buffers = other._buffers;
	return *this;
}

48
void SMUCNGPerfOperator::printConfig(LOG_LEVEL ll) {
49 50 51 52 53
    OperatorTemplate<SMUCSensorBase>::printConfig(ll);
    LOG_VAR(ll) << " metric to position map: ";
    for(auto &kv : _metricToPosition){
    	LOG_VAR(ll) << "Metric = " << kv.first << "Position = " << kv.second;
    }
54 55
}

56
void SMUCNGPerfOperator::compute(U_Ptr unit) {
57
	auto inputs = unit->getInputs();
58 59 60 61 62 63 64 65 66 67
	auto timestamp = getTimestamp() - 10e9 ; //ToDo timestamp minus some time...
	if (_metricToPosition.size() <3) {
		for (auto& inSensor:unit->getInputs()){
			_metricToPosition[inSensor->getMetric()] = inSensor->getPosition();	
		}
		for (auto& outSensor:unit->getOutputs()){
			_metricToPosition[outSensor->getMetric()] = outSensor->getPosition();	
		}
	}

68
	for(auto& outSensor : unit->getOutputs()){
69 70
		if( outSensor->getMetric() == SMUCSensorBase::CPI) {
			std::cout << "CPI found!";
Carla Guillen Carias's avatar
Carla Guillen Carias committed
71 72
			std::vector<reading_t> & instructions = _buffers[0];
			std::vector<reading_t> & clocks = _buffers[1];
73 74
			query(inputs[_metricToPosition[SMUCSensorBase::INSTRUCTIONS]]->getName(), timestamp, instructions);
			query(inputs[_metricToPosition[SMUCSensorBase::CLOCKS]]->getName(), timestamp, clocks);
75
			bool wascalced = false;
76
			reading_t cpi;
77
			if (instructions.size() > 0 && clocks.size() > 0 && calculateMetricRatio(clocks[0], instructions[0], outSensor->getScalingFactor(), cpi)) {
78
				outSensor->storeReading(cpi);
79
			}
80 81
		} else if (outSensor->getMetric() == SMUCSensorBase::FREQUENCY) {
			std::cout << "Frequency found!";
Carla Guillen Carias's avatar
Carla Guillen Carias committed
82 83
			std::vector<reading_t> & clocks = _buffers[0];
			std::vector<reading_t> & clocks_ref = _buffers[1];
84 85
			query(inputs[_metricToPosition[SMUCSensorBase::CLOCKS]]->getName(), timestamp, clocks);
			query(inputs[_metricToPosition[SMUCSensorBase::CLOCKS_REF]]->getName(), timestamp, clocks_ref);
86
			reading_t frequency;
87
			if( clocks.size() > 0 && clocks_ref.size() > 0 && calculateFrequency(clocks_ref[0],clocks[0], MIN_FREQ_MHZ, MAX_FREQ_MHZ, frequency)) {
88
				outSensor->storeReading(frequency);
89 90
			}
		}
Carla Guillen Carias's avatar
Carla Guillen Carias committed
91 92 93 94
		resetBuffers();
	}
}

Carla Guillen's avatar
Carla Guillen committed
95
void SMUCNGPerfOperator::query(const std::string & sensor_name, const uint64_t timestamp, vector<reading_t> &buffer){
96 97 98
	_queryEngine.querySensor(sensor_name, timestamp, timestamp, buffer, false); //use absolute timestamp and always false
}

Carla Guillen Carias's avatar
Carla Guillen Carias committed
99 100 101
void SMUCNGPerfOperator::resetBuffers(){
	for(auto &buffer: _buffers){
		buffer.clear();
102 103
	}
}