This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
#include <type_traits>
|
||||
@@ -113,7 +114,7 @@ public:
|
||||
web_debug_port_,
|
||||
[this]() {
|
||||
auto s = collect_snapshots();
|
||||
return web_debug::to_json(s.nodes, s.channels, s.elapsed_s);
|
||||
return web_debug::to_json(s.nodes, s.channels, s.resources, s.elapsed_s);
|
||||
});
|
||||
web_server_->start();
|
||||
std::cerr << "[kpn] web debug UI: http://localhost:" << web_debug_port_ << "\n";
|
||||
@@ -143,6 +144,12 @@ public:
|
||||
void set_web_debug_port(uint16_t port) { web_debug_port_ = port; }
|
||||
#endif
|
||||
|
||||
// Register a shared resource so it appears in diagnostics and the debug UI.
|
||||
// The probe must outlive this network (typically the resource is on the same stack).
|
||||
void register_resource(const std::string& name, IResourceProbe* probe) {
|
||||
resource_probes_.emplace_back(name, probe);
|
||||
}
|
||||
|
||||
// Print diagnostics using compile-time node labels
|
||||
void print_diagnostics(std::ostream& os = std::cerr) const {
|
||||
os << "\n┌─ KPN++ StaticNetwork diagnostics ─────────────────────────────\n";
|
||||
@@ -159,9 +166,10 @@ public:
|
||||
|
||||
private:
|
||||
struct Snapshots {
|
||||
std::vector<NodeSnapshot> nodes;
|
||||
std::vector<ChannelSnapshot> channels;
|
||||
double elapsed_s;
|
||||
std::vector<NodeSnapshot> nodes;
|
||||
std::vector<ChannelSnapshot> channels;
|
||||
std::vector<ResourceSnapshot> resources;
|
||||
double elapsed_s;
|
||||
};
|
||||
|
||||
Snapshots collect_snapshots() const {
|
||||
@@ -178,7 +186,11 @@ private:
|
||||
for (auto& probe : channel_probes_)
|
||||
channels.push_back(probe->snapshot());
|
||||
|
||||
return {std::move(nodes), std::move(channels), elapsed_s};
|
||||
std::vector<ResourceSnapshot> resources;
|
||||
for (auto& [name, probe] : resource_probes_)
|
||||
resources.push_back(probe->snapshot(name));
|
||||
|
||||
return {std::move(nodes), std::move(channels), std::move(resources), elapsed_s};
|
||||
}
|
||||
|
||||
std::string name_;
|
||||
@@ -189,6 +201,7 @@ private:
|
||||
std::vector<std::string> user_node_names_;
|
||||
std::vector<std::string> fanout_node_names_;
|
||||
std::vector<std::unique_ptr<IChannelProbe>> channel_probes_;
|
||||
std::vector<std::pair<std::string, IResourceProbe*>> resource_probes_;
|
||||
clock_t::time_point start_time_;
|
||||
#ifdef KPN_WEB_DEBUG
|
||||
uint16_t web_debug_port_{9090};
|
||||
|
||||
Reference in New Issue
Block a user