… | |
… | |
268 | sub command($) { |
268 | sub command($) { |
269 | my ($cmd) = @_; |
269 | my ($cmd) = @_; |
270 | |
270 | |
271 | $cmd =~ s/\s+$//; |
271 | $cmd =~ s/\s+$//; |
272 | |
272 | |
273 | if ($cmd =~ /^ps (?:\s* (\S+)) $/x) { |
273 | if ($cmd =~ /^ps (?:\s* (\S+))? $/x) { |
274 | my $flags = $1; |
274 | my $flags = $1; |
275 | my $desc = $flags =~ /w/ ? "%-24s" : "%-24.24s"; |
275 | my $desc = $flags =~ /w/ ? "%-24s" : "%-24.24s"; |
276 | printf "%20s %s%s %4s %4s $desc %s\n", "PID", "S", "C", "RSS", "USES", "Description", "Where"; |
276 | my $buf = sprintf "%20s %s%s %4s %4s $desc %s\n", |
|
|
277 | "PID", "S", "C", "RSS", "USES", "Description", "Where"; |
|
|
278 | Coro::cede; |
277 | for my $coro (reverse Coro::State::list) { |
279 | for my $coro (reverse Coro::State::list) { |
278 | Coro::cede; |
|
|
279 | my @bt; |
280 | my @bt; |
280 | Coro::State::call ($coro, sub { |
281 | Coro::State::call ($coro, sub { |
281 | # we try to find *the* definite frame that gives msot useful info |
282 | # we try to find *the* definite frame that gives msot useful info |
282 | # by skipping Coro frames and pseudo-frames. |
283 | # by skipping Coro frames and pseudo-frames. |
283 | for my $frame (1..10) { |
284 | for my $frame (1..10) { |
284 | my @frame = caller $frame; |
285 | my @frame = caller $frame; |
285 | @bt = @frame if $frame[2]; |
286 | @bt = @frame if $frame[2]; |
286 | last unless $bt[0] =~ /^Coro/; |
287 | last unless $bt[0] =~ /^Coro/; |
287 | } |
288 | } |
288 | }); |
289 | }); |
289 | printf "%20s %s%s %4s %4s $desc %s\n", |
290 | $buf .= sprintf "%20s %s%s %4s %4s $desc %s\n", |
290 | $coro+0, |
291 | $coro+0, |
291 | $coro->is_new ? "N" : $coro->is_running ? "U" : $coro->is_ready ? "R" : "-", |
292 | $coro->is_new ? "N" : $coro->is_running ? "U" : $coro->is_ready ? "R" : "-", |
292 | $coro->is_traced ? "T" : $coro->has_cctx ? "C" : "-", |
293 | $coro->is_traced ? "T" : $coro->has_cctx ? "C" : "-", |
293 | format_num4 $coro->rss, |
294 | format_num4 $coro->rss, |
294 | format_num4 $coro->usecount, |
295 | format_num4 $coro->usecount, |
295 | $coro->debug_desc, |
296 | $coro->debug_desc, |
296 | (@bt ? sprintf "[%s:%d]", $bt[1], $bt[2] : "-"); |
297 | (@bt ? sprintf "[%s:%d]", $bt[1], $bt[2] : "-"); |
297 | } |
298 | } |
|
|
299 | Coro::cede; |
|
|
300 | print $buf; |
298 | |
301 | |
299 | } elsif ($cmd =~ /^bt\s+(\d+)$/) { |
302 | } elsif ($cmd =~ /^bt\s+(\d+)$/) { |
300 | if (my $coro = find_coro $1) { |
303 | if (my $coro = find_coro $1) { |
301 | my $bt; |
304 | my $bt; |
302 | Coro::State::call ($coro, sub { |
305 | Coro::State::call ($coro, sub { |