]> ncurses.scripts.mit.edu Git - ncurses.git/blob - test/tracemunch
ncurses 5.2
[ncurses.git] / test / tracemunch
1 #!/usr/bin/perl
2 #
3 # tracemunch -- compactify ncurses trace logs
4 #
5 # The error logs produced by ncurses with tracing enabled can be very tedious
6 # to wade through.  This script helps by compacting runs of log lines that
7 # can be conveniently expressed as higher-level operations.
8 #
9 # ($Id: tracemunch,v 1.2 1995/10/06 15:02:37 esr Exp $)
10
11 $putattr="PutAttrChar\\('(.)' = 0x.., {A_NORMAL}\\) at \\(([0-9]+), ([0-9]+)\\)";
12 $waddnstr="waddnstr\\(0x([0-9a-f]+),\"([^\"]+)\",[0-9]+\\) called {A_NORMAL}";
13
14 sub transaddr
15 {
16     $arg = $_[0];
17
18     $arg =~ s/$curscr/curscr/ if ($curscr);
19     $arg =~ s/$newscr/newscr/ if ($newscr);
20     $arg =~ s/$stdscr/stdscr/ if ($stdscr);
21
22     return $arg;
23 }
24
25 while (<STDIN>)
26 {
27 CLASSIFY: {
28         # Transform window pointer addresses so it's easier to compare logs
29         $awaiting = "curscr" if ($_ =~ /creating curscr/);
30         $awaiting = "newscr" if ($_ =~ /creating newscr/);
31         $awaiting = "stdscr" if ($_ =~ /creating stdscr/);
32         if ($awaiting && $_ =~ /newwin: returned window is 0x([0-9a-f]+)/)
33         {
34             $curscr = "0x$1" if ($awaiting eq "curscr");
35             $newscr = "0x$1" if ($awaiting eq "newscr");
36             $stdscr = "0x$1" if ($awaiting eq "stdscr");
37             $awaiting = "";
38         }
39
40         # Compactify runs of PutAttrChar calls (TR_CHARPUT)
41         if ($_ =~ /$putattr/)
42         {
43                 $putattr_chars = $1;
44                 $starty = $2;
45                 $startx = $3;
46                 while (<STDIN>)
47                 {
48                         if ($_ =~ /$putattr/) {
49                                 $putattr_chars .= $1;
50                         } else {
51                                 last;
52                         }
53                 }
54                 print "RUN of PutAttrChar()s: \"$putattr_chars\" from ${starty}, ${startx}\n";
55                 redo CLASSIFY;
56         }
57
58         # Compactify runs of waddnstr calls (TR_CALLS)
59         if ($_ =~ /$waddnstr/)
60         {
61                 $waddnstr_chars = $2;
62                 $winaddr = $1;
63                 while (<STDIN>)
64                 {
65                         if ($_ =~ /$waddnstr/ && $1 eq $winaddr) {
66                                 $waddnstr_chars .= $2;
67                         } else {
68                                 last;
69                         }
70                 }
71                 $winaddstr = &transaddr($winaddr);
72                 print "RUN of waddnstr()s: $winaddr, \"$waddnstr_chars\"\n";
73                 redo CLASSIFY;
74         }
75
76         # More transformations can go here
77
78         # Repeated runs of anything
79         $anyline = &transaddr($_);
80         $repeatcount = 1;
81         while (<STDIN>) {
82             if (&transaddr($_) eq $anyline) {
83                 $repeatcount++;
84             } else {
85                 last;
86             }
87         }
88         if ($repeatcount > 1) {
89                 print "${repeatcount} REPEATS OF $anyline";
90         } else {
91                 print $anyline
92         }
93         redo CLASSIFY if $_;
94
95         } # :CLASSIFY
96 }
97
98 # tracemunch ends here