PerfeventConfigurator.h 2.55 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
12
13
#include "PerfCounter.h"
#include "../../Configurator.h"
#include <string>
14
15
#include <vector>
#include <map>
16
#include <set>
17
18
#include <boost/property_tree/ptree.hpp>

19
class PerfeventConfigurator : public Configurator<PerfCounter> {
20

21
	typedef std::map<std::string, PerfCounter> counterMap_t;
22
	typedef std::map<std::string, std::set<int>> templateCpuMap_t;
23
	typedef std::map<std::string, unsigned int> enumMap_t;
24

25
public:
26

27
28
	PerfeventConfigurator();
	virtual ~PerfeventConfigurator();
29
30
31

	/**
	 * Read the configuration for perfpusher.
32
	 * @param cfgPath	Path + name of the configuration file
33
	 * @return		true on success, false otherwise
34
	 */
35
	bool readConfig(std::string cfgPath);
36

37
38
39
40
41
42
43
	//Overwrite from Configurator
	bool reReadConfig() {
		_templateCounters.clear();
		_templateCpus.clear();
		return Configurator::reReadConfig();
	}

44
45
46
47
48
private:
	/**
	 * Set the variables of counter according to the values specified in config.
	 * @param counter	The counter to be configured
	 * @param config	A property(sub)tree containing the values
49
	 * @return	true on success, false if a required value could not be parsed
50
	 */
51
	bool readCounter(PerfCounter& counter, boost::property_tree::iptree& config);
52

53
54
55
56
57
58
59
60
61
62
63
	/**
	 * 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);

64
65
66
67
68
69
70
71
72
73
	/**
	 * 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);

74
	counterMap_t _templateCounters;
75
	templateCpuMap_t _templateCpus;
76

77
78
	enumMap_t _enumType;
	enumMap_t _enumConfig;
79
80
};

81
82
83
84
85
86
87
88
extern "C" Configurator* create() {
	return new PerfeventConfigurator;
}

extern "C" void destroy(Configurator* c) {
	delete c;
}

89
#endif /* PERFEVENTCONFIGURATOR_H_ */