@@ -346,12 +346,37 @@ std::string build_csv_row(const std::vector<std::string>& chunks, const std::str
346346 });
347347}
348348
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+
349372vector<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)
351374{
352375 vector<string> result;
353376 vector<string> current_row;
354377 auto header = combine_stack_name_and_counter_names (" Name" );
378+ if (show_root_port)
379+ header.insert (header.begin (), " Root Port" );
355380 header.insert (header.begin (), " Socket" );
356381 result.push_back (build_csv_row (header, csv_delimiter));
357382 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
373398
374399 const uint32_t stack_id = stack->iio_unit_id ;
375400 // 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) {
377405 map<uint32_t , struct counter *> h_array = vunit->second ;
378406 uint32_t vv_id = vunit->first ;
379407 vector<uint64_t > h_data;
@@ -384,6 +412,10 @@ vector<string> build_csv(vector<struct iio_stacks_on_socket>& iios, vector<struc
384412
385413 current_row.clear ();
386414 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+ }
387419 current_row.push_back (stack_name);
388420 current_row.push_back (v_name);
389421 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)
11381170 << " to a file, in case filename is provided\n " ;
11391171 cerr << " -csv-delimiter=<value> | /csv-delimiter=<value> => set custom csv delimiter\n " ;
11401172 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 " ;
11411174 cerr << " -i[=number] | /i[=number] => allow to determine number of iterations\n " ;
11421175 cerr << " Examples:\n " ;
11431176 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[])
11591192 load_PCIDB (pciDB);
11601193 bool csv = false ;
11611194 bool human_readable = false ;
1195+ bool show_root_port = false ;
11621196 std::string csv_delimiter = " ," ;
11631197 std::string output_file;
11641198 double delay = PCM_DELAY_DEFAULT;
@@ -1186,6 +1220,9 @@ int main(int argc, char * argv[])
11861220 else if (check_argument_equals (*argv, {" -human-readable" , " /human-readable" })) {
11871221 human_readable = true ;
11881222 }
1223+ else if (check_argument_equals (*argv, {" -root-port" , " /root-port" })) {
1224+ show_root_port = true ;
1225+ }
11891226 else if (mainLoop.parseArg (*argv)) {
11901227 continue ;
11911228 }
@@ -1277,7 +1314,7 @@ int main(int argc, char * argv[])
12771314 {
12781315 collect_data (m, delay, iios, counters);
12791316 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) :
12811318 build_display (iios, counters, pciDB);
12821319 display (display_buffer, *output);
12831320 return true ;
0 commit comments