PerfSensorBase.h 3.37 KB
Newer Older
1
2
3
//================================================================================
// Name        : PerfSensorBase.h
// Author      : Micha Mueller
Micha Müller's avatar
Micha Müller committed
4
// Contact     : info@dcdb.it
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// Copyright   : Leibniz Supercomputing Centre
// Description : Sensor base class for Perfevent plugin.
//================================================================================

//================================================================================
// 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

28
29
30
31
32
33
34
/**
 * @defgroup perf Perf plugin
 * @ingroup  pusherplugins
 *
 * @brief Collect data from a CPU's performance (perf) counters.
 */

35
36
37
#ifndef PERFEVENT_PERFSENSORBASE_H_
#define PERFEVENT_PERFSENSORBASE_H_

38
#include "sensorbase.h"
39
40
#include <limits.h>

41
42
43
44
45
/**
 * @brief SensorBase specialization for this plugin.
 *
 * @ingroup perf
 */
46
class PerfSensorBase : public SensorBase {
47
      public:
48
	static constexpr uint64_t MAXCOUNTERVALUE = LLONG_MAX; //ToDo check if it is not LLONG_MAX, or make it configurable!
49

50
51
52
53
54
55
56
57
58
	PerfSensorBase(const std::string &name)
	    : SensorBase(name),
	      _type(0),
	      _config(0),
	      _cpu(-1),
	      _fd(-1),
	      _id(0) {
		//default delta to true, as perfevent has only monotonic sensors usually
		_delta = true;
59
		_deltaMax = MAXCOUNTERVALUE;
60
	}
61

62
63
64
65
66
67
68
	PerfSensorBase(const PerfSensorBase &other)
	    : SensorBase(other),
	      _type(other._type),
	      _config(other._config),
	      _cpu(other._cpu),
	      _fd(-1),
	      _id(0) {}
69

70
71
	virtual ~PerfSensorBase() {}

72
73
74
75
76
77
78
	PerfSensorBase &operator=(const PerfSensorBase &other) {
		SensorBase::operator=(other);
		_type = other._type;
		_config = other._config;
		_cpu = other._cpu;
		_fd = -1;
		_id = 0;
79

80
		return *this;
81
82
	}

83
84
85
86
87
	unsigned getType() const { return _type; }
	unsigned getConfig() const { return _config; }
	int      getCpu() const { return _cpu; }
	int      getFd() const { return _fd; }
	uint64_t getId() const { return _id; }
88

89
90
91
92
93
	void setType(unsigned type) { _type = type; }
	void setConfig(unsigned config) { _config = config; }
	void setCpu(int cpu) { _cpu = cpu; }
	void setFd(int fd) { _fd = fd; }
	void setId(uint64_t id) { _id = id; }
94

95
	void printConfig(LOG_LEVEL ll, LOGGER &lg, unsigned leadingSpaces = 16) {
96
		std::string leading(leadingSpaces, ' ');
97
98
99
100
		LOG_VAR(ll) << leading << "    Type:   " << _type;
		LOG_VAR(ll) << leading << "    Config: " << _config;
		LOG_VAR(ll) << leading << "    CPU:    " << _cpu;
	}
101

102
      protected:
103
104
	unsigned int _type;
	unsigned int _config;
105
106
107
	int          _cpu;
	int          _fd;
	uint64_t     _id;
108
109
110
};

#endif /* PERFEVENT_PERFSENSORBASE_H_ */