3
/**********************************************************************
6
* Douglas Schilling Landgraf <dougsland@redhat.com>
8
* This program is free software; you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License as published by
10
* the Free Software Foundation, version 2 of the License.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
20
* This is a quick hack to parse logs from the usbsnoop (usb sniffer)
23
* If needed to process a huge log maybe is needed to increase
30
* $ php ./usb_snoop ./Usbsnoop > output.txt
34
* 009279: 002309 ms 126080 ms c0 0e a0 00 00 00 01 00 <<< 00
35
* 009280: 000007 ms 126087 ms c0 10 a0 00 00 00 01 00 <<< 00
36
* 009281: 000005 ms 126092 ms 40 0e a0 00 00 00 01 00 >>> 99
37
* 009282: 000107 ms 126199 ms c0 0e a0 00 01 00 01 00 <<< 99
38
* 009283: 000015 ms 126214 ms c0 0e a0 00 10 00 01 00 <<< 99
39
* 009284: 000004 ms 126218 ms 40 10 a0 00 00 00 01 00 >>> 00
40
* 009285: 000004 ms 126222 ms 40 0e a0 00 00 00 01 00 >>> 00
42
***********************************************************************/
44
function removeNL($var) {
46
$newstr = str_replace("\n", "", $var);
50
function removeZeros($var) {
52
/* Removing 00000000 */
53
$remZeros = strstr($var, ": ");
56
$remNewLine = str_replace(": ", "", $remZeros);
59
$newstr = removeNL($remNewLine);
74
printf("Usage: $argv[0] usbsnoop-log.txt\n");
78
$file = fopen($argv[1], "r") or exit("Unable to open file!\n");
80
/* Copying to a temp. buffer */
83
$arrayFile[$i] = fgets($file);
92
if(!isset($arrayFile[$j])) {
96
$str = removeNL($arrayFile[$j]);
98
$pieces = explode(" ", $str);
100
if (((strstr($str, "<<<")) || (strstr($str, ">>>"))) ) {
101
$URB = $pieces[6] . ":";
105
if( $pieces[0] != "--") {
107
$timeTotalOp = str_replace("[", "", $t);
108
$timeTotalOp = $timeTotalOp . " ms";
111
/* Updating current time*/
112
$currentTime = $timeTotalOp;
114
$str = removeNL($arrayFile[$j]);
116
/* Searching for type to analyze*/
118
if (strstr($str, "-- URB_FUNCTION_CONTROL_TRANSFER:")) {
125
if(!isset($arrayFile[$j])) {
129
/* Setting Direction */
130
if (strstr($arrayFile[$j], "TransferFlags")) {
131
if(strstr($arrayFile[$j], "USBD_TRANSFER_DIRECTION_OUT")) {
139
if (strstr($arrayFile[$j], "TransferBufferMDL")) {
145
if (strstr($arrayFile[$j], "000000")) {
146
$aa = "$arrayFile[$j]\n";
147
if($getValues == 1) {
148
$cmdV = removeZeros($aa);
151
$cmdV .= " " . removeZeros($aa);
159
$j = $j - $getValues;
161
if (strstr($arrayFile[$j], "SetupPacket")) {
163
/* To catch the command we increase a line */
169
$diff = $timeTotalOp - $oldTime . " ms";
172
$ctrlCmds = removeZeros($arrayFile[$j]);
175
printf ("%06d: %06d ms %06d ms %s %s %s%s\n",
176
$URB + 0, $diff, $timeTotalOp, $ctrlCmds, $direction, $cmdVD, $cmdV);
180
printf ("%06d: %06d ms %06d ms %s %s %s\n",
181
$URB + 0, $diff, $timeTotalOp, $ctrlCmds, $direction, $cmdV);
183
$oldTime = $timeTotalOp;
186
if (strstr($arrayFile[$j], "[")) {
193
if (strstr($arrayFile[$j], "-- URB_FUNCTION_VENDOR_DEVICE:")) {
200
if (strstr($arrayFile[$j], "TransferBufferMDL")) {
205
if (strstr($arrayFile[$j], "UrbLink")) {
209
$tmpCMD = "$arrayFile[$j]\n";
210
$cmdVD = removeZeros($tmpCMD);
213
if (strstr($arrayFile[$j], "[")) {