Skip to content

Commit 939a705

Browse files
committed
[metrics] Add option to export to .csv
1 parent 094dd94 commit 939a705

File tree

1 file changed

+43
-8
lines changed

1 file changed

+43
-8
lines changed

src/CommandLineUtilities/ProgramMetrics.cxx

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
///
1414
/// \author Kostas Alexopoulos ([email protected])
1515

16+
#include <fstream>
1617
#include <iostream>
1718
#include "Cru/Constants.h"
1819
#include "ReadoutCard/ChannelFactory.h"
@@ -41,6 +42,10 @@ class ProgramMetrics: public Program
4142
virtual void addOptions(boost::program_options::options_description& options)
4243
{
4344
Options::addOptionCardId(options);
45+
options.add_options()
46+
("csv-out",
47+
po::value<std::string>(&mOptions.csvOut),
48+
"Path to CSV file to write output");
4449
}
4550

4651
virtual void run(const boost::program_options::variables_map& map)
@@ -63,9 +68,14 @@ class ProgramMetrics: public Program
6368
} else {
6469
std::cout << "Something went wrong parsing the card id" << std::endl;
6570
}
71+
72+
if (mOptions.csvOut != "") {
73+
mOutputToCsv = true;
74+
}
75+
76+
std::ofstream csvOut;
6677

6778
std::ostringstream table;
68-
6979
auto formatHeader = " %-3s %-6s %-10s %-10s %-19s %-20s %-19s %-8s %-17s %-17s\n";
7080
auto formatRow = " %-3s %-6s %-10s %-10s %-19s %-20s %-19s %-8s %-17s %-17s\n";
7181
auto header = (boost::format(formatHeader)
@@ -74,7 +84,13 @@ class ProgramMetrics: public Program
7484
auto lineFat = std::string(header.length(), '=') + '\n';
7585
auto lineThin = std::string(header.length(), '-') + '\n';
7686

77-
table << lineFat << header << lineThin;
87+
if (mOutputToCsv) {
88+
csvOut.open(mOptions.csvOut);
89+
auto csvHeader = "#,Type,PCI Addr,Temp (C),#Dropped Packets,CTP Clock (MHz),Local Clock (MHz),#links,#Wrapper 0 links, #Wrapper 1 links\n";
90+
csvOut << csvHeader;
91+
} else {
92+
table << lineFat << header << lineThin;
93+
}
7894

7995
int i = 0;
8096
for (const auto& card : cardsFound) {
@@ -91,18 +107,37 @@ class ProgramMetrics: public Program
91107
uint32_t links0 = bar2->getLinksPerWrapper(0);
92108
uint32_t links1 = bar2->getLinksPerWrapper(1);
93109

94-
auto format = boost::format(formatRow) % i % CardType::toString(card.cardType) % card.pciAddress.toString()
95-
% temperature % dropped % ctp_clock % local_clock % links % links0 % links1;
110+
if (mOutputToCsv) {
111+
auto csvLine = std::to_string(i) + "," + CardType::toString(card.cardType) + "," + card.pciAddress.toString() + "," + std::to_string(temperature)
112+
+ "," + std::to_string(dropped) + "," + std::to_string(ctp_clock) + "," + std::to_string(local_clock) + "," + std::to_string(links) + ","
113+
+ std::to_string(links0) + "," + std::to_string(links1) + "\n";
114+
csvOut << csvLine;
115+
} else {
116+
auto format = boost::format(formatRow) % i % CardType::toString(card.cardType) % card.pciAddress.toString()
117+
% temperature % dropped % ctp_clock % local_clock % links % links0 % links1;
96118

97-
table << format;
119+
table << format;
120+
}
98121
i++;
99122
}
100123

101-
table << lineFat;
102-
std::cout << table.str();
124+
if (mOutputToCsv) {
125+
csvOut.close();
126+
} else {
127+
auto lineFat = std::string(header.length(), '=') + '\n';
128+
table << lineFat;
129+
std::cout << table.str();
130+
}
103131
}
104132

105-
private:
133+
private:
134+
135+
struct OptionsStruct {
136+
std::string csvOut = "";
137+
} mOptions;
138+
139+
bool mOutputToCsv = false;
140+
106141
};
107142

108143
int main(int argc, char** argv)

0 commit comments

Comments
 (0)