/usr/bin/wg-classLoadTest is in webgui 7.10.28-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | #!/usr/bin/perl
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2009 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
use strict;
use File::Basename ();
use File::Spec;
my $webguiRoot;
BEGIN {
$webguiRoot = '/usr/share/webgui';
unshift @INC, File::Spec->catdir($webguiRoot, 'lib');
}
$|++; # disable output buffering
our ($configFile, $help, $man, $class);
use Pod::Usage;
use Getopt::Long;
use WebGUI::Session;
# Get parameters here, including $help
GetOptions(
'configFile=s' => \$configFile,
'help' => \$help,
'man' => \$man,
'class=s' => \$class,
);
pod2usage( verbose => 1 ) if $help;
pod2usage( verbose => 2 ) if $man;
pod2usage( msg => "Must specify a config file!" ) unless $configFile;
foreach my $libDir ( readLines( "/etc/webgui/preload.custom" ) ) {
if ( !-d $libDir ) {
warn "WARNING: Not adding lib directory '$libDir' from /etc/webgui/preload.custom: Directory does not exist.\n";
next;
}
unshift @INC, $libDir;
}
my $session = start( $webguiRoot, $configFile );
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 $webguiRoot = shift;
my $configFile = shift;
my $session = WebGUI::Session->open($webguiRoot,$configFile);
$session->user({userId=>3});
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;
}
__END__
=head1 NAME
classLoadTest.pl -- Test a single class performance
=head1 SYNOPSIS
classLoadTest.pl --configFile config.conf --class=<>
classLoadTest.pl --help
=head1 DESCRIPTION
This script will test the time it takes to instanciate and view all the
assets of a particular class from the given site.
=head1 OPTIONS
=over
=item B<--configFile config.conf>
The WebGUI config file to use. Only the file name needs to be specified,
since it will be looked up inside WebGUI's configuration directory.
This parameter is required.
=item B<--class>
The full class name of the asset to test. Something like WebGUI::Asset::Wobject::Layout
or WebGUI::Asset::Wobject::Navigation.
=item B<--help>
Shows a short summary and usage
=item B<--man>
Shows this document
=back
=head1 AUTHOR
Copyright 2001-2009 Plain Black Corporation.
=cut
#vim:ft=perl
|