PerfeventConfigurator.h 2.11 KB
Newer Older
1
/*
2
 * PerfeventConfigurator.h
3
4
5
6
7
 *
 *  Created on: 13.12.2017
 *      Author: Micha Mueller
 */

8
9
#ifndef PERFEVENTCONFIGURATOR_H_
#define PERFEVENTCONFIGURATOR_H_
10

11
#include <set>
12

13
14
#include "PerfCounter.h"
#include "PerfCounterGroup.h"
15
16
#include "../../ConfiguratorTemplate.h"

17
class PerfeventConfigurator : public ConfiguratorTemplate<PerfSensorBase, PerfCounter> {
18

19
	typedef std::map<std::string, std::set<int>> templateCpuMap_t;
20
	typedef std::map<std::string, unsigned int> enumMap_t;
21

22
public:
23

24
25
	PerfeventConfigurator();
	virtual ~PerfeventConfigurator();
26

27
28
29
protected:
	bool derivedReadConfig(boost::property_tree::iptree& cfg) override;
	void derivedReReadConfig() override { _templateCpus.clear(); }
30
31
	void derivedSetGlobalSettings(const pluginSettings_t& pluginSettings) override { /*nothing to overwrite*/ }
	bool derivedReadSensorBase(PerfSensorBase& sensor, boost::property_tree::iptree& config) override;
32

33
private:
34
35
36
37
38
39
40
41
42
43
44
	/**
	 * Increase the mqtt by val means
	 * Example: increaseMqtt("003F", 1) 	returns "0040"
	 * 			increaseMqtt("003F", 15)	returns "004D"
	 *
	 * @param mqtt	The mqtt-topic to be increased
	 * @param val	The value by which the mqtt-topic should be increased
	 * @return	The increased mqtt-topic
	 */
	const std::string increaseMqtt(const std::string& mqtt, int val);

45
46
47
48
49
50
51
52
53
54
55
	/**
	 * Tries to parse the given cpuString as integer numbers. On success, the specified numbers will be inserted
	 * into a set, which will be returned. On failure, an empty set is returned. A set is used to maintain uniqueness
	 * and an ascending order among the numbers although this is not strictly required.
	 *
	 * @param cpuString	String which specifies a range and/or set of numbers (e.g. "1,2,3-5,7-9,10")
	 * @return	A set of integers as specified in the cpuString. If the string could not be parsed the set will be empty.
	 */
	std::set<int> parseCpuString(const std::string& cpuString);

	templateCpuMap_t _templateCpus;
56

57
58
	enumMap_t _enumType;
	enumMap_t _enumConfig;
59
60
};

61
extern "C" ConfiguratorInterface* create() {
62
63
64
	return new PerfeventConfigurator;
}

65
extern "C" void destroy(ConfiguratorInterface* c) {
66
67
68
	delete c;
}

69
#endif /* PERFEVENTCONFIGURATOR_H_ */