Changeset 1372
- Timestamp:
- 02/14/08 22:31:01 (7 months ago)
- Files:
-
- branches/release-30/build/mt-dists/default.mk (modified) (1 diff)
- branches/release-30/lib/MT.pm.pre (modified) (5 diffs)
- branches/release-30/lib/MT/App.pm (modified) (3 diffs)
- branches/release-30/lib/MT/Builder.pm (modified) (5 diffs)
- branches/release-30/lib/MT/Core.pm (modified) (2 diffs)
- branches/release-30/lib/MT/Entry.pm (modified) (2 diffs)
- branches/release-30/lib/MT/Tag.pm (modified) (4 diffs)
- branches/release-30/lib/MT/Template.pm (modified) (3 diffs)
- branches/release-30/lib/MT/Util/ReqTimer.pm (added)
- branches/release-30/lib/MT/WeblogPublisher.pm (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/release-30/build/mt-dists/default.mk
r1333 r1372 1 1 PRODUCT_NAME = Movable Type Core 2 2 3 PRODUCT_VERSION = 4.1 3 PRODUCT_VERSION = 4.11 4 4 SCHEMA_VERSION = 4.0037 5 API_VERSION = 4.1 5 API_VERSION = 4.11 6 6 7 7 # BUILD_LANGUAGE = en_US branches/release-30/lib/MT.pm.pre
r1308 r1372 856 856 } 857 857 858 if ($cfg->ProcessMemoryCommand) { 859 $mt->log_times(); 860 } 861 858 862 $mt->set_language( $cfg->DefaultLanguage ); 859 863 … … 866 870 867 871 1; 872 } 873 874 { 875 my ($memory_start); 876 sub log_times { 877 my $pkg = shift; 878 879 my $timer = $pkg->get_timer; 880 return unless $timer; 881 882 my $memory; 883 my $cmd = $pkg->config->ProcessMemoryCommand; 884 if ($cmd) { 885 my $re; 886 if (ref($cmd) eq 'HASH') { 887 $re = $cmd->{regex}; 888 $cmd = $cmd->{command}; 889 } 890 $cmd =~ s/\$\$/$$/g; 891 $memory = `$cmd`; 892 if ($re) { 893 if ($memory =~ m/$re/) { 894 $memory = $1; 895 $memory =~ s/\D//g; 896 } 897 } else { 898 $memory =~ s/\s+//gs; 899 } 900 } 901 902 # Called at the start of the process; so we're only recording 903 # the memory usage at the start of the app right now. 904 unless ($timer->{elapsed}) { 905 $memory_start = $memory; 906 return; 907 } 908 909 my $log_file; 910 911 # Log filename calcluation; changes daily, so we don't cache this 912 require File::Spec; 913 my $dir = File::Spec->catdir( MT->instance->static_file_path, 914 'support', 'logs'); 915 if (! -d $dir) { 916 require File::Path; 917 eval { File::Path::mkpath([$dir], 0, 0777) }; 918 if ($@) { 919 $log_file = 0; 920 return; 921 } 922 } 923 my @time = localtime(time); 924 my $file = sprintf("pl-%04d%02d%02d.log", $time[5] + 1900, $time[4]+1, $time[3]); 925 $log_file = File::Spec->catfile( $dir, $file ); 926 927 my $first_write = ! -f $log_file; 928 929 local *PERFLOG; 930 open PERFLOG, ">>$log_file"; 931 require Fcntl; 932 flock(PERFLOG, Fcntl::LOCK_EX()); 933 934 if ($first_write) { 935 require Config; 936 my ($osname, $osvers) = ($Config::Config{osname}, $Config::Config{osvers}); 937 print PERFLOG "# Operating System: $osname/$osvers\n"; 938 print PERFLOG "# Platform: $^O\n"; 939 my $ver = ref($^V) eq 'version' ? $^V->normal : ( $^V ? join('.', unpack 'C*', $^V) : $] ); 940 print PERFLOG "# Perl Version: $ver\n"; 941 print PERFLOG "# Web Server: $ENV{SERVER_SOFTWARE}\n"; 942 require MT::Object; 943 my $driver = MT::Object->driver; 944 if ($driver) { 945 my $dbh = $driver->r_handle; 946 if ($dbh) { 947 my $dbname = $dbh->get_info( 17 ); # SQL_DBMS_NAME 948 my $dbver = $dbh->get_info( 18 ); # SQL_DBMS_VER 949 if ($dbname && $dbver) { 950 print PERFLOG "# Database: $dbname/$dbver\n"; 951 } 952 } 953 } 954 my ($drname, $drh) = each %DBI::installed_drh; 955 print PERFLOG "# Database Library: DBI/" . $DBI::VERSION . "; DBD/" . $drh->{Version} . "\n"; 956 if ($ENV{MOD_PERL}) { 957 print PERFLOG "# App Mode: mod_perl\n"; 958 } 959 elsif ($ENV{FAST_CGI}) { 960 print PERFLOG "# App Mode: FastCGI\n"; 961 } 962 else { 963 print PERFLOG "# App Mode: CGI\n"; 964 } 965 } 966 967 if ($memory) { 968 print PERFLOG $timer->dump_line("mem_start=$memory_start", "mem_end=$memory"); 969 } else { 970 print PERFLOG $timer->dump_line(); 971 } 972 973 close PERFLOG; 974 } 975 } 976 977 sub get_timer { 978 my $mt = shift; 979 $mt = MT->instance unless ref $mt; 980 my $timer = $mt->request('timer'); 981 unless ($timer) { 982 my $uri; 983 if ($mt->isa('MT::App')) { 984 $uri = $mt->uri( args => { $mt->param_hash } ); 985 } 986 require MT::Util::ReqTimer; 987 $timer = MT::Util::ReqTimer->new( $uri ); 988 $mt->request('timer', $timer); 989 } 990 return $timer; 991 } 992 993 sub time_this { 994 my $mt = shift; 995 my ($str, $code) = @_; 996 my $timer = $mt->get_timer(); 997 my $ret; 998 if ($timer) { 999 $timer->pause_partial(); 1000 $ret = $code->(); 1001 $timer->mark($str); 1002 } else { 1003 $ret = $code->(); 1004 } 1005 return $ret; 868 1006 } 869 1007 … … 1077 1215 my $mt = shift; 1078 1216 my ($PluginSwitch, $use_plugins, $PluginPaths) = @_; 1217 1218 my $timer; 1219 if ($mt->config->PerformanceLogging) { 1220 $timer = $mt->get_timer(); 1221 } 1079 1222 1080 1223 foreach my $PluginPath (@$PluginPaths) { … … 1108 1251 return 0 if exists $Plugins{$plugin_sig}; 1109 1252 $Plugins{$plugin_sig}{full_path} = $plugin_full_path; 1253 $timer->pause_partial if $timer; 1110 1254 eval { require $plugin }; 1255 $timer->mark("Loaded plugin " . $sig) if $timer; 1111 1256 if ($@) { 1112 1257 $Plugins{$plugin_sig}{error} = $@; … … 1867 2012 return $mt->error( 1868 2013 $mt->translate("Loading template '[_1]' failed.", $file)) unless $tmpl; 1869 $tmpl->{__file} = $file if $type eq 'filename';1870 2014 $mt->set_default_tmpl_params($tmpl); 1871 2015 $tmpl->param($param) if $param; branches/release-30/lib/MT/App.pm
r1371 r1372 2049 2049 my $q = $app->param; 2050 2050 2051 my $timer; 2052 if ($app->config->PerformanceLogging) { 2053 $timer = $app->get_timer(); 2054 $timer->pause_partial(); 2055 } 2056 2051 2057 my($body); 2052 2058 eval { … … 2252 2258 } 2253 2259 } 2260 2261 if ($timer) { 2262 $timer->mark(ref($app) . '::run'); 2263 } 2264 2254 2265 $app->takedown(); 2255 2266 } … … 2314 2325 require MT::Auth; 2315 2326 MT::Auth->release; 2327 2328 if ($app->config->PerformanceLogging) { 2329 $app->log_times(); 2330 } 2316 2331 2317 2332 $app->request->finish; branches/release-30/lib/MT/Builder.pm
r1174 r1372 283 283 #print STDERR syntree2str($tokens,0) unless $count++ == 1; 284 284 285 my $timer; 286 if ($MT::DebugMode & 8) { 287 $timer = MT->get_timer(); 288 } 289 285 290 if ($cond) { 286 291 my %lcond; … … 331 336 my($h, $type) = $ctx->handler_for($t->[0]); 332 337 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; 338 339 local($ctx->{__stash}{tag}) = $t->[0]; 339 340 local($ctx->{__stash}{tokens}) = ref($tokens) ? bless $tokens, 'MT::Template::Tokens' : undef; … … 382 383 my $err = $ctx->errstr; 383 384 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)); 385 386 } 386 387 else { … … 402 403 $res .= $out 403 404 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)); 407 409 } 408 410 } else { … … 417 419 } 418 420 421 sub 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 } 419 461 1; 420 462 __END__ branches/release-30/lib/MT/Core.pm
r1369 r1372 499 499 # Basename settings 500 500 'AuthorBansenameLimit' => { default => 30 }, 501 'PerformanceLogging' => { default => 0 }, 502 'PerformanceLoggingThreshold' => { default => 0.1 }, 503 'ProcessMemoryCommand' => { handler => \&ProcessMemoryCommand }, 501 504 }, 502 505 upgrade_functions => \&load_upgrade_fns, … … 801 804 } 802 805 806 sub ProcessMemoryCommand { 807 my $cfg = shift; 808 $cfg->set_internal( 'ProcessMemoryCommand', @_ ) if @_; 809 my $cmd = $cfg->get_internal('ProcessMemoryCommand'); 810 unless ($cmd) { 811 my $os = $^O; 812 if ($os eq 'darwin') { 813 $cmd = 'ps $$ -o rss='; 814 } 815 elsif ($os eq 'linux') { 816 $cmd = 'ps -p $$ -o rss='; 817 } 818 elsif ($os eq 'MSWin32') { 819 $cmd = { command => q{tasklist /FI "PID eq $$" /FO TABLE /NH}, 820 regex => qr/([\d,]+) K/ }; 821 } 822 } 823 return $cmd; 824 } 825 803 826 sub SecretToken { 804 827 my $cfg = shift; branches/release-30/lib/MT/Entry.pm
r1174 r1372 222 222 sub __load_category_data { 223 223 my $entry = shift; 224 my $t = MT->get_timer; 225 $t->pause_partial if $t; 224 226 my $cache = MT::Memcached->instance; 225 227 my $memkey = $entry->cache_key('categories'); … … 231 233 $cache->set($memkey, $rows, CATEGORY_CACHE_TIME); 232 234 } 235 $t->mark('MT::Entry::__load_category_data') if $t; 233 236 return $rows; 234 237 } branches/release-30/lib/MT/Tag.pm
r1208 r1372 325 325 sub __load_tags { 326 326 my $obj = shift; 327 my $t = MT->get_timer; 328 $t->pause_partial if $t; 329 327 330 if (!$obj->id) { 328 331 $obj->{__tags} = []; … … 347 350 } 348 351 $obj->{__tags} = [ map { $_->name } @tags ]; 352 $t->mark('MT::Tag::__load_tags') if $t; 349 353 $obj->{__tag_objects} = \@tags; 350 354 } … … 375 379 my @tags = @{ $obj->{__tags} }; 376 380 return 1 unless @tags; 381 382 my $t = MT->get_timer; 383 $t->pause_partial if $t; 384 377 385 $obj->{__tag_objects} = []; 378 386 my $blog_id = $obj->has_column('blog_id') ? $obj->blog_id : 0; … … 427 435 MT::Memcached->instance->delete( $obj->tag_cache_key ); 428 436 } 437 $t->mark('MT::Tag::save_tags') if $t; 429 438 1; 430 439 } branches/release-30/lib/MT/Template.pm
r1369 r1372 91 91 $tmpl->{include_path} = $param{path}; 92 92 $tmpl->{include_filter} = $param{filter}; 93 $tmpl->{__file} = $file; 93 94 my $contents = $tmpl->load_file($file); 94 95 if (defined $contents) { … … 211 212 $ctx ||= $tmpl->context; 212 213 214 my ($timer, $start); 215 if (MT->config->PerformanceLogging) { 216 $timer = MT->get_timer(); 217 } 218 local $timer->{elapsed} = 0 if $timer; 219 213 220 local $ctx->{__stash}{template} = $tmpl; 214 221 my $tokens = $tmpl->tokens … … 243 250 $ctx->var( 'page_columns', $columns ) if $columns; 244 251 } 245 defined(my $res = $build->build($ctx, $tokens, $cond)) or 252 253 $timer->pause_partial if $timer; 254 255 my $res = $build->build($ctx, $tokens, $cond); 256 257 if ($timer) { 258 $timer->mark("MT::Template::build[" . ($tmpl->name || $tmpl->{__file}).']'); 259 } 260 261 unless (defined($res)) { 246 262 return $tmpl->error(MT->translate( 247 263 "Publish error in template '[_1]': [_2]", 248 264 $tmpl->name || $tmpl->{__file}, $build->errstr)); 265 } 249 266 $res =~ s/^\s*//; 250 267 return $res; branches/release-30/lib/MT/WeblogPublisher.pm
r1365 r1372 1210 1210 my ( $blog, $root_path, $map, $at, $ctx, $cond, $build_static, %specifier ) 1211 1211 = @_; 1212 1212 1213 my $finfo; 1213 1214 my $archiver = $mt->archiver($at); … … 1408 1409 return 1 if ( $tmpl->build_dynamic ); 1409 1410 return 1 if ( $entry && $entry->status != MT::Entry::RELEASE() ); 1411 1412 my $timer = MT->get_timer; 1413 if ($timer) { 1414 $timer->pause_partial; 1415 } 1416 local $timer->{elapsed} = 0 if $timer; 1410 1417 1411 1418 if ( … … 1451 1458 1452 1459 $html = $tmpl->build( $ctx, $cond ); 1453 defined($html) 1454 or return $mt->error( 1460 unless (defined($html)) { 1461 $timer->unpause if $timer; 1462 return $mt->error( 1455 1463 ( 1456 1464 $category ? MT->translate( … … 1473 1481 ) 1474 1482 ); 1483 } 1475 1484 my $orig_html = $html; 1476 1485 MT->run_callbacks( … … 1506 1515 ## changed. If not, we won't update the published 1507 1516 ## file, so as not to modify the mtime. 1508 return 1 unless $fmgr->content_is_updated( $file, \$html ); 1517 unless ($fmgr->content_is_updated( $file, \$html )) { 1518 $timer->unpause if $timer; 1519 return 1; 1520 } 1509 1521 1510 1522 ## Determine if we need to build directory structure, … … 1516 1528 unless $path eq '/'; ## OS X doesn't like / at the end in mkdir(). 1517 1529 unless ( $fmgr->exists($path) ) { 1518 $fmgr->mkpath($path) 1519 or return $mt->trans_error( "Error making path '[_1]': [_2]", 1520 $path, $fmgr->errstr ); 1530 if (!$fmgr->mkpath($path)) { 1531 $timer->unpause if $timer; 1532 return $mt->trans_error( "Error making path '[_1]': [_2]", 1533 $path, $fmgr->errstr ); 1534 } 1521 1535 } 1522 1536 … … 1528 1542 my $use_temp_files = !$mt->{NoTempFiles}; 1529 1543 my $temp_file = $use_temp_files ? "$file.new" : $file; 1530 defined( $fmgr->put_data( $html, $temp_file ) ) 1531 or return $mt->trans_error( "Writing to '[_1]' failed: [_2]", 1532 $temp_file, $fmgr->errstr ); 1544 unless ( defined $fmgr->put_data( $html, $temp_file ) ) { 1545 $timer->unpause if $timer; 1546 return $mt->trans_error( "Writing to '[_1]' failed: [_2]", 1547 $temp_file, $fmgr->errstr ); 1548 } 1533 1549 if ($use_temp_files) { 1534 $fmgr->rename( $temp_file, $file ) 1535 or return $mt->trans_error( 1536 "Renaming tempfile '[_1]' failed: [_2]", 1537 $temp_file, $fmgr->errstr ); 1550 if (!$fmgr->rename( $temp_file, $file )) { 1551 $timer->unpause if $timer; 1552 return $mt->trans_error( 1553 "Renaming tempfile '[_1]' failed: [_2]", 1554 $temp_file, $fmgr->errstr ); 1555 } 1538 1556 } 1539 1557 MT->run_callbacks( … … 1568 1586 1569 1587 } 1588 $timer->mark("total:rebuild_file[template_id:" . $tmpl->id . "]") 1589 if $timer; 1570 1590 1; 1571 1591 } … … 1689 1709 $finfo->save(); 1690 1710 } 1711 1712 my $timer = MT->get_timer; 1713 if ($timer) { 1714 $timer->pause_partial; 1715 } 1716 local $timer->{elapsed} = 0 if $timer; 1691 1717 1692 1718 my $ctx = MT::Template::Context->new; … … 1715 1741 1716 1742 my $html = $tmpl->build($ctx); 1717 return $mt->error( $tmpl->errstr ) unless defined $html; 1743 unless (defined $html) { 1744 $timer->unpause if $timer; 1745 return $mt->error( $tmpl->errstr ); 1746 } 1718 1747 1719 1748 my $orig_html = $html; … … 1752 1781 unless $path eq '/'; ## OS X doesn't like / at the end in mkdir(). 1753 1782 unless ( $fmgr->exists($path) ) { 1754 $fmgr->mkpath($path) 1755 or return $mt->trans_error( "Error making path '[_1]': [_2]", 1756 $path, $fmgr->errstr ); 1783 if (! $fmgr->mkpath($path) ) { 1784 $timer->unpause if $timer; 1785 return $mt->trans_error( "Error making path '[_1]': [_2]", 1786 $path, $fmgr->errstr ); 1787 } 1757 1788 } 1758 1789 … … 1760 1791 my $use_temp_files = !$mt->{NoTempFiles}; 1761 1792 my $temp_file = $use_temp_files ? "$file.new" : $file; 1762 defined( $fmgr->put_data( $html, $temp_file ) ) 1763 or return $mt->trans_error( "Writing to '[_1]' failed: [_2]", 1764 $temp_file, $fmgr->errstr ); 1793 unless (defined( $fmgr->put_data( $html, $temp_file ) )) { 1794 $timer->unpause if $timer; 1795 return $mt->trans_error( "Writing to '[_1]' failed: [_2]", 1796 $temp_file, $fmgr->errstr ); 1797 } 1765 1798 if ($use_temp_files) { 1766 $fmgr->rename( $temp_file, $file ) 1767 or 1768 return $mt->trans_error( "Renaming tempfile '[_1]' failed: [_2]", 1769 $temp_file, $fmgr->errstr ); 1799 if (!$fmgr->rename( $temp_file, $file )) { 1800 $timer->unpause if $timer; 1801 return $mt->trans_error( "Renaming tempfile '[_1]' failed: [_2]", 1802 $temp_file, $fmgr->errstr ); 1803 } 1770 1804 } 1771 1805 MT->run_callbacks( … … 1790 1824 file => $file 1791 1825 ); 1826 1827 $timer->mark("total:rebuild_indexes[template_id:" . $tmpl->id . ";file:$file]") 1828 if $timer; 1792 1829 } 1793 1830 1;
