Implement dump_stats command for usbconfig(8).

This command is useful when debugging USB device issues.

MFC after:	1 week
Sponsored by:	Mellanox Technologies
This commit is contained in:
hselasky 2019-12-27 20:37:14 +00:00
parent 37ff270164
commit 4ed888af67
4 changed files with 50 additions and 3 deletions

View File

@ -483,3 +483,32 @@ dump_string_by_index(struct libusb20_device *pdev, uint8_t str_index)
}
free(pbuf);
}
void
dump_device_stats(struct libusb20_device *pdev)
{
struct libusb20_device_stats st;
if (libusb20_dev_get_stats(pdev, &st)) {
printf("{}\n");
} else {
printf("{\n"
" UE_CONTROL_OK : %llu\n"
" UE_ISOCHRONOUS_OK : %llu\n"
" UE_BULK_OK : %llu\n"
" UE_INTERRUPT_OK : %llu\n"
" UE_CONTROL_FAIL : %llu\n"
" UE_ISOCHRONOUS_FAIL : %llu\n"
" UE_BULK_FAIL : %llu\n"
" UE_INTERRUPT_FAIL : %llu\n"
"}\n",
(unsigned long long)st.xfer_ok[0],
(unsigned long long)st.xfer_ok[1],
(unsigned long long)st.xfer_ok[2],
(unsigned long long)st.xfer_ok[3],
(unsigned long long)st.xfer_fail[0],
(unsigned long long)st.xfer_fail[1],
(unsigned long long)st.xfer_fail[2],
(unsigned long long)st.xfer_fail[3]);
}
}

View File

@ -37,6 +37,7 @@ void dump_device_info(struct libusb20_device *pdev, uint8_t show_drv);
void dump_be_quirk_names(struct libusb20_backend *pbe);
void dump_be_dev_quirks(struct libusb20_backend *pbe);
void dump_device_desc(struct libusb20_device *pdev);
void dump_device_stats(struct libusb20_device *pdev);
void dump_config(struct libusb20_device *pdev, uint8_t all_cfg);
#endif /* _DUMP_H_ */

View File

@ -1,6 +1,6 @@
.\" $FreeBSD$
.\"
.\" Copyright (c) 2008-2010 Hans Petter Selasky. All rights reserved.
.\" Copyright (c) 2008-2019 Hans Petter Selasky. All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
@ -23,7 +23,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd August 16, 2019
.Dd December 27, 2019
.Dt USBCONFIG 8
.Os
.Sh NAME
@ -116,6 +116,8 @@ Display all the configuration descriptors.
Display string descriptor at selected index.
.It Cm dump_info
Display summary information about the device.
.It Cm dump_stats
Display USB transfer statistics.
.It Cm show_ifdrv
Display the list of interface drivers (such as
.Xr ukbd 4

View File

@ -82,6 +82,7 @@ struct options {
uint8_t got_dump_curr_config:1;
uint8_t got_dump_all_config:1;
uint8_t got_dump_info:1;
uint8_t got_dump_stats:1;
uint8_t got_show_iface_driver:1;
uint8_t got_remove_device_quirk:1;
uint8_t got_add_device_quirk:1;
@ -121,6 +122,7 @@ enum {
T_DUMP_ALL_CONFIG_DESC,
T_DUMP_STRING,
T_DUMP_INFO,
T_DUMP_STATS,
T_SUSPEND,
T_RESUME,
T_POWER_OFF,
@ -155,6 +157,7 @@ static const struct token token[] = {
{"dump_all_config_desc", T_DUMP_ALL_CONFIG_DESC, 0},
{"dump_string", T_DUMP_STRING, 1},
{"dump_info", T_DUMP_INFO, 0},
{"dump_stats", T_DUMP_STATS, 0},
{"show_ifdrv", T_SHOW_IFACE_DRIVER, 0},
{"suspend", T_SUSPEND, 0},
{"resume", T_RESUME, 0},
@ -296,6 +299,7 @@ usage(void)
" dump_all_config_desc" "\n"
" dump_string <index>" "\n"
" dump_info" "\n"
" dump_stats" "\n"
" show_ifdrv" "\n"
" suspend" "\n"
" resume" "\n"
@ -506,7 +510,8 @@ flush_command(struct libusb20_backend *pbe, struct options *opt)
opt->got_dump_device_desc ||
opt->got_dump_curr_config ||
opt->got_dump_all_config ||
opt->got_dump_info);
opt->got_dump_info ||
opt->got_dump_stats);
if (opt->got_list || dump_any) {
dump_device_info(pdev,
@ -527,6 +532,10 @@ flush_command(struct libusb20_backend *pbe, struct options *opt)
dump_device_desc(pdev);
dump_config(pdev, 1);
}
if (opt->got_dump_stats) {
printf("\n");
dump_device_stats(pdev);
}
if (dump_any) {
printf("\n");
}
@ -751,6 +760,12 @@ main(int argc, char **argv)
opt->got_dump_info = 1;
opt->got_any++;
break;
case T_DUMP_STATS:
if (opt->got_dump_stats)
duplicate_option(argv[n]);
opt->got_dump_stats = 1;
opt->got_any++;
break;
case T_DUMP_STRING:
if (opt->got_dump_string)
duplicate_option(argv[n]);