File: extract.pl

package info (click to toggle)
0ad 0.0.21-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 54,068 kB
  • sloc: cpp: 230,527; ansic: 23,115; python: 13,559; perl: 2,499; sh: 948; xml: 776; makefile: 696; java: 533; ruby: 229; erlang: 53; sql: 21
file content (47 lines) | stat: -rw-r--r-- 1,096 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/perl

use strict;
use warnings;

# Run the game normally to generate a simulation command log.
# Run the replay mode like:
#  ./pyrogenesis -mod=public -replay=$HOME/.config/0ad/logs/sim_log/99999/commands.txt
# to generate profile.txt.
# Then run:
#  perl extract.pl > data.js
# then open graph.html.

open my $f, '../../../binaries/system/profile.txt' or die $!;
my $turn = 0;
my %s;
my %f;
while (<$f>) {
    if (/^PS profiler snapshot/) {
        if ($turn) {
            for (keys %f) {
                $s{$_}[$turn-1] = $f{$_};
            }
        }
        ++$turn;
        %f = ();
    } elsif (/Time in node: ([\d.]+)/) {
        $f{"total"} += $1;
    } elsif (/^[|'][- |']*([^|]+?)\s+\|[^|]+\|\s+(\S+)/) {
        $f{$1} += $2;
    } elsif (/^[|']-([^|]+?)\s+\|\s+(\d+)/) {
        $f{$1} += $2;
    }
}

print "var graphData = [\n";
my $n = 0;
for my $k (sort keys %s) {
    print ",\n" if $n++;
    print "{label: '$k', data:[";
    for my $t (0..$#{$s{$k}}) {
        print "," if $t;
        print "[$t,".($s{$k}[$t] || 0)."]";
    }
    print "]}";
}
print "\n];\n";