|
| 1 | +/// \file ProgramMetrics.cxx |
| 2 | +/// \brief Tool that returns current information about RoCs. |
| 3 | +/// |
| 4 | +/// \author Kostas Alexopoulos ([email protected]) |
| 5 | + |
| 6 | +#include <iostream> |
| 7 | +#include "Cru/Constants.h" |
| 8 | +#include "ReadoutCard/ChannelFactory.h" |
| 9 | +#include "CommandLineUtilities/Options.h" |
| 10 | +#include "CommandLineUtilities/Program.h" |
| 11 | +#include "RocPciDevice.h" |
| 12 | +#include <boost/format.hpp> |
| 13 | +#include <boost/optional/optional_io.hpp> |
| 14 | + |
| 15 | +using namespace AliceO2::roc::CommandLineUtilities; |
| 16 | +using namespace AliceO2::roc; |
| 17 | +using namespace AliceO2::InfoLogger; |
| 18 | +namespace po = boost::program_options; |
| 19 | + |
| 20 | +class ProgramMetrics: public Program |
| 21 | +{ |
| 22 | + public: |
| 23 | + |
| 24 | + virtual Description getDescription() |
| 25 | + { |
| 26 | + return {"Metrics", "Return current RoC parameters", |
| 27 | + "roc-metrics\n" |
| 28 | + "roc-metrics --pci-address 42:00.0\n"}; |
| 29 | + } |
| 30 | + |
| 31 | + virtual void addOptions(boost::program_options::options_description& options) |
| 32 | + { |
| 33 | + options.add_options() |
| 34 | + ("pci-address", |
| 35 | + po::value<std::string>(&mOptions.pciAddress)->default_value("-1"), |
| 36 | + "Card's PCI Address"); |
| 37 | + } |
| 38 | + |
| 39 | + virtual void run(const boost::program_options::variables_map& map) |
| 40 | + { |
| 41 | + |
| 42 | + std::vector<CardDescriptor> cardsFound; |
| 43 | + if (mOptions.pciAddress != "-1") |
| 44 | + cardsFound = AliceO2::roc::RocPciDevice::findSystemDevices(mOptions.pciAddress); |
| 45 | + else |
| 46 | + cardsFound = AliceO2::roc::RocPciDevice::findSystemDevices(); |
| 47 | + |
| 48 | + |
| 49 | + std::ostringstream table; |
| 50 | + |
| 51 | + auto formatHeader = " %-3s %-6s %-10s %-10s %-19s %-20s %-19s %-8s %-17s %-17s\n"; |
| 52 | + auto formatRow = " %-3s %-6s %-10s %-10s %-19s %-20s %-19s %-8s %-17s %-17s\n"; |
| 53 | + auto header = (boost::format(formatHeader) |
| 54 | + % "#" % "Type" % "PCI Addr" % "Temp (C)" % "#Dropped Packets" % "CTP Clock (MHz)" % "Local Clock (MHz)" |
| 55 | + % "#links" % "#Wrapper 0 links" % "#Wrapper 1 links").str(); |
| 56 | + auto lineFat = std::string(header.length(), '=') + '\n'; |
| 57 | + auto lineThin = std::string(header.length(), '-') + '\n'; |
| 58 | + |
| 59 | + table << lineFat << header << lineThin; |
| 60 | + |
| 61 | + int i = 0; |
| 62 | + for (const auto& card : cardsFound) { |
| 63 | + Parameters params = Parameters::makeParameters(card.pciAddress, 2); |
| 64 | + auto bar2 = ChannelFactory().getBar(params); |
| 65 | + |
| 66 | + float temperature = bar2->getTemperature().value_or(0); |
| 67 | + int32_t dropped = bar2->getDroppedPackets(); |
| 68 | + float ctp_clock = bar2->getCTPClock()/1e6; |
| 69 | + float local_clock = bar2->getLocalClock()/1e6; |
| 70 | + int32_t links = bar2->getLinks(); |
| 71 | + uint32_t links0 = bar2->getLinksPerWrapper(0); |
| 72 | + uint32_t links1 = bar2->getLinksPerWrapper(1); |
| 73 | + |
| 74 | + auto format = boost::format(formatRow) % i % CardType::toString(card.cardType) % card.pciAddress.toString() |
| 75 | + % temperature % dropped % ctp_clock % local_clock % links % links0 % links1; |
| 76 | + |
| 77 | + table << format; |
| 78 | + i++; |
| 79 | + } |
| 80 | + |
| 81 | + table << lineFat; |
| 82 | + std::cout << table.str(); |
| 83 | + } |
| 84 | + |
| 85 | + struct OptionsStruct |
| 86 | + { |
| 87 | + std::string pciAddress = "-1"; |
| 88 | + }mOptions; |
| 89 | + |
| 90 | + private: |
| 91 | +}; |
| 92 | + |
| 93 | +int main(int argc, char** argv) |
| 94 | +{ |
| 95 | + if (argc > 2){ |
| 96 | + std::cout << "Too many arguments" << std::endl; |
| 97 | + return -1; |
| 98 | + } |
| 99 | + return ProgramMetrics().execute(argc, argv); |
| 100 | +} |
0 commit comments