#include "hotplug.hpp" #include namespace hotplug { std::string Engine::observe(int result) const { std::ostringstream output; output << "R " << result << '\n'; for (const auto &event : ledger_.events()) { output << "E " << event.kind; output << ' ' << event.key; output << ' ' << event.cpu; output << ' ' << event.ticket; output << ' ' << event.detail << '\n'; } const auto &totals = ledger_.counters(); output << "S " << static_cast(ready_); output << ' ' << cpu_count_; output << ' ' << online_.bits(); output << ' ' << online_.count(); output << ' ' << ledger_.next_ticket(); output << ' ' << totals.attempts; output << ' ' << totals.failures; output << ' ' << totals.stops; output << ' ' << totals.registrations; output << ' ' << totals.removals; output << ' ' << totals.ups; output << ' ' << totals.downs; output << ' ' << totals.syncs; output << ' ' << states_.size() << '\n'; for (const auto &state : descriptors()) { output << "D " << state.key; output << ' ' << state.priority; output << ' ' << state.tag; output << ' ' << state.replay; output << ' ' << ledger_.cohort(state.key).bits() << '\n'; } for (int key = 1; key <= max_keys; ++key) { const auto cohort = ledger_.cohort(key); for (int cpu : cohort.ascending()) { const auto &entry = ledger_.lease(key, cpu); output << "L " << key; output << ' ' << cpu; output << ' ' << entry.ticket; output << ' ' << entry.tag << '\n'; } } for (int key = 1; key <= max_keys; ++key) { for (int cpu = 0; cpu < max_cpus; ++cpu) { const int count = ledger_.budget(key, cpu); if (count == 0) { continue; } output << "F " << key; output << ' ' << cpu; output << ' ' << count << '\n'; } } output << "END\n"; return output.str(); } }