24#include <nlohmann/json.hpp>
35int main(
int argc,
const char *argv[]) {
37 cli.description(
"Query an ESI system for information from the manifest.");
39 CLI::App *versionSub =
40 cli.add_subcommand(
"version",
"Print ESI system version");
41 bool infoDetails =
false;
43 cli.add_subcommand(
"info",
"Print ESI system information");
44 infoSub->add_flag(
"--details", infoDetails,
45 "Print detailed information about the system");
46 bool hierDetails =
false;
47 CLI::App *hierSub = cli.add_subcommand(
"hier",
"Print ESI system hierarchy");
48 hierSub->add_flag(
"--details", hierDetails,
49 "Print detailed information about the system");
50 bool telemetryJson =
false;
51 CLI::App *telemetrySub =
52 cli.add_subcommand(
"telemetry",
"Print ESI system telemetry information");
53 telemetrySub->add_flag(
"--json", telemetryJson,
54 "Dump telemetry information as JSON");
56 if (
int rc = cli.
esiParse(argc, argv))
58 if (!cli.get_help_ptr()->empty())
67 std::cout << info.getEsiVersion() << std::endl;
72 else if (*telemetrySub) {
79 }
catch (std::exception &e) {
86 std::string jsonManifest =
89 os <<
"API version: " << m.
getApiVersion() << std::endl << std::endl;
90 os <<
"********************************" << std::endl;
91 os <<
"* Module information" << std::endl;
92 os <<
"********************************" << std::endl;
101 os <<
"********************************" << std::endl;
102 os <<
"* Type table" << std::endl;
103 os <<
"********************************" << std::endl;
107 os <<
" " << i++ <<
": " << t->getID() << std::endl;
119 os << indent <<
" " << port.
getID() <<
":";
121 if (
auto svcPortStr = svcPort->toString()) {
122 os <<
" " << *svcPortStr << std::endl;
126 for (
const auto &[name, chan] : port.
getChannels())
127 os << indent <<
" " << name <<
": " << chan.getType()->getID()
135 [&](
const std::pair<const AppID, BundlePort &> port) {
136 return showPort(port.second, details);
138 if (!details && !hasPorts && d->
getChildren().empty())
140 os << indent <<
"* Instance: ";
141 if (
auto inst =
dynamic_cast<const Instance *
>(d)) {
142 os << inst->getID() << std::endl;
143 if (inst->getInfo() && inst->getInfo()->name)
144 os << indent <<
"* Module: " << *inst->getInfo()->name << std::endl;
146 os <<
"top" << std::endl;
149 os << indent <<
"* Ports:" << std::endl;
151 printPort(os, port, indent +
" ", details);
153 if (!children.empty()) {
154 os << indent <<
"* Children:" << std::endl;
165 os <<
"********************************" << std::endl;
166 os <<
"* Design hierarchy" << std::endl;
167 os <<
"********************************" << std::endl;
174 bool hasData =
false;
176 for (
const auto &portRef :
module.getPortsOrdered()) {
177 BundlePort &port = portRef.get();
181 node[metric->getID().toString()] = metric->readInt();
186 for (
const Instance *child : module.getChildrenOrdered()) {
187 nlohmann::json childNode = nlohmann::json::object();
189 node[child->getID().toString()] = childNode;
203 nlohmann::json root = nlohmann::json::object();
205 root = nlohmann::json{{
"error",
"No telemetry metrics found"}};
207 os << root.dump(2) << std::endl;
218 os <<
"No telemetry service found" << std::endl;
221 os <<
"********************************" << std::endl;
222 os <<
"* Telemetry" << std::endl;
223 os <<
"********************************" << std::endl;
226 const std::map<AppIDPath, services::TelemetryService::Metric *>
228 for (
const auto &[
id, port] : telemetryPorts) {
232 uint64_t value = port->readInt();
233 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)