Commit 74004fdb authored by Micha Mueller's avatar Micha Mueller
Browse files

First implementation of PerfCounter::startPolling()

Some bug-fixes and improvements
parent 7b8cced8
......@@ -45,7 +45,7 @@ private:
*/
void readCounter(PerfCounter& counter, boost::property_tree::iptree& config);
perfCounterVector_t _templateCounters;
perfCounterMap_t _templateCounters;
std::map<std::string, unsigned int> enumType;
std::map<std::string, unsigned int> enumConfig;
......
......@@ -6,9 +6,13 @@
*/
#include "MQTTPusher.h"
#include <iostream>
#include <string>
#include <unistd.h>
#include <boost/foreach.hpp>
extern volatile int keepRunning;
MQTTPusher::MQTTPusher(Configuration& cfg) :
_cfg(cfg), _connected(false) {
//print some info
......
TARGET = sysfspusher
TARGET = perfpusher
DCDBBASEPATH ?= $(realpath $(dir $(lastword $(MAKEFILE_LIST)))/..)
DCDBCOREPATH ?= $(DCDBBASEPATH)/dcdb
......
......@@ -8,17 +8,22 @@
#include "PerfCounter.h"
#include "timestamp.h"
#include <functional>
#include <sys/ioctl.h>
#include <sys/sysinfo.h>
#include <linux/perf_event.h>
#include <asm/unistd.h>
extern volatile int keepRunning;
PerfCounter::PerfCounter(const std::string name) {
_name = name;
_mqtt = "";
_minValues = 1;
_fileDescriptor = -1;
_interval = 0;
_lastValue.value = 0;
_lastValue.timestamp = 0;
_name = name;
_mqtt = "";
_minValues = 1;
_interval = 0;
_type = 0;
_config = 0;
_latestValue.value = 0;
_latestValue.timestamp = 0;
_timer = NULL;
_latestReading = 0;
......@@ -30,7 +35,9 @@ PerfCounter::~PerfCounter() {
delete _readingQueue;
_readingQueue = NULL;
}
close(fd); //TODO keep an eye here
for(int fd : _fileDescriptors) {
close(fd); //TODO keep an eye here
}
}
void PerfCounter::read() {
......@@ -51,9 +58,38 @@ void PerfCounter::readAsync() {
}
void PerfCounter::startPolling(boost::asio::io_service& io) {
if(_readingQueue == NULL) {
if (_readingQueue == NULL) {
_readingQueue = new boost::lockfree::spsc_queue<reading_t>(1024);
}
//open perf-counter for every CPU
//TODO get_nprocs best possibility?
for (int i = 0; i < get_nprocs(); i++) {
int fd;
struct perf_event_attr pe;
memset(&pe, 0, sizeof(struct perf_event_attr));
pe.type = _type;
pe.size = sizeof(struct perf_event_attr);
pe.config = _config;
pe.disabled = 1;
pe.exclude_kernel = 1;
pe.exclude_hv = 1;
//TODO set other parameters?
fd = syscall(__NR_perf_event_open, &pe, -1, i, -1, 0);
if (fd == -1) {
//TODO more meaningfull error message
std::cerr << "Error opening performance-counter" << pe.config << std::endl;
continue;
}
//TODO necessary? or just start with perf-counter enabled ( pe.disabled = 0)?
ioctl(fd, PERF_EVENT_IOC_RESET, 0);
ioctl(fd, PERF_EVENT_IOC_ENABLE, 0);
_fileDescriptors.push_back(fd);
}
//TODO open file descriptor?
_timer = new boost::asio::deadline_timer(io, boost::posix_time::seconds(0));
_timer->async_wait(std::bind(&PerfCounter::readAsync, this));
......
......@@ -9,6 +9,7 @@
#define PERFCOUNTER_H_
#include <string>
#include <vector>
#include <boost/asio.hpp>
#include <boost/lockfree/spsc_queue.hpp>
......@@ -80,9 +81,10 @@ private:
unsigned int _interval;
unsigned int _type;
unsigned int _config;
int _fileDescriptor;
reading_t _latestValue;
std::vector<int> _fileDescriptors;
boost::asio::deadline_timer* _timer;
uint64_t _latestReading;
boost::lockfree::spsc_queue<reading_t>* _readingQueue;
......
......@@ -3,6 +3,7 @@
#include <unistd.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/sysinfo.h>
#include <linux/perf_event.h>
#include <asm/unistd.h>
......@@ -21,6 +22,10 @@ main(int argc, char **argv)
long long count;
int fd;
printf("This system has %d processors configured and "
"%d processors available.\n",
get_nprocs_conf(), get_nprocs());
memset(&pe, 0, sizeof(struct perf_event_attr));
pe.type = PERF_TYPE_HARDWARE;
pe.size = sizeof(struct perf_event_attr);
......
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