How to use usbmon for knowing amount of data transferred from usb (pendrive )?

13,655

Solution 1

usbmon.txt and usbmon.txt Examples gives a clear explanation about usbmon or usbdump.

You have to find which bus connected to your device. For that open your terminal and type:

cat /sys/kernel/debug/usb/devices

It will give you an output similar to:

T:  Bus=03 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#=  2 Spd=12  MxCh= 0
D:  Ver= 1.10 Cls=00(>ifc ) Sub=00 Prot=00 MxPS= 8 #Cfgs=  1
P:  Vendor=0557 ProdID=2004 Rev= 1.00
S:  Manufacturer=ATEN
S:  Product=UC100KM V2.00

In the above sample output, T has Bus with its ID. So, Bus id is 03.

or

To see Bus ID you can also use lsusb , open terminal & type:

lsusb

It will give you an output similar to:

Bus 003 Device 002: ID 0557:2004 ATEN UC100KM V2.00

Which means Bus ID 003.

You now know that the USB gets connected to BUS ID 003. Then in terminal type:

cat /sys/kernel/debug/usb/usbmon/3u > /tmp/1.mon.out

In the above command, you are monitoring the data transmission happening in Bus ID 03. If you want to monitor the data transmission at all Buses, then type:

cat /sys/kernel/debug/usb/usbmon/0u > /tmp/1.mon.out

Which will scan until the transmission goes to the end. If you want to interrupt then use CTRL+C.

To understand the output read: The usbmon: USB monitoring framework

Solution 2

Install wireshark than easiest way is to:

  1. Check device "Bus" and Number "Device" with lsusb ( in "" are lsusb fields)
  2. Mount usbmon sudo modprobe usbmon
  3. Start wireshark sudo wireshark
  4. In wireshark select what to listen to: usbmon{Bus nr form lsusb} fe: usbmon1
  5. Add filter for your "Device" number

Cleaner way is to add rule for usbmon for your user, than you can use it (and wireshark) without root privileges

Solution 3

Find the bus number your device is on (see shekar's answer). Then on the raw /dev/usbmonX, use pipemeter (or pipebench) to measure throughput, or dump it to a file and visualize its growth with speedometer..f.e. for device on bus number 2:

# next three commands are equivalent - use any one
# pipemeter /dev/usbmon2 > /dev/null
# pipemeter < /dev/usbmon2 > /dev/null
# cat /dev/usbmon2 | pipemeter > /dev/null

# in 1st terminal
# cat /dev/usbmon2 > /tmp/usbdump
# in 2nd terminal
# speedometer /tmp/usbdump

The formatted text output from the /sys/kernel/debug/usb/usbmon/Xu files produces overhead for small amounts of traffic but seems to truncate bigger data blocks, so the raw usbmon device should give you more exact figures.

Share:
13,655
user3529205
Author by

user3529205

Updated on September 18, 2022

Comments

  • user3529205
    user3529205 over 1 year

    Please someone explain me in simple terms how to use usbmon to track the amount of data transferred from pendrive ?

  • user3529205
    user3529205 about 10 years
    But that file 1.mon.out is showing very weird output , how to use that output to calculate the data transferred in Bytes ?
  • user3529205
    user3529205 about 10 years
  • shekhar
    shekhar about 10 years
    @user3529205 Found it. Please look at 2nd link in my answer.
  • user3529205
    user3529205 about 10 years
    still i think there is no way to find the size of packet file ?
  • shekhar
    shekhar about 10 years
    @user3529205 yes , its explaining the output.
  • user3529205
    user3529205 about 10 years
    please can you point out in line 1-5 of pastebin link what would be the length field ? actually after " Number of isochronous frame descriptors and descriptors themselves" and before " < > = " signs there are two numbers