//================================================================================ // Name : CaliperSensorGroup.h // Author : Micha Mueller // Contact : info@dcdb.it // Copyright : Leibniz Supercomputing Centre // Description : Header file for Caliper sensor group class. //================================================================================ //================================================================================ // 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 CALIPER_CALIPERSENSORGROUP_H_ #define CALIPER_CALIPERSENSORGROUP_H_ #include "../../includes/SensorGroupTemplate.h" #include "CaliperSensorBase.h" #include #include #include /** * @brief SensorGroupTemplate specialization for this plugin. * * @ingroup caliper */ class CaliperSensorGroup : public SensorGroupTemplate { /******************************************************************************* * Keep in sync with DcdbPusher Caliper service ******************************************************************************/ #define SHM_MAX_RETRIES 5 #define MAX_SYMBOL_SIZE 512 #define MAX_PATH_SIZE 4096 #define MSGQ_SIZE 8192 #define STR_PREFIX "/cali_dcdb_" #define SHM_SIZE (32*1024*1024) typedef struct { uintptr_t pc; uint64_t ts; unsigned short cpu; } snap_data; /* Entry for an executable symbol in the symbol table */ typedef struct { uintptr_t start_addr; uintptr_t end_addr; char name[MAX_SYMBOL_SIZE]; } fsym_data; /* Defines a contiguous executable memory block */ typedef struct { uintptr_t start_addr; uintptr_t end_addr; uintptr_t offset; // offset as parsed from /proc//maps size_t fsym_offset; // Offset in bytes from the address of this struct // to the beginning of the associated symbol section size_t fsym_count; // Number of symbols in this address range char pathname[MAX_PATH_SIZE]; // Filepath + name of the binary where // this memory range comes from or // "[Anonymous]" if unknown } addr_data; /* * Layout of shared-memory file used to communicate with Caliper service: * * //Communication queue, aka ring buffer: * size_t r_index //points to the last read element * size_t w_index //points to the last written element * sem_t r_sem; * sem_t w_sem; * snap_data[MSGQ_SIZE] * * //symbol lookup data * size_t addr_count * addr_data[addr_count] * addr_count * (fsym_data[addr_data.fsym_count]) */ static constexpr size_t lookup_data_offset = 2*sizeof(size_t) + 2*sizeof(sem_t) + MSGQ_SIZE*sizeof(snap_data); public: CaliperSensorGroup(const std::string& name); CaliperSensorGroup(const CaliperSensorGroup& other); virtual ~CaliperSensorGroup(); CaliperSensorGroup& operator=(const CaliperSensorGroup& other); bool execOnStart() final override; void execOnStop() final override; std::vector& acquireSensors() final override { while (_lock.test_and_set(std::memory_order_acquire)) {} return _baseSensors; } void releaseSensors() final override { _lock.clear(std::memory_order_release); } void printGroupConfig(LOG_LEVEL ll) final override; void setGlobalMqttPrefix(const std::string& prefix) { _globalMqttPrefix = prefix; } private: void read() final override; int _socket; int _connection; void* _shm; int _shmFile; size_t _shmFailCnt; std::string _globalMqttPrefix; std::atomic_flag _lock; ///< Lock to synchronize access to associated sensors //TODO aggregate sensor values: store pair of S_Ptr and counter. Only push values at end of iteration std::unordered_map _sensorIndex; ///< Additional sensor storage for fast lookup }; #endif /* CALIPER_CALIPERSENSORGROUP_H_ */