Skip to content
Snippets Groups Projects

Saving counters result as monitoring histogram

Merged Valerii Kholoimov requested to merge dev_kholoimov_monitoring_counters_histogram into master
2 files
+ 87
1
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -23,6 +23,9 @@
namespace Allen::Monitoring {
struct AccumulatorBase;
template<typename T>
struct Counter;
struct AccumulatorInfosAndPointers {
std::size_t offset {0};
std::size_t size {0};
@@ -30,6 +33,65 @@ namespace Allen::Monitoring {
std::vector<AccumulatorBase*> owners;
};
struct CountersHistogram {
CountersHistogram() : m_bins(2, 0)
{}
friend void reset(CountersHistogram& c)
{
std::fill(c.m_bins.begin(), c.m_bins.end(), 0.0);
c.m_totNEntries = 0.0;
}
friend void to_json(nlohmann::json& j, CountersHistogram const& h)
{
j = {{"type", "histogram:Histogram:d"},
{"title", h.m_title},
{"dimension", 1},
{"empty", h.m_totNEntries == 0},
{"nEntries", h.m_totNEntries},
{"axis",
{{
{"nBins", h.m_bins.size() - 2},
{"minValue", h.m_minValue},
{"maxValue", h.m_maxValue},
{"title", ""},
{"labels", h.m_labels}
}}},
{"bins", h.m_bins}};
}
void registerHistogram()
{
// Register CountersHistogram for Gaudi
#ifndef ALLEN_STANDALONE
Gaudi::svcLocator()->monitoringHub().registerEntity("CountersHistogram", "CountersValues", "histogram:Histogram:d", *this);
#endif
}
void addCounter(std::string label)
{
m_labels.push_back(label);
m_maxValue++;
m_bins.push_back(0);
}
void increaseBin(int bin_index, double value)
{
m_bins[bin_index + 1] = m_bins[bin_index + 1] + static_cast<int>(value);
m_totNEntries = m_totNEntries + value;
}
std::string m_title;
std::vector<int> m_bins;
int m_minValue = 0;
int m_maxValue = 0;
std::vector<std::string> m_labels;
std::string m_x_axis_label;
double m_totNEntries = 0.0;
};
struct AccumulatorManager {
static AccumulatorManager* get()
{
@@ -38,6 +100,7 @@ namespace Allen::Monitoring {
}
void registerAccumulator(AccumulatorBase* acc);
void registerCounter(Counter<unsigned>* c) {m_counters.push_back(c);}
void initAccumulators(unsigned number_of_streams);
void mergeAndReset(bool singlethreaded = false);
char* bufferForStream(unsigned stream_id) const { return m_dev_buffer_ptr[m_stream_current_buffer[stream_id]]; }
@@ -60,7 +123,10 @@ namespace Allen::Monitoring {
std::vector<unsigned> m_stream_current_buffer;
std::vector<bool> m_stream_done;
CountersHistogram m_counters_histogram;
std::vector<AccumulatorBase*> m_registered_accumulators;
std::vector<Counter<unsigned>*> m_counters;
std::map<std::string, AccumulatorInfosAndPointers> m_accumulators;
};
@@ -122,7 +188,11 @@ namespace Allen::Monitoring {
using type = T;
using DeviceType = DeviceCounter<T>;
Counter(const Allen::Algorithm* owner, std::string name) : AccumulatorBase(owner, name) {}
Counter(const Allen::Algorithm* owner, std::string name) : AccumulatorBase(owner, name)
{
if constexpr (std::is_same<T, unsigned>::value)
AccumulatorManager::get()->registerCounter(this);
}
std::size_t size() const override { return 1; }
std::size_t elementSize() const override { return sizeof(T); }
DeviceType data(const Allen::Context& ctx) const { return reinterpret_cast<T*>(currentDevicePtr(ctx.stream_id)); }
@@ -465,6 +535,7 @@ namespace Allen::Monitoring {
{"nEntries", h.m_totNEntries},
{"axis", h.axisArray()},
{"bins", h.m_bins}};
}
void registerAccumulator() override
Loading