Skip to content

Source · fairmq/shmem/

Manager.cxxsource

Described in Run a benchmark, Handle errors and timeouts, Test your devices, How shared memory works, Monitor and clean up, Unmanaged regions, Sessions and segments, Out-of-band buffers, Tune and debug.

fairmq/shmem/Manager.cxx63 lines · C++GitHub ↗
1/********************************************************************************2 *    Copyright (C) 2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH    *3 *                                                                              *4 *              This software is distributed under the terms of the             *5 *              GNU Lesser General Public Licence (LGPL) version 3,             *6 *                  copied verbatim in the file "LICENSE"                       *7 ********************************************************************************/8 9#include "Manager.h"10#include "TransportFactory.h"11 12// Needed to compile-firewall the <boost/process/async.hpp> header because it13// interferes with the <asio/buffer.hpp> header. So, let's factor14// the whole dependency to Boost.Process out of the header.15#ifdef FAIRMQ_BOOST_PROCESS_V1_HEADER16#include <boost/process/v1.hpp>17namespace bp = boost::process::v1;18#else19#include <boost/process.hpp>20namespace bp = boost::process;21#endif22#include <fairlogger/Logger.h>23 24namespace fair::mq::shmem {25 26bool Manager::SpawnShmMonitor(const std::string& id)27{28    auto const env(boost::this_process::environment());29    std::string const fairmq_path_key("FAIRMQ_PATH");30    std::string const shmmonitor_exe_name("fairmq-shmmonitor");31    std::string const shmmonitor_verbose_key("FAIRMQ_SHMMONITOR_VERBOSE");32    auto path(boost::this_process::path());33 34    if (env.count(fairmq_path_key)) {35        path.emplace(path.begin(), env.at(fairmq_path_key).to_string());36    }37 38    auto exe(bp::search_path(shmmonitor_exe_name, path));39    if (exe.empty()) {40        LOG(warn) << "could not find " << shmmonitor_exe_name << " in \"$" << fairmq_path_key41                  << ":$PATH\"";42        return false;43    }44 45    // TODO Move this to fairmq-shmmonitor itself ?46    bool verbose(env.count(shmmonitor_verbose_key)47                 && env.at(shmmonitor_verbose_key).to_string() == "true");48 49    bp::spawn(50        exe, "-x", "-m", "--shmid", id, "-d", "-t", "2000", (verbose ? "--verbose" : ""), env);51 52    return true;53}54 55char* GetDataAddressFromHandle(fair::mq::TransportFactory& factory, const MetaHeader& meta)56{57    if (factory.GetType() != fair::mq::Transport::SHM) {58        throw SharedMemoryError("GetDataAddressFromHandle called on a non-shmem transport");59    }60    return static_cast<TransportFactory&>(factory).GetDataAddressFromHandle(meta);61}62 63}   // namespace fair::mq::shmem