Commit 1f28de13 authored by lu43jih's avatar lu43jih
Browse files

Outdated code which will not be used

parent fb1037d1
//================================================================================
// Name : TimestampDatabase.cpp
// Author : Carla Guillen
// Contact : info@dcdb.it
// Copyright : Leibniz Supercomputing Centre
// Description :
//================================================================================
//================================================================================
// This file is part of DCDB (DataCenter DataBase)
// Copyright (C) 2019-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.
//================================================================================
#include "TimestampDatabase.h"
JobMetrics::JobMetrics(unsigned int job_id, const std::string& user, uint64_t start_time, uint64_t batch_domain) :
_job_id(job_id), _user(user), _start_time(start_time), _batch_domain(batch_domain) {
}
void JobMetrics::addMetric(const Domain_t& domain_id, const std::string &metric, int64_t val, uint64_t interval) {
std::map<Domain_t, MetricValueMap_t>::iterator foundit = _metricData.find(domain_id);
if(foundit != _metricData.end()){
foundit->second[metric] = val;
} else {
MetricValueMap_t myMap;
value_t measurement;
measurement.value = val;
measurement.interval = interval;
myMap[metric] = val;
_metricData[domain_id] = std::move(myMap);
}
}
void JobMetrics::eraseMetric(const Domain_t& domain_id, const std::string &metric) {
std::map<Domain_t, MetricValueMap_t>::iterator foundit = _metricData.find(domain_id);
if(foundit != _metricData.end()){
foundit->second.erase(metric);
if(foundit->second.size() == 0){
_metricData.erase(domain_id);
}
} //else nothing to erase..
}
bool JobMetrics::getMetric(const Domain_t& domain_id, const std::string& metric, int64_t& val, uint64_t &interval) {
std::map<Domain_t, MetricValueMap_t>::iterator fIt = _metricData.find(domain_id);
if(fIt == _metricData.end()) {
return false;
}
MetricValueMap_t::iterator foundMetric = fIt->second.find(metric);
if(foundMetric == fIt->second.end()){
return false;
}
val=foundMetric->second.value;
interval = foundMetric->second.interval;
return true;
}
TimestampDatabase::TimestampDatabase(uint64_t timestamp): _timestamp(timestamp) {
}
TimestampDatabase::~TimestampDatabase() {
_jobs.clear();
}
//================================================================================
// Name : TimestampDatabase.h
// Author : Carla Guillen
// Contact : info@dcdb.it
// Copyright : Leibniz Supercomputing Centre
// Description :
//================================================================================
//================================================================================
// This file is part of DCDB (DataCenter DataBase)
// Copyright (C) 2019-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.
//================================================================================
#ifndef TIMESTAMPDATABASE_H_
#define TIMESTAMPDATABASE_H_
#include <stdint.h>
#include <string>
#include <vector>
#include <map>
typedef struct {
int64_t value;
uint64_t interval; // time value was measured, 0 if it is a snapshot metric (i.e. Memory Used, Power)
} value_t;
using MetricValueMap_t = std::map<std::string, value_t>;
using Domain_t = std::string;
class JobMetrics {
public:
JobMetrics(unsigned int job_id, const std::string& user, uint64_t start_time, uint64_t batch_domain);
void addMetric(const Domain_t& domain_id, const std::string &metric, int64_t val, uint64_t interval);
void eraseMetric(const Domain_t& domain_id, const std::string &metric);
bool getMetric(const Domain_t& domain_id, const std::string& metric, int64_t& val, uint64_t &interval);
const std::map<Domain_t, MetricValueMap_t>& getMetricData() const {
return _metricData;
}
private:
unsigned int _job_id; //!< SLURM id without the period '.' nor step id.
std::string _user;
uint64_t _start_time;
unsigned int _batch_domain;
std::map<Domain_t, MetricValueMap_t> _metricData; //!< domain - metric id - value map
};
class TimestampDatabase {
private:
uint64_t _timestamp;
std::vector<JobMetrics> _jobs;
public:
TimestampDatabase(uint64_t timestamp);
virtual ~TimestampDatabase();
void addJobMetrics(JobMetrics js) {
_jobs.push_back(js);
}
const std::vector<JobMetrics> & getJobs() const{
return _jobs;
}
};
#endif /* TIMESTAMPDATABASE_H_ */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment