-
Notifications
You must be signed in to change notification settings - Fork 499
Expand file tree
/
Copy pathResourcesMonitoringHelper.h
More file actions
72 lines (59 loc) · 2.57 KB
/
ResourcesMonitoringHelper.h
File metadata and controls
72 lines (59 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright CERN and copyright holders of ALICE O2. This software is
// distributed under the terms of the GNU General Public License v3 (GPL
// Version 3), copied verbatim in the file "COPYING".
//
// See http://alice-o2.web.cern.ch/license for full licensing information.
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
#ifndef O2_FRAMEWORK_RESOURCESMONITORINGHELPER_H_
#define O2_FRAMEWORK_RESOURCESMONITORINGHELPER_H_
#include "Framework/DeviceMetricsInfo.h"
#include "Monitoring/ProcessMonitor.h"
#include <boost/property_tree/ptree.hpp>
#include "Framework/DeviceSpec.h"
#include <vector>
#include <type_traits>
namespace o2::framework
{
class ResourcesMonitoringHelper
{
public:
static bool dumpMetricsToJSON(const std::vector<DeviceMetricsInfo>& metrics, const std::vector<DeviceSpec>& specs) noexcept;
static bool isResourcesMonitoringEnabled(unsigned short interval) noexcept { return interval > 0; }
private:
template <typename T>
static boost::property_tree::ptree fillNodeWithValue(const DeviceMetricsInfo& deviceMetrics,
const T& metricsStorage, size_t labelIndex, size_t storageIndex);
template <typename T>
inline static T retriveValue(T val)
{
return val;
}
inline static std::string retriveValue(const std::reference_wrapper<const StringMetric> val)
{
return std::string(val.get().data);
}
ResourcesMonitoringHelper() = delete;
};
template <typename T>
boost::property_tree::ptree ResourcesMonitoringHelper::fillNodeWithValue(const DeviceMetricsInfo& deviceMetrics,
const T& metricsStorage, size_t labelIndex, size_t storageIndex)
{
unsigned int loopRange = std::min(deviceMetrics.metrics[labelIndex].filledMetrics, metricsStorage[storageIndex].size());
boost::property_tree::ptree metricNode;
for (unsigned int idx = 0; idx < loopRange; ++idx) {
boost::property_tree::ptree values;
values.add("timestamp", deviceMetrics.timestamps[labelIndex][idx]);
if constexpr (std::is_arithmetic_v<T>) {
values.add("value", std::to_string(retriveValue(std::cref(metricsStorage[storageIndex][idx]))));
} else {
values.add("value", retriveValue(std::cref(metricsStorage[storageIndex][idx])));
}
metricNode.push_back(std::make_pair("", values));
}
return metricNode;
}
} // namespace o2::framework
#endif // O2_FRAMEWORK_RESOURCESMONITORINGHELPER_H_