14 #include <boost/regex.hpp> 15 #include <boost/algorithm/string/trim.hpp> 16 #include <boost/filesystem.hpp> 18 #include <yaml-cpp/yaml.h> 20 #include <fmt/format.h> 24 template<
typename... Args>
25 std::runtime_error
error(
const char* fmt,
const Args& ... args)
27 return std::runtime_error(fmt::format(fmt, args...));
36 : m_config(
std::move(config))
37 , m_fdWatcher(
std::move(watcher))
40 for(
auto& launchNode :
m_config->nodes())
42 auto node = std::make_shared<NodeMonitor>(launchNode,
m_fdWatcher,
m_nh);
46 if(launchNode->required())
48 node->exitedSignal.connect(
69 std::vector<std::string> paramNames;
73 if(node->clearParams())
75 std::string paramNamespace = node->namespaceString() +
"/" + node->name() +
"/";
79 if(paramNames.empty())
82 throw error(
"Could not get list of parameters for clear_param");
85 for(
auto&
param : paramNames)
87 if(
param.substr(0, paramNamespace.length()) == paramNamespace)
141 double timeout = 0.0;
144 if(node->stopTimeout() > timeout)
145 timeout = node->stopTimeout();
156 template<
typename... Args>
161 fmt::format(fmt, std::forward<Args>(args)...)
165 template<
typename... Args>
170 fmt::format(fmt, std::forward<Args>(args)...),
181 namespace fs = boost::filesystem;
183 fs::directory_iterator it(
"/proc");
184 fs::directory_iterator end;
186 std::map<int, NodeMonitor::Ptr> nodeMap;
189 if(node->pid() != -1)
190 nodeMap[node->pid()] = node;
192 node->beginStatUpdate();
196 procInfo.second.active =
false;
198 for(; it != end; ++it)
200 fs::path statPath = (*it) /
"stat";
208 auto it = nodeMap.find(stat.
pgrp);
209 if(it == nodeMap.end())
212 auto& node = it->second;
216 auto infoIt = m_processInfos.find(stat.
pid);
217 if(infoIt == m_processInfos.end())
222 m_processInfos[stat.
pid] = info;
226 const auto& oldStat = infoIt->second.
stat;
228 node->addCPUTime(stat.
utime - oldStat.utime, stat.
stime - oldStat.stime);
231 infoIt->second.active =
true;
232 infoIt->second.stat = stat;
235 double elapsedTime = (
event.current_real -
event.last_real).toSec();
237 for(
auto& node : m_nodes)
241 for(
auto it = m_processInfos.begin(); it != m_processInfos.end();)
243 if(!it->second.active)
244 it = m_processInfos.erase(it);
ros::WallTimer m_statTimer
ROSCPP_DECL bool getParamNames(std::vector< std::string > &keys)
boost::signals2::signal< void(LogEvent)> logMessageSignal
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val)
jiffies_t stime
Total time spent in kernel space.
std::runtime_error error(const char *fmt, const Args &...args)
std::map< int, ProcessInfo > m_processInfos
process_info::ProcessStat stat
void log(const char *fmt, Args &&...args)
bool readStatFile(const char *filename, ProcessStat *stat)
SteadyTimer createSteadyTimer(WallDuration period, void(T::*callback)(const SteadyTimerEvent &), T *obj, bool oneshot=false, bool autostart=true) const
std::vector< NodeMonitor::Ptr > m_nodes
Monitor(launch::LaunchConfig::ConstPtr config, FDWatcher::Ptr watcher)
WallTimer createWallTimer(WallDuration period, void(T::*callback)(const WallTimerEvent &), T *obj, bool oneshot=false, bool autostart=true) const
void logTyped(LogEvent::Type type, const char *fmt, Args &&...args)
FDWatcher::Ptr m_fdWatcher
std::shared_ptr< const LaunchConfig > ConstPtr
ROSCPP_DECL bool del(const std::string &key)
jiffies_t utime
Total time spent in userspace.
jiffies_t kernel_hz()
Number of kernel jiffies per second.
std::size_t mem_rss
Resident memory size in bytes.
void handleRequiredNodeExit(const std::string &name)
void updateStats(const ros::WallTimerEvent &event)
launch::LaunchConfig::ConstPtr m_config
unsigned long pgrp
Process group ID.
void setParam(const std::string &key, const XmlRpc::XmlRpcValue &v) const