1 | #!/usr/bin/perl
|
---|
2 |
|
---|
3 | open(STRACEIN, '<:utf8', 'strace.out') or die('Error! Failed to open file for reading: strace.out');
|
---|
4 | open(TSVOUT, '>:utf8', 'strace.tsv') or die('Error! Failed to open file for writing: strace.tsv');
|
---|
5 | print TSVOUT "TIMESTAMP\tPID\tSYSCALL\tELAPSED\tTOTALDUR\tTOTALIN\tTOTALCPU\tARGS\tRESULT\n";
|
---|
6 |
|
---|
7 | my $io_function_list = {
|
---|
8 | 'access'=>1,
|
---|
9 | 'chmod'=>1, 'close'=>1, 'creat'=>1,
|
---|
10 | 'fclose'=>1, 'fcntl'=>1, 'fgetpos'=>1, 'flock'=>1, 'fseek'=>1, 'fsetpos'=>1,
|
---|
11 | 'fstat'=>1, 'fsync'=>1, 'ftell'=>1,
|
---|
12 | 'getdents'=>1,
|
---|
13 | 'ioctl'=>1, # John added
|
---|
14 | 'llseek'=>1, 'lockf'=>1, 'lseek'=>1, 'lseek64'=>1,
|
---|
15 | 'mkdir'=>1,
|
---|
16 | 'open'=>1,
|
---|
17 | 'read'=>1, 'readdir'=>1, 'rename'=>1, 'rewind'=>1, 'rewinddir'=>1,
|
---|
18 | 'scandir'=>1, 'stat'=>1, 'stat64'=>1,
|
---|
19 | 'telldir'=>1,
|
---|
20 | 'unlink'=>1,
|
---|
21 | 'write'=>1
|
---|
22 | };
|
---|
23 |
|
---|
24 | print "Converting 'strace.out' to 'strace.tsv'... ";
|
---|
25 | my $line = '';
|
---|
26 | my $total_duration = 0;
|
---|
27 | my $total_io_duration = 0;
|
---|
28 | my $total_cpu_duration = 0;
|
---|
29 | my $pid = 0;
|
---|
30 | my $start_time = 0;
|
---|
31 | while ($line = <STRACEIN>)
|
---|
32 | {
|
---|
33 | # PID Prefix
|
---|
34 | if ($line =~ /^(\d+)\s+(.*)$/)
|
---|
35 | {
|
---|
36 | $pid = $1;
|
---|
37 | $line = $2;
|
---|
38 | }
|
---|
39 | # Special Cases
|
---|
40 | # - exit_group
|
---|
41 | if ($line =~ /^(\d+\.\d+)\s+exit_group\(0\)\s+=\s+\?$/)
|
---|
42 | {
|
---|
43 | }
|
---|
44 | # Normal Command
|
---|
45 | elsif ($line =~/^(\d+\.\d+)\s+([a-z0-9_]+)\((.*)\)\s+=\s+(.+)\s+<(\d+\.\d+)>$/s)
|
---|
46 | {
|
---|
47 | my $timestamp = $1;
|
---|
48 | my $syscall = $2;
|
---|
49 | my $args = $3;
|
---|
50 | my $result = $4;
|
---|
51 | my $duration = $5;
|
---|
52 |
|
---|
53 | if ($start_time == 0)
|
---|
54 | {
|
---|
55 | $start_time = $timestamp;
|
---|
56 | $timestamp = 0;
|
---|
57 | }
|
---|
58 | else
|
---|
59 | {
|
---|
60 | $timestamp = $timestamp - $start_time;
|
---|
61 | }
|
---|
62 |
|
---|
63 | print TSVOUT sprintf("%0.6f", $timestamp) . "\t";
|
---|
64 | print TSVOUT $pid . "\t";
|
---|
65 | print TSVOUT $syscall . "\t";
|
---|
66 | print TSVOUT sprintf("%0.6f", $duration) . "\t";
|
---|
67 | print TSVOUT $args . "\t";
|
---|
68 | print TSVOUT $result . "\n";
|
---|
69 | }
|
---|
70 | else
|
---|
71 | {
|
---|
72 | chomp($line);
|
---|
73 | print 'Unparsed: |' . $line . "|\n";
|
---|
74 | }
|
---|
75 | }
|
---|
76 | close(STRACEIN);
|
---|
77 | close(TSVOUT);
|
---|
78 |
|
---|
79 | print "Complete!\n\n";
|
---|
80 | print " - Duration: " . $total_duration . "\n";
|
---|
81 | print " - Total IO: " . $total_io_duration . "\n";
|
---|
82 | exit;
|
---|
83 | 1;
|
---|