Whamcloud - gitweb
d2c92733979923f7bb545f1aa74246939a246389
[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     $line = shift;
65 #    print "$_\n";
66     if ($line =~ m/\(\) ([0-9]*)\+[0-9]*\):/) {
67         return $1;
68     }
69     if ($line =~ m/\(\) ([0-9]*) | [0-9]*\+[0-9]*\):/) {
70         return $1;
71     }
72 }
73
74 sub entering
75 {
76     $_ = shift;
77     $entering = /Process entered/;
78 }
79
80 sub leaving
81 {
82     $_ = shift;
83     $entering = /Process leaving/;
84 }
85
86 sub getsubsys
87 {
88     my ($subsys, $mask) = split ":";
89     return hex($subsys);
90 }
91
92 sub getmask
93 {
94     my ($subsys, $mask) = split ":";
95     return hex($mask);
96 }
97
98 sub setcolor
99 {
100     my $linemask = shift;
101     if ($linemask == $masks->{TRACE}) {
102         print color("yellow on_black");
103     }
104     if ($linemask == $masks->{DLMTRACE}) {
105         print color("magenta on_black");
106     }
107     if ($linemask == $masks->{DLM}) {
108         print color("magenta on_black");
109     }
110     if ($linemask == $masks->{DENTRY}) {
111         print color("red on_black");
112     }
113 }
114
115 sub study_lock
116 {
117     $_ = shift;
118     my $rc;
119
120     $rc = /completion callback handler START ns: (.*) lock: (.*) lrc: (.*) mode/;
121     if ($rc) {
122         $completion_callbacks{$1}->{$2} = $3;
123 #         print color("white");
124 #         print "---CP CB START: $1 $2 $3\n";
125 #         print color("reset");
126     }
127     $rc = /callback handler finished.* ns: (.*) lock: (.*) lrc: (.*) mode/;
128     if ($rc) {
129 #         print color("white");
130 #         print "---CP CB END: $1 $2 $3 deleting $completion_callbacks{$1}->{$2}\n";
131 #         print color("reset");
132         delete $completion_callbacks{$1}->{$2};
133     }
134
135     if ($rc) {
136         $rc = /client blocking AST callback handler START ns: (.*) lock: (.*) lrc: (.*) mode/;
137         $blocking_callbacks{$1}->{$2} = $3;
138 #         print color("white");
139 #         print "---BL CB START: $1 $2\n";
140 #         print color("reset");
141     }
142     $rc = /client blocking callback handler END ns: (.*) lock: (.*) lrc: (.*) mode/;
143     if ($rc) {
144 #         print color("white");
145 #         print "---BL CB END: $1 $2 $3 deleting $blocking_callbacks{$1}->{$2}\n";
146 #         print color("reset");
147         delete $blocking_callbacks{$1}->{$2};
148     }
149
150     $rc = /ldlm_lock_addref.*ns: (.*) lock: (.*) lrc: (.*) mode/;
151 #     print color("white");
152 #     print "------>addref ns: $1 lock: $2 lrc: $3\n" if ($rc);
153 #     print color("reset");
154     $locks{$1}->{$2} = {$3} if ($rc);
155     $rc = /ldlm_lock_decref.*ns: (.*) lock: (.*) lrc: (.*) mode/;
156 #     print color("white");
157 #     print "------>decref ns: $1 lock: $2 lrc: $3\n" if ($rc);
158 #     print color("reset");
159     $locks{$1}->{$2} = {$3} if ($rc);
160 }
161
162 sub hanging_locks 
163 {
164     my $found; 
165     my $ns;
166
167     foreach (keys %completion_callbacks) {
168         $ns = $_;
169         $found = 0;
170         foreach (keys %{$completion_callbacks{$ns}}) {
171             if (!$found) {
172                 print "Unfinished completions in ns $ns: \n";
173                 $found =1;
174             }
175             print "  lock: $_ lrc: $completion_callbacks{$ns}->{$_}\n";
176         }
177     }
178     foreach (keys %blocking_callbacks) {
179         $ns = $_;
180         $found = 0;
181         foreach (keys %{$blocking_callbacks{$ns}}) {
182             if (!$found) {
183                 print "Unfinished blocking in ns $ns: \n";
184                 $found =1;
185             }
186             printf("  lock: $_ lrc: %s\n", $blocking_callbacks{$ns}->{$_});
187         }
188     }
189
190 }
191
192 sub study_intent 
193 {
194     $_ = shift;
195     my $rc;
196
197     $rc = /D_IT UP dentry (.*) fsdata/;
198     delete $it{$1} if ($rc);
199     $rc = /D_IT DOWN dentry (.*) fsdata/;
200     $it{$1} = "yes"  if ($rc);
201 }
202
203 sub unmatched_intents { 
204     my $found;
205     foreach (keys %it) {
206         if (!$found) {
207             print "Unmatched intents: \n";
208             $found =1;
209         }
210         print "  $_\n";
211     }
212 }
213
214 while (<STDIN>) {
215     $linepid = extractpid($_);
216     $linemask = getmask($_);
217     $linesubsys = getsubsys($_);
218
219 #    printf "---> mask %x subsys %x\n", $linemask, $linesubsys;
220
221     if (leaving($_)) {
222         chop $prefix->{$linepid};
223         chop $prefix->{$linepid};
224     }
225
226     if ($linemask == $masks->{DENTRY}) {
227         study_intent($_);
228     }
229     if ($linemask == $masks->{DLMTRACE}) {
230         study_lock($_);
231     }
232
233     if ( !$pid || $linepid == $pid) {
234         next if ($rpctrace && $linemask != $masks->{RPCTRACE});
235         next if ($trace && $linemask != $masks->{TRACE});
236
237
238         next if ($nodlm && 
239                  (  $linesubsys == $subsys->{LDLM}));
240         next if ($noclass && 
241                  (  $linesubsys == $subsys->{CLASS}));
242
243         next if ($nonet && 
244                  (  $linesubsys == $subsys->{RPC} ||
245                     $linesubsys == $subsys->{NET} ||
246                     $linesubsys == $subsys->{PORTALS} ||
247                     $linesubsys == $subsys->{SOCKNAL} ||
248                     $linesubsys == $subsys->{QSWNAL} ||
249                     $linesubsys == $subsys->{GMNAL}));
250
251
252 #        printf "sub/mask: %s - %s\n", getsubsys($_), getmask($_);
253         if (!$silent) { 
254             setcolor($linemask);
255             printf("%s%s", $prefix->{$linepid}, $_);
256             print color("reset");
257         }
258             #        last if $count++ > 100;
259     }
260     if (entering($_)) {
261         $prefix->{$linepid} .= '  ';
262     } 
263 }
264
265
266 unmatched_intents();
267 hanging_locks();
268 # printf "argv %s pid %d\n", $ARGV[0], extractpid($ARGV[0]);