ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/lib/AnyEvent/Debug.pm
(Generate patch)

Comparing AnyEvent/lib/AnyEvent/Debug.pm (file contents):
Revision 1.17 by root, Mon Aug 15 19:19:19 2011 UTC vs.
Revision 1.18 by root, Tue Aug 16 14:47:26 2011 UTC

26 26
27package AnyEvent::Debug; 27package AnyEvent::Debug;
28 28
29use Carp (); 29use Carp ();
30use Errno (); 30use Errno ();
31use POSIX ();
32 31
33use AnyEvent (); BEGIN { AnyEvent::common_sense } 32use AnyEvent (); BEGIN { AnyEvent::common_sense }
34use AnyEvent::Util (); 33use AnyEvent::Util ();
35use AnyEvent::Socket (); 34use AnyEvent::Socket ();
35use AnyEvent::Log ();
36 36
37=item $shell = AnyEvent;::Debug::shell $host, $service 37=item $shell = AnyEvent;::Debug::shell $host, $service
38 38
39This function binds on the given host and service port and returns a 39This function binds on the given host and service port and returns a
40shell object, which determines the lifetime of the shell. Any number 40shell object, which determines the lifetime of the shell. Any number
136 136
137 sub help() { 137 sub help() {
138 <<EOF 138 <<EOF
139help this command 139help this command
140wr [level] sets wrap level to level (or toggles if missing) 140wr [level] sets wrap level to level (or toggles if missing)
141t [level] sets trace level (or toggles if missing) 141v [level] sets verbosity (or toggles if missing)
142wl 'regex' print wrapped watchers matching the regex (or all if missing) 142wl 'regex' print wrapped watchers matching the regex (or all if missing)
143w id,... prints the watcher with the given ids in more detail 143w id,... prints the watcher with the given ids in more detail
144EOF 144EOF
145 } 145 }
146 146
176 AnyEvent::Debug::wrap (@_); 176 AnyEvent::Debug::wrap (@_);
177 177
178 "wrap level now $AnyEvent::Debug::WRAP_LEVEL" 178 "wrap level now $AnyEvent::Debug::WRAP_LEVEL"
179 } 179 }
180 180
181 sub t { 181 sub v {
182 $AnyEvent::Debug::TRACE_LEVEL = @_ ? shift : $AnyEvent::Debug::TRACE_LEVEL ? 0 : 9; 182 $AnyEvent::VERBOSE = @_ ? shift : $AnyEvent::VERBOSE ? 0 : 9;
183 183
184 "trace level now $AnyEvent::Debug::TRACE_LEVEL" 184 "verbosity level now $AnyEvent::VEBROSE"
185 } 185 }
186} 186}
187 187
188=item AnyEvent::Debug::wrap [$level] 188=item AnyEvent::Debug::wrap [$level]
189 189
378 @DB::args = (); 378 @DB::args = ();
379 379
380 bless \@bt, "AnyEvent::Debug::Backtrace" 380 bless \@bt, "AnyEvent::Debug::Backtrace"
381} 381}
382 382
383# Format Time, not public - yet?
384sub ft($) {
385 my $t = shift;
386 my $i = int $t;
387 my $f = sprintf "%06d", 1e6 * ($t - $i);
388
389 POSIX::strftime "%Y-%m-%d %H:%M:%S.$f %z", localtime $i
390}
391
392package AnyEvent::Debug::Wrap; 383package AnyEvent::Debug::Wrap;
393 384
394use AnyEvent (); BEGIN { AnyEvent::common_sense } 385use AnyEvent (); BEGIN { AnyEvent::common_sense }
395use Scalar::Util (); 386use Scalar::Util ();
396use Carp (); 387use Carp ();
419 410
420 return &$cb 411 return &$cb
421 unless $TRACE_LEVEL; 412 unless $TRACE_LEVEL;
422 413
423 local $TRACE_CUR = "$w"; 414 local $TRACE_CUR = "$w";
424 print AnyEvent::Debug::ft AE::now, " enter $TRACE_CUR\n" if $TRACE_LEVEL; 415 AE::log trace => "enter $TRACE_CUR";
425 eval { 416 eval {
426 local $SIG{__DIE__} = sub { die $_[0] . AnyEvent::Debug::backtrace }; 417 local $SIG{__DIE__} = sub { die $_[0] . AnyEvent::Debug::backtrace };
427 &$cb; 418 &$cb;
428 }; 419 };
429 if ($@) { 420 if ($@) {
430 push @{ $w->{error} }, [AE::now, $@] 421 push @{ $w->{error} }, [AE::now, $@]
431 if @{ $w->{error} } < 10; 422 if @{ $w->{error} } < 10;
432 print AnyEvent::Debug::ft AE::now, " ERROR $TRACE_CUR $@"; 423 AE::log error => "$TRACE_CUR $@";
433 } 424 }
434 print AnyEvent::Debug::ft AE::now, " leave $TRACE_CUR\n" if $TRACE_LEVEL; 425 AE::log trace => "leave $TRACE_CUR";
435 }; 426 };
436 427
437 $self = bless { 428 $self = bless {
438 type => $name, 429 type => $name,
439 w => $self->$super (%arg), 430 w => $self->$super (%arg),
453 if $WRAP_LEVEL >= 2; 444 if $WRAP_LEVEL >= 2;
454 445
455 Scalar::Util::weaken ($w = $self); 446 Scalar::Util::weaken ($w = $self);
456 Scalar::Util::weaken ($AnyEvent::Debug::Wrapped{Scalar::Util::refaddr $self} = $self); 447 Scalar::Util::weaken ($AnyEvent::Debug::Wrapped{Scalar::Util::refaddr $self} = $self);
457 448
458 print AnyEvent::Debug::ft AE::now, " creat $w\n" if $TRACE_LEVEL; 449 AE::log trace => "creat $w";
459 450
460 $self 451 $self
461 }; 452 };
462 } 453 }
463} 454}
489sub verbose { 480sub verbose {
490 my ($self) = @_; 481 my ($self) = @_;
491 482
492 my $res = "type: $self->{type} watcher\n" 483 my $res = "type: $self->{type} watcher\n"
493 . "args: " . (join " ", %{ $self->{arg} }) . "\n" # TODO: decode fh? 484 . "args: " . (join " ", %{ $self->{arg} }) . "\n" # TODO: decode fh?
494 . "created: " . (AnyEvent::Debug::ft $self->{now}) . " ($self->{now})\n" 485 . "created: " . (AnyEvent::Log::ft $self->{now}) . " ($self->{now})\n"
495 . "file: $self->{file}\n" 486 . "file: $self->{file}\n"
496 . "line: $self->{line}\n" 487 . "line: $self->{line}\n"
497 . "subname: $self->{sub}\n" 488 . "subname: $self->{sub}\n"
498 . "context: $self->{cur}\n" 489 . "context: $self->{cur}\n"
499 . "cb: $self->{cb} (" . (AnyEvent::Debug::cb2str $self->{cb}) . ")\n" 490 . "cb: $self->{cb} (" . (AnyEvent::Debug::cb2str $self->{cb}) . ")\n"
504 } 495 }
505 496
506 if (exists $self->{error}) { 497 if (exists $self->{error}) {
507 $res .= "errors: " . @{$self->{error}} . "\n"; 498 $res .= "errors: " . @{$self->{error}} . "\n";
508 499
509 $res .= "error: " . (AnyEvent::Debug::ft $_->[0]) . " ($_->[0]) $_->[1]\n" 500 $res .= "error: " . (AnyEvent::Log::ft $_->[0]) . " ($_->[0]) $_->[1]\n"
510 for @{$self->{error}}; 501 for @{$self->{error}};
511 } 502 }
512 503
513 $res 504 $res
514} 505}
515 506
516sub DESTROY { 507sub DESTROY {
517 print AnyEvent::Debug::ft AE::now, " dstry $_[0]\n" if $TRACE_LEVEL; 508 AE::log trace => "dstry $_[0]";
518 509
519 delete $AnyEvent::Debug::Wrapped{Scalar::Util::refaddr $_[0]}; 510 delete $AnyEvent::Debug::Wrapped{Scalar::Util::refaddr $_[0]};
520} 511}
521 512
522package AnyEvent::Debug::Backtrace; 513package AnyEvent::Debug::Backtrace;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines