CGI-Application-Plugin-DBIProfile
view release on metacpan or search on metacpan
lib/CGI/Application/Plugin/DBIProfile.pm view on Meta::CPAN
my %opts = @_;
my $nodes = $opts{nodes};
my $number = $opts{number};
my $sort = $opts{sort};
my $index = $sort eq 'count' ? 0 :
$sort eq 'total' ? 1 :
$sort eq 'shortest'? 3 :
$sort eq 'longest' ? 4 : die "Unknown sort '$sort'";
my $title = _page_title($self, %opts);
my $data = [ map { $nodes->[$_][$index] } (0 .. $#$nodes) ];
my $tag = 1;
my $tags = [ map { $tag++ } @$data ];
# load graphing plugin, and run it.
my $graph_plug = _load_graph_module ($self);
my $graph = $graph_plug->build_graph(
self => $self,
mode_param => $self->mode_param,
title => $title,
ylabel => $sort eq 'count' ? 'Count' : 'Seconds',
data => $data,
tags => $tags,
);
warn "Unable to build graph." unless defined $graph;
return ref($graph) ? $$graph : $graph || "";
}
sub _load_graph_module
{
my $self = shift;
my $module = $ENV{CAP_DBIPROFILE_GRAPHMODULE};
$module ||= 'CGI::Application::Plugin::DBIProfile::Graph::HTML';
eval "require $module";
if ($@)
{
die "CAP::DBIProfile: Unable to load graphing module \"$module\": $@";
}
return $module;
}
our $TEMPLATE2 = <<END2;
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>CGI::Application::Plugin::DBIProfile Profiling Screen</title>
<style type="text/css">
div.report { border: dotted 1px black; margin: 1em;}
div.report h2 { color: #000; background-color: #ddd; padding:.2em; margin-top:0;}
div.report_full, div.report_summary { padding: 0em 1em; }
a:hover, div.report h2:hover { cursor: pointer; background-color: #eee; }
a { text-decoration: underline }
</style>
<script language="javascript"><!--
function swap(id1,id2)
{
var d1 = document.getElementById(id1);
var d2 = document.getElementById(id2);
var s = d1.style.display;
d1.style.display = d2.style.display;
d2.style.display = s;
}
// --></script>
</head>
<body onload="swap('#DBIPS_count', '#DBIPR_count');">
<div class="report">
<tmpl_var page_body>
</div>
</body></html>
END2
our $TEMPLATE = <<END;
<style type="text/css">
.legend_header {
background-color: #7187C7;
color: #FFF;
}
.legend_odd_row {
background-color: #FFF;
}
.legend_even_row {
background-color: #EEE;
}
</style>
<table border=0 cellspacing=0 cellpadding=0 width=100%>
<tr>
<td valign="top">
<tmpl_loop profile_pages>
<h2 onclick="swap('#DBIPS_<tmpl_var sort>', '#DBIPR_<tmpl_var sort>');"><tmpl_var profile_title></h2>
<div id="#DBIPS_<tmpl_var sort>" class="report_summary"></div>
<div id="#DBIPR_<tmpl_var sort>" class="report_full" style="display:none">
<span><tmpl_var profile_graph></span>
<table border=0 width=100% cellspacing=0 style="margin: 5px">
<tr>
<td class="legend_header" align="center">#</td>
<td class="legend_header" width="90%">SQL Statement</td>
( run in 2.096 seconds using v1.01-cache-2.11-cpan-cdf2f3d4e48 )