25#pragma GCC diagnostic push
26#pragma GCC diagnostic ignored "-Wcovered-switch-default"
28#include <nlohmann/json.hpp>
30#pragma GCC diagnostic pop
42int main(
int argc,
const char *argv[]) {
44 cli.description(
"Query an ESI system for information from the manifest.");
46 CLI::App *versionSub =
47 cli.add_subcommand(
"version",
"Print ESI system version");
48 bool infoDetails =
false;
50 cli.add_subcommand(
"info",
"Print ESI system information");
51 infoSub->add_flag(
"--details", infoDetails,
52 "Print detailed information about the system");
53 bool hierDetails =
false;
54 CLI::App *hierSub = cli.add_subcommand(
"hier",
"Print ESI system hierarchy");
55 hierSub->add_flag(
"--details", hierDetails,
56 "Print detailed information about the system");
57 bool telemetryJson =
false;
58 CLI::App *telemetrySub =
59 cli.add_subcommand(
"telemetry",
"Print ESI system telemetry information");
60 telemetrySub->add_flag(
"--json", telemetryJson,
61 "Dump telemetry information as JSON");
63 if (
int rc = cli.
esiParse(argc, argv))
65 if (!cli.get_help_ptr()->empty())
74 std::cout << info.getEsiVersion() << std::endl;
79 else if (*telemetrySub) {
86 }
catch (std::exception &e) {
93 std::string jsonManifest =
96 os <<
"API version: " << m.
getApiVersion() << std::endl << std::endl;
97 os <<
"********************************" << std::endl;
98 os <<
"* Module information" << std::endl;
99 os <<
"********************************" << std::endl;
108 os <<
"********************************" << std::endl;
109 os <<
"* Type table" << std::endl;
110 os <<
"********************************" << std::endl;
114 os <<
" " << i++ <<
": " << t->getID() << std::endl;
126 os << indent <<
" " << port.
getID() <<
":";
128 if (
auto svcPortStr = svcPort->toString(
true)) {
129 os <<
" " << *svcPortStr << std::endl;
133 for (
const auto &[name, chan] : port.
getChannels())
134 os << indent <<
" " << name <<
": " << chan.getType()->
toString(
true)
142 [&](
const std::pair<const AppID, BundlePort &> port) {
143 return showPort(port.second, details);
145 if (!details && !hasPorts && d->
getChildren().empty())
147 os << indent <<
"* Instance: ";
148 if (
auto inst =
dynamic_cast<const Instance *
>(d)) {
149 os << inst->getID() << std::endl;
150 if (inst->getInfo() && inst->getInfo()->name)
151 os << indent <<
"* Module: " << *inst->getInfo()->name << std::endl;
153 os <<
"top" << std::endl;
156 os << indent <<
"* Ports:" << std::endl;
158 printPort(os, port, indent +
" ", details);
160 if (!children.empty()) {
161 os << indent <<
"* Children:" << std::endl;
172 os <<
"********************************" << std::endl;
173 os <<
"* Design hierarchy" << std::endl;
174 os <<
"********************************" << std::endl;
181 bool hasData =
false;
183 for (
const auto &portRef :
module.getPortsOrdered()) {
184 BundlePort &port = portRef.get();
188 node[metric->getID().toString()] = metric->readInt();
193 for (
const Instance *child : module.getChildrenOrdered()) {
194 nlohmann::json childNode = nlohmann::json::object();
196 node[child->getID().toString()] = childNode;
210 nlohmann::json root = nlohmann::json::object();
212 root = nlohmann::json{{
"error",
"No telemetry metrics found"}};
214 os << root.dump(2) << std::endl;
225 os <<
"No telemetry service found" << std::endl;
228 os <<
"********************************" << std::endl;
229 os <<
"* Telemetry" << std::endl;
230 os <<
"********************************" << std::endl;
233 const std::map<AppIDPath, services::TelemetryService::Metric *>
235 for (
const auto &[
id, port] : telemetryPorts) {
239 uint64_t value = port->readInt();
240 os << value << std::endl;
Abstract class representing a connection to an accelerator.
ServiceClass * getService(AppIDPath id={}, std::string implName={}, ServiceImplDetails details={}, HWClientDetails clients={})
Get a typed reference to a particular service type.
Context & getCtxt() const
AcceleratorServiceThread * getServiceThread()
Return a pointer to the accelerator 'service' thread (or threads).
void addPoll(HWModule &module)
Poll this module.
Top level accelerator class.
Services provide connections to 'bundles' – collections of named, unidirectional communication channe...
const PortMap & getChannels() const
AppID getID() const
Get the ID of the port.
Common options and code for ESI runtime tools.
Context & getContext()
Get the context.
AcceleratorConnection * connect()
Connect to the accelerator using the specified backend and connection.
int esiParse(int argc, const char **argv)
Run the parser.
AcceleratorConnections, Accelerators, and Manifests must all share a context.
Represents either the top level or an instance of a hardware module.
std::vector< std::reference_wrapper< BundlePort > > getPortsOrdered() const
Get the module's ports in a deterministic order.
std::vector< const Instance * > getChildrenOrdered() const
Get a vector of the module's children in a deterministic order.
const std::map< AppID, BundlePort & > & getPorts() const
Access the module's ports by ID.
const std::map< AppID, Instance * > & getChildren() const
Access the module's children by ID.
Subclass of HWModule which represents a submodule instance.
virtual void error(const std::string &subsystem, const std::string &msg, const std::map< std::string, std::any > *details=nullptr)
Report an error.
Class to parse a manifest.
uint32_t getApiVersion() const
Accelerator * buildAccelerator(AcceleratorConnection &acc) const
const std::vector< const Type * > & getTypeTable() const
The Type Table is an ordered list of types.
std::vector< ModuleInfo > getModuleInfos() const
Root class of the ESI type system.
Add a custom interface to a service client at a particular point in the design hierarchy.
Information about the Accelerator system.
virtual std::string getJsonManifest() const
Return the JSON-formatted system manifest.
A telemetry port which gets attached to a service port.
Service for retrieving telemetry data from the accelerator.
std::map< AppIDPath, Metric * > getTelemetryPorts()
void printHier(std::ostream &os, AcceleratorConnection &acc, bool details)
void printInstance(std::ostream &os, const HWModule *d, std::string indent, bool details)
void printPort(std::ostream &os, const BundlePort &port, std::string indent, bool details)
void printInfo(std::ostream &os, AcceleratorConnection &acc, bool details)
void printTelemetry(std::ostream &os, AcceleratorConnection &acc)
static bool showPort(const BundlePort &port, bool details)
static bool collectTelemetryJson(const HWModule &module, nlohmann::json &node)
int main(int argc, const char *argv[])
void printTelemetryJson(std::ostream &os, AcceleratorConnection &acc)
std::string toString() const