Created
August 3, 2010 18:44
-
-
Save plainblack/506900 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use lib "/data/WebGUI/lib"; | |
use strict; | |
use Getopt::Long; | |
use WebGUI::Session; | |
use Time::HiRes; | |
foreach my $libDir ( readLines( "/data/WebGUI/sbin/preload.custom" ) ) { | |
if ( !-d $libDir ) { | |
warn "WARNING: Not adding lib directory '$libDir' from /data/WebGUI/sbin/preload.custom: Directory does not exist.\n"; | |
next; | |
} | |
unshift @INC, $libDir; | |
} | |
my $class; | |
my $session = start(); | |
open(my $null, ">:utf8","/dev/null"); | |
$session->output->setHandle($null); | |
printf "%22s\t\%18s\t%12s\t%s\n", 'Asset ID', 'Instanciate Time', 'Render Time','URL'; | |
my $count = 0; | |
my $sth = $session->db->read("select assetId from asset where className=? and state='published'",[$class]); | |
while (my ($id) = $sth->array) { | |
$count++; | |
print $id; | |
# check instanciation time | |
my $t = [Time::HiRes::gettimeofday]; | |
my $asset = eval { WebGUI::Asset->new($session, $id, $class)}; | |
if (!defined $asset || $@) { | |
my $url = $session->db->quickScalar("select url from assetData where assetId=? order by revisionDate desc",[$id]); | |
print "\tbad asset: $@ \t url: $url \n"; | |
next; | |
} | |
my $instanciation = Time::HiRes::tv_interval($t); | |
# set the default asset for those things that need it | |
$session->asset($asset); | |
# check render time | |
$t = [Time::HiRes::gettimeofday]; | |
eval {my $junk = $asset->www_view}; | |
my $rendering = Time::HiRes::tv_interval($t); | |
if ($@) { | |
$rendering = $@; | |
} | |
# get the url | |
my $url = $asset->getValue("url"); | |
# output the results | |
printf "\t%18.4f\t%12.4f\t%s\n", $instanciation, $rendering ,$url; | |
} | |
close($null); | |
print "Total assets: $count\n"; | |
finish($session); | |
#------------------------------------------------- | |
sub start { | |
my $configFile; | |
$| = 1; #disable output buffering | |
GetOptions( | |
'configFile=s' => \$configFile, | |
'className=s' => \$class, | |
); | |
unless ($class && $configFile) { | |
print "Usage: perl $0 --config=www.example.com.conf --class=WebGUI::Asset::Wobject::SQLReport\n"; | |
exit; | |
} | |
my $session = WebGUI::Session->open("/data/WebGUI",$configFile); | |
return $session; | |
} | |
#------------------------------------------------- | |
sub finish { | |
my $session = shift; | |
$session->var->end; | |
$session->close; | |
} | |
#------------------------------------------------- | |
sub readLines { | |
my $file = shift; | |
my @lines; | |
if (open(my $fh, '<', $file)) { | |
while (my $line = <$fh>) { | |
$line =~ s/#.*//; | |
$line =~ s/^\s+//; | |
$line =~ s/\s+$//; | |
next if !$line; | |
push @lines, $line; | |
} | |
close $fh; | |
} | |
return @lines; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment