Whamcloud - gitweb
merge b_md onto HEAD. as best as I can remember:
[fs/lustre-release.git] / lustre / utils / llanalyze
1 #!/usr/bin/perl
2
3 use Getopt::Long;
4 use Term::ANSIColor;
5
6 GetOptions("pid=i" => \$pid, 
7            "trace!" => \$trace, 
8            "silent!" => \$silent, 
9            "rpctrace!" => \$rpctrace, 
10            "nodlm!" => \$nodlm,
11            "noclass!" => \$noclass,
12            "nonet!" => \$nonet);
13
14 print "pid: $pid, nodlm $nodlm nonet $nonet trace $trace\n";
15
16
17 $subsys->{UNDEFINED} = 0;
18 $subsys->{MDC} = 1;
19 $subsys->{MDS} = 2;
20 $subsys->{OSC} = 3;
21 $subsys->{OST} = 4;
22 $subsys->{CLASS} = 5;
23 $subsys->{OBDFS} = 6;
24 $subsys->{LLITE} = 7;
25 $subsys->{RPC} = 8;
26 $subsys->{EXT2OBD} = 9;
27 $subsys->{PORTALS} = 10;
28 $subsys->{SOCKNAL} = 11;
29 $subsys->{QSWNAL} = 12;
30 $subsys->{PINGER} = 13;
31 $subsys->{FILTER} = 14;
32 $subsys->{TRACE} = 15; # obdtrace, not to be confused with D_TRACE */
33 $subsys->{ECHO} = 16;
34 $subsys->{LDLM} = 17;
35 $subsys->{LOV} = 18;
36 $subsys->{GMNAL} = 19;
37 $subsys->{PTLROUTER} = 20;
38
39
40 $masks->{TRACE} = 1 << 0; # /* ENTRY/EXIT markers */
41 $masks->{INODE} = 1 << 1; #
42 $masks->{SUPER} = 1 << 2; #
43 $masks->{EXT2} = 1 << 3; # /* anything from ext2_debug */
44 $masks->{MALLOC} = 1 << 4; # /* print malloc, free information */
45 $masks->{CACHE} = 1 << 5; # /* cache-related items */
46 $masks->{INFO} = 1 << 6; # /* general information */
47 $masks->{IOCTL} = 1 << 7; # /* ioctl related information */
48 $masks->{BLOCKS} = 1 << 8; # /* ext2 block allocation */
49 $masks->{NET} = 1 << 9; # /* network communications */
50 $masks->{WARNING} = 1 << 10; #
51 $masks->{BUFFS} = 1 << 11; #
52 $masks->{OTHER} = 1 << 12; #
53 $masks->{DENTRY} = 1 << 13; #
54 $masks->{PORTALS} = 1 << 14; # /* ENTRY/EXIT markers */
55 $masks->{PAGE} = 1 << 15; # /* bulk page handling */
56 $masks->{DLMTRACE} = 1 << 16; #
57 $masks->{ERROR} = 1 << 17; # /* CERROR} = ...) == CDEBUG} = D_ERROR, ...) */
58 $masks->{EMERG} = 1 << 18; # /* CEMERG} = ...) == CDEBUG} = D_EMERG, ...) */
59 $masks->{HA} = 1 << 19; # /* recovery and failover */
60 $masks->{RPCTRACE} = 1 << 19; # /* recovery and failover */
61
62 sub extractpid
63 {
64     $_ = shift;
65 #    print "$_\n";
66     /l. [0-9]* (.*)\):/;
67     return $1;
68 }
69
70 sub entering
71 {
72     $_ = shift;
73     $entering = /Process entered/;
74 }
75
76 sub leaving
77 {
78     $_ = shift;
79     $entering = /Process leaving/;
80 }
81
82 sub getsubsys
83 {
84     my ($subsys, $mask) = split ":";
85     return hex($subsys);
86 }
87
88 sub getmask
89 {
90     my ($subsys, $mask) = split ":";
91     return hex($mask);
92 }
93
94 sub setcolor
95 {
96     my $linemask = shift;
97     if ($linemask == $masks->{TRACE}) {
98         print color("yellow on_black");
99     }
100     if ($linemask == $masks->{DLMTRACE}) {
101         print color("magenta on_black");
102     }
103     if ($linemask == $masks->{DLM}) {
104         print color("magenta on_black");
105     }
106     if ($linemask == $masks->{DENTRY}) {
107         print color("red on_black");
108     }
109 }
110
111 sub study_lock
112 {
113     $_ = shift;
114     my $rc;
115
116     $rc = /completion callback handler START ns: (.*) lock: (.*) lrc: (.*) mode/;
117     if ($rc) {
118         $completion_callbacks{$1}->{$2} = $3;
119 #         print color("white");
120 #         print "---CP CB START: $1 $2 $3\n";
121 #         print color("reset");
122     }
123     $rc = /callback handler finished.* ns: (.*) lock: (.*) lrc: (.*) mode/;
124     if ($rc) {
125 #         print color("white");
126 #         print "---CP CB END: $1 $2 $3 deleting $completion_callbacks{$1}->{$2}\n";
127 #         print color("reset");
128         delete $completion_callbacks{$1}->{$2};
129     }
130
131     if ($rc) {
132         $rc = /client blocking AST callback handler START ns: (.*) lock: (.*) lrc: (.*) mode/;
133         $blocking_callbacks{$1}->{$2} = $3;
134 #         print color("white");
135 #         print "---BL CB START: $1 $2\n";
136 #         print color("reset");
137     }
138     $rc = /client blocking callback handler END ns: (.*) lock: (.*) lrc: (.*) mode/;
139     if ($rc) {
140 #         print color("white");
141 #         print "---BL CB END: $1 $2 $3 deleting $blocking_callbacks{$1}->{$2}\n";
142 #         print color("reset");
143         delete $blocking_callbacks{$1}->{$2};
144     }
145
146     $rc = /ldlm_lock_addref.*ns: (.*) lock: (.*) lrc: (.*) mode/;
147 #     print color("white");
148 #     print "------>addref ns: $1 lock: $2 lrc: $3\n" if ($rc);
149 #     print color("reset");
150     $locks{$1}->{$2} = {$3} if ($rc);
151     $rc = /ldlm_lock_decref.*ns: (.*) lock: (.*) lrc: (.*) mode/;
152 #     print color("white");
153 #     print "------>decref ns: $1 lock: $2 lrc: $3\n" if ($rc);
154 #     print color("reset");
155     $locks{$1}->{$2} = {$3} if ($rc);
156 }
157
158 sub hanging_locks 
159 {
160     my $found; 
161     my $ns;
162
163     foreach (keys %completion_callbacks) {
164         $ns = $_;
165         $found = 0;
166         foreach (keys %{$completion_callbacks{$ns}}) {
167             if (!$found) {
168                 print "Unfinished completions in ns $ns: \n";
169                 $found =1;
170             }
171             print "  lock: $_ lrc: $completion_callbacks{$ns}->{$_}\n";
172         }
173     }
174     foreach (keys %blocking_callbacks) {
175         $ns = $_;
176         $found = 0;
177         foreach (keys %{$blocking_callbacks{$ns}}) {
178             if (!$found) {
179                 print "Unfinished blocking in ns $ns: \n";
180                 $found =1;
181             }
182             printf("  lock: $_ lrc: %s\n", $blocking_callbacks{$ns}->{$_});
183         }
184     }
185
186 }
187
188 sub study_intent 
189 {
190     $_ = shift;
191     my $rc;
192
193     $rc = /D_IT UP dentry (.*) fsdata/;
194     delete $it{$1} if ($rc);
195     $rc = /D_IT DOWN dentry (.*) fsdata/;
196     $it{$1} = "yes"  if ($rc);
197 }
198
199 sub unmatched_intents { 
200     my $found;
201     foreach (keys %it) {
202         if (!$found) {
203             print "Unmatched intents: \n";
204             $found =1;
205         }
206         print "  $_\n";
207     }
208 }
209
210 while (<STDIN>) {
211     $linepid = extractpid($_);
212     $linemask = getmask($_);
213     $linesubsys = getsubsys($_);
214
215 #    printf "---> mask %x subsys %x\n", $linemask, $linesubsys;
216
217     if (leaving($_)) {
218         chop $prefix->{$linepid};
219         chop $prefix->{$linepid};
220     }
221
222     if ($linemask == $masks->{DENTRY}) {
223         study_intent($_);
224     }
225     if ($linemask == $masks->{DLMTRACE}) {
226         study_lock($_);
227     }
228
229     if ( !$pid || $linepid == $pid) {
230         next if ($rpctrace && $linemask != $masks->{RPCTRACE});
231         next if ($trace && $linemask != $masks->{TRACE});
232
233
234         next if ($nodlm && 
235                  (  $linesubsys == $subsys->{LDLM}));
236         next if ($noclass && 
237                  (  $linesubsys == $subsys->{CLASS}));
238
239         next if ($nonet && 
240                  (  $linesubsys == $subsys->{RPC} ||
241                     $linesubsys == $subsys->{NET} ||
242                     $linesubsys == $subsys->{PORTALS} ||
243                     $linesubsys == $subsys->{SOCKNAL} ||
244                     $linesubsys == $subsys->{QSWNAL} ||
245                     $linesubsys == $subsys->{GMNAL}));
246
247
248 #        printf "sub/mask: %s - %s\n", getsubsys($_), getmask($_);
249         if (!$silent) { 
250             setcolor($linemask);
251             printf("%s%s", $prefix->{$linepid}, $_);
252             print color("reset");
253         }
254             #        last if $count++ > 100;
255     }
256     if (entering($_)) {
257         $prefix->{$linepid} .= '  ';
258     } 
259 }
260
261
262 unmatched_intents();
263 hanging_locks();
264 # printf "argv %s pid %d\n", $ARGV[0], extractpid($ARGV[0]);