Add process collector
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
#include <cstring>
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <set>
|
||||
#include <string>
|
||||
@@ -451,6 +452,12 @@ struct Metric {
|
||||
return *threadArenas;
|
||||
}
|
||||
|
||||
static auto &get_collectors() {
|
||||
using CollectorRegistry = std::vector<std::shared_ptr<Collector>>;
|
||||
static CollectorRegistry *collectors = new CollectorRegistry();
|
||||
return *collectors;
|
||||
}
|
||||
|
||||
// Thread cleanup for per-family thread-local storage
|
||||
struct ThreadInit {
|
||||
ArenaAllocator arena;
|
||||
@@ -1697,6 +1704,11 @@ std::span<std::string_view> render(ArenaAllocator &arena) {
|
||||
// prevents races during static member initialization at program startup
|
||||
std::unique_lock<std::mutex> _{Metric::mutex};
|
||||
|
||||
// Call all registered collectors to update their metrics
|
||||
for (const auto &collector : Metric::get_collectors()) {
|
||||
collector->collect();
|
||||
}
|
||||
|
||||
// Phase 1: Compile - generate static text and instructions
|
||||
// Safe: cached_plan access/initialization protected by mutex above
|
||||
if (!Metric::cached_plan || Metric::cached_plan->registration_version !=
|
||||
@@ -1800,4 +1812,10 @@ void reset_metrics_for_testing() {
|
||||
// when threads exit naturally
|
||||
}
|
||||
|
||||
void register_collector(std::shared_ptr<Collector> collector) {
|
||||
std::unique_lock<std::mutex> _{Metric::mutex};
|
||||
++Metric::registration_version;
|
||||
Metric::get_collectors().push_back(std::move(collector));
|
||||
}
|
||||
|
||||
} // namespace metric
|
||||
|
||||
Reference in New Issue
Block a user