root/gs2-extensions/parallel-building/trunk/src/bin/script/strace_to_tsv.pl @ 28666

Revision 28666, 2.3 KB (checked in by jmt12, 6 years ago)

A script to transform a strace.out into a Tab separated file worthy of being imported into a spreadsheet app

  • Property svn:executable set to *
Line 
1#!/usr/bin/perl
2
3open(STRACEIN, '<:utf8', 'strace.out') or die('Error! Failed to open file for reading: strace.out');
4open(TSVOUT, '>:utf8', 'strace.tsv') or die('Error! Failed to open file for writing: strace.tsv');
5print TSVOUT "TIMESTAMP\tPID\tSYSCALL\tELAPSED\tTOTALDUR\tTOTALIN\tTOTALCPU\tARGS\tRESULT\n";
6
7my $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
24print "Converting 'strace.out' to 'strace.tsv'... ";
25my $line = '';
26my $total_duration = 0;
27my $total_io_duration = 0;
28my $total_cpu_duration = 0;
29my $pid = 0;
30my $start_time = 0;
31while ($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}
76close(STRACEIN);
77close(TSVOUT);
78
79print "Complete!\n\n";
80print " - Duration: " . $total_duration . "\n";
81print " - Total IO: " . $total_io_duration . "\n";
82exit;
831;
Note: See TracBrowser for help on using the browser.