@@ -346,12 +346,37 @@ std::string build_csv_row(const std::vector<std::string>& chunks, const std::str
346
346
});
347
347
}
348
348
349
+ std::string get_root_port_dev (const bool show_root_port, int part_id, const pcm::iio_stack *stack)
350
+ {
351
+ char tmp[9 ] = " " ;
352
+ std::string rp_pci;
353
+
354
+ if (!show_root_port)
355
+ return rp_pci;
356
+
357
+ for (auto part = stack->parts .begin (); part != stack->parts .end (); part = std::next (part))
358
+ {
359
+ if (part->part_id == part_id)
360
+ {
361
+ std::snprintf (tmp, sizeof (tmp), " %02x:%02x.%x" , part->root_pci_dev .bdf .busno ,
362
+ part->root_pci_dev .bdf .devno , part->root_pci_dev .bdf .funcno );
363
+ break ;
364
+ }
365
+ }
366
+
367
+ rp_pci.append (tmp);
368
+ return rp_pci;
369
+
370
+ }
371
+
349
372
vector<string> build_csv (vector<struct iio_stacks_on_socket >& iios, vector<struct counter >& ctrs,
350
- const bool human_readable, const std::string& csv_delimiter)
373
+ const bool human_readable, const bool show_root_port, const std::string& csv_delimiter)
351
374
{
352
375
vector<string> result;
353
376
vector<string> current_row;
354
377
auto header = combine_stack_name_and_counter_names (" Name" );
378
+ if (show_root_port)
379
+ header.insert (header.begin (), " Root Port" );
355
380
header.insert (header.begin (), " Socket" );
356
381
result.push_back (build_csv_row (header, csv_delimiter));
357
382
std::map<uint32_t ,map<uint32_t ,struct counter *>> v_sort;
@@ -373,7 +398,10 @@ vector<string> build_csv(vector<struct iio_stacks_on_socket>& iios, vector<struc
373
398
374
399
const uint32_t stack_id = stack->iio_unit_id ;
375
400
// Print data
376
- for (std::map<uint32_t ,map<uint32_t ,struct counter *>>::const_iterator vunit = v_sort.cbegin (); vunit != v_sort.cend (); ++vunit) {
401
+ int part_id;
402
+ std::map<uint32_t ,map<uint32_t ,struct counter *>>::const_iterator vunit;
403
+ for (vunit = v_sort.cbegin (), part_id = 0 ;
404
+ vunit != v_sort.cend (); ++vunit, ++part_id) {
377
405
map<uint32_t , struct counter *> h_array = vunit->second ;
378
406
uint32_t vv_id = vunit->first ;
379
407
vector<uint64_t > h_data;
@@ -384,6 +412,10 @@ vector<string> build_csv(vector<struct iio_stacks_on_socket>& iios, vector<struc
384
412
385
413
current_row.clear ();
386
414
current_row.push_back (socket_name);
415
+ if (show_root_port) {
416
+ auto pci_dev = get_root_port_dev (show_root_port, part_id, &(*stack));
417
+ current_row.push_back (pci_dev);
418
+ }
387
419
current_row.push_back (stack_name);
388
420
current_row.push_back (v_name);
389
421
for (map<uint32_t ,struct counter *>::const_iterator hunit = h_array.cbegin (); hunit != h_array.cend (); ++hunit) {
@@ -1138,6 +1170,7 @@ void print_usage(const string& progname)
1138
1170
<< " to a file, in case filename is provided\n " ;
1139
1171
cerr << " -csv-delimiter=<value> | /csv-delimiter=<value> => set custom csv delimiter\n " ;
1140
1172
cerr << " -human-readable | /human-readable => use human readable format for output (for csv only)\n " ;
1173
+ cerr << " -root-port | /root-port => add root port devices to output (for csv only)\n " ;
1141
1174
cerr << " -i[=number] | /i[=number] => allow to determine number of iterations\n " ;
1142
1175
cerr << " Examples:\n " ;
1143
1176
cerr << " " << progname << " 1.0 -i=10 => print counters every second 10 times and exit\n " ;
@@ -1159,6 +1192,7 @@ int main(int argc, char * argv[])
1159
1192
load_PCIDB (pciDB);
1160
1193
bool csv = false ;
1161
1194
bool human_readable = false ;
1195
+ bool show_root_port = false ;
1162
1196
std::string csv_delimiter = " ," ;
1163
1197
std::string output_file;
1164
1198
double delay = PCM_DELAY_DEFAULT;
@@ -1186,6 +1220,9 @@ int main(int argc, char * argv[])
1186
1220
else if (check_argument_equals (*argv, {" -human-readable" , " /human-readable" })) {
1187
1221
human_readable = true ;
1188
1222
}
1223
+ else if (check_argument_equals (*argv, {" -root-port" , " /root-port" })) {
1224
+ show_root_port = true ;
1225
+ }
1189
1226
else if (mainLoop.parseArg (*argv)) {
1190
1227
continue ;
1191
1228
}
@@ -1277,7 +1314,7 @@ int main(int argc, char * argv[])
1277
1314
{
1278
1315
collect_data (m, delay, iios, counters);
1279
1316
vector<string> display_buffer = csv ?
1280
- build_csv (iios, counters, human_readable, csv_delimiter) :
1317
+ build_csv (iios, counters, human_readable, show_root_port, csv_delimiter) :
1281
1318
build_display (iios, counters, pciDB);
1282
1319
display (display_buffer, *output);
1283
1320
return true ;
0 commit comments