Show
Ignore:
Timestamp:
02/14/08 22:31:01 (22 months ago)
Author:
bchoate
Message:

Initial work for performance logging.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/release-30/lib/MT/Builder.pm

    r1174 r1372  
    283283    #print STDERR syntree2str($tokens,0) unless $count++ == 1; 
    284284 
     285    my $timer; 
     286    if ($MT::DebugMode & 8) { 
     287        $timer = MT->get_timer(); 
     288    } 
     289 
    285290    if ($cond) { 
    286291        my %lcond; 
     
    331336            my($h, $type) = $ctx->handler_for($t->[0]); 
    332337            if ($h) { 
    333                 my $start; 
    334                 if ($MT::DebugMode & 8) { 
    335                     require Time::HiRes; 
    336                     $start = [ Time::HiRes::gettimeofday() ]; 
    337                 } 
     338                $timer->pause_partial if $timer; 
    338339                local($ctx->{__stash}{tag}) = $t->[0]; 
    339340                local($ctx->{__stash}{tokens}) = ref($tokens) ? bless $tokens, 'MT::Template::Tokens' : undef; 
     
    382383                    my $err = $ctx->errstr; 
    383384                    if (defined $err) { 
    384                         return $build->error(MT->translate("Error in <mt:[_1]> tag: [_2]", $t->[0], $ctx->errstr)); 
     385                        return $build->error(MT->translate("Error in <mt[_1]> tag: [_2]", $t->[0], $ctx->errstr)); 
    385386                    } 
    386387                    else { 
     
    402403                $res .= $out 
    403404                    if defined $out; 
    404                 if ($MT::DebugMode & 8) { 
    405                     my $elapsed = Time::HiRes::tv_interval($start); 
    406                     print STDERR "Builder: Tag [" . $t->[0] . "] - $elapsed seconds\n" if $elapsed > 0.25; 
     405 
     406                if ($timer) { 
     407                    $timer->mark("tag_" 
     408                        . lc($t->[0]) . args_to_string(\%args)); 
    407409                } 
    408410            } else { 
     
    417419} 
    418420 
     421sub args_to_string { 
     422    my ($args) = @_; 
     423    my $str = ''; 
     424    foreach my $a (keys %$args) { 
     425        next if $a eq '@'; 
     426        next unless defined $args->{$a}; 
     427        next if $args->{$a} eq ''; 
     428        $str .= ';' . $a . ':'; 
     429        if (ref $args->{$a} eq 'ARRAY') { 
     430            foreach my $aa (@{ $args->{$a} }) { 
     431                $aa = '...' if $aa =~ m/ /; 
     432                $str .= $aa . ';'; 
     433            } 
     434            chop($str); 
     435        } else { 
     436            $str .= $args->{$a} =~ m/ / ? '...' : $args->{$a}; 
     437        } 
     438    } 
     439    my $more_args = $args->{'@'}; 
     440    if ($more_args && @$more_args) { 
     441        foreach my $a (@$more_args) { 
     442            if (ref $a->[1] eq 'ARRAY') { 
     443                $str .= ' ' . $a->[0] . '='; 
     444                foreach my $aa (@{ $a->[1] }) { 
     445                    $aa = '...' if $aa =~ m/ /; 
     446                    $str .= $aa . ';'; 
     447                } 
     448                chop($str); 
     449            } else { 
     450                next if exists $args->{$a->[0]} 
     451                    && ($args->{$a->[0]} eq $a->[1]); 
     452                next unless defined $args->[1]; 
     453                next if $args->[1] eq ''; 
     454                $str .= ';' . $a->[0] . ':'; 
     455                $str .= $a->[1]; 
     456            } 
     457        } 
     458    } 
     459    return $str ne '' ? '[' . substr($str,1) . ']' : ''; 
     460} 
    4194611; 
    420462__END__