line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CGI::Application::Plugin::DBIProfile::Graph::HTML; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
2067
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
37
|
|
4
|
1
|
|
|
1
|
|
5
|
use HTML::Template; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
5
|
1
|
|
|
1
|
|
25
|
use List::Util qw(max); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
690
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# setup colors, generated by |
8
|
|
|
|
|
|
|
# http://wellstyled.com/tools/colorscheme/index-en.html |
9
|
|
|
|
|
|
|
our @BARS = qw( 2856E0 8DA6F0 C5D1F7 445896 222C4B 687AB0 9FA9C8 |
10
|
|
|
|
|
|
|
FFAB2E FFD596 FFEACB AA854D 554227 BFA071 DFCDB1 ); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub build_graph |
13
|
|
|
|
|
|
|
{ |
14
|
0
|
|
|
0
|
0
|
|
my $proto = shift; |
15
|
0
|
|
0
|
|
|
|
my $class = ref($proto) || $proto; |
16
|
|
|
|
|
|
|
|
17
|
0
|
|
|
|
|
|
my %opts = @_; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
#my $self = { }; |
20
|
|
|
|
|
|
|
#bless $self, $class; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
0
|
|
0
|
|
|
|
$opts{data} ||= []; |
24
|
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
|
our @BARS; |
26
|
0
|
|
|
|
|
|
my @bars = map { "#$_" } @BARS; |
|
0
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
|
28
|
0
|
|
|
|
|
|
my $stmt_count = @{$opts{data}}; |
|
0
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
|
my $title = "Top $stmt_count statements"; # by total runtime |
30
|
0
|
|
|
|
|
|
my $tag = 1; |
31
|
0
|
|
|
|
|
|
my $tags = [ map { $tag++ } @{$opts{data}} ]; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
my %defs = ( |
34
|
|
|
|
|
|
|
tags => $tags, |
35
|
|
|
|
|
|
|
data => [], |
36
|
|
|
|
|
|
|
title => $title, |
37
|
|
|
|
|
|
|
ylabel => '', |
38
|
|
|
|
|
|
|
barlength => 150, |
39
|
|
|
|
|
|
|
barwidth => 10, |
40
|
|
|
|
|
|
|
barcolors => \@bars, |
41
|
|
|
|
|
|
|
); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# merge options with defaults. |
44
|
0
|
|
|
|
|
|
%opts = (%defs, map { $_ => $opts{$_} } |
|
0
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
grep { defined $opts{$_} } |
46
|
|
|
|
|
|
|
keys %opts ); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# rotate ylabel |
49
|
0
|
|
|
|
|
|
$opts{ylabel} = join ' ', split(//, $opts{ylabel}); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# get max value from dataset (XXX doesn't support negative values) |
52
|
0
|
|
0
|
|
|
|
my $maxval = max(@{$opts{data}}) || 1; |
53
|
|
|
|
|
|
|
# ratio of barlenth to values |
54
|
0
|
|
|
|
|
|
my $ratio = $opts{barlength} / $maxval; |
55
|
|
|
|
|
|
|
# all bar lengths |
56
|
0
|
0
|
|
|
|
|
my @barlength = map { $_ || 1 } |
|
0
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
map { sprintf('%0.0f', ($_ * $ratio)) } |
58
|
0
|
|
|
|
|
|
@{$opts{data}}; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# build data for HTML::Template |
61
|
0
|
|
|
|
|
|
my $cols = []; |
62
|
0
|
|
|
|
|
|
for (my $i=0; $i<@barlength; $i++) { |
63
|
0
|
|
|
|
|
|
push(@$cols, { |
64
|
|
|
|
|
|
|
tag => $opts{tags}->[$i], |
65
|
|
|
|
|
|
|
value => $opts{data}->[$i], |
66
|
|
|
|
|
|
|
barlength => $barlength[$i], |
67
|
|
|
|
|
|
|
barwidth => $opts{barwidth}, |
68
|
0
|
|
|
|
|
|
barcolor => $opts{barcolors}[ $i % scalar @{$opts{barcolors}} ], |
69
|
|
|
|
|
|
|
}); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
my $TEMPLATE = <
|
74
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
TMPL |
104
|
|
|
|
|
|
|
|
105
|
0
|
|
|
|
|
|
my $t = HTML::Template->new(scalarref => \$TEMPLATE, |
106
|
|
|
|
|
|
|
loop_context_vars => 1, |
107
|
|
|
|
|
|
|
die_on_bad_params => 0, ); |
108
|
0
|
|
|
|
|
|
$t->param('title' => $opts{title}); |
109
|
0
|
|
|
|
|
|
$t->param('ylabel' => $opts{ylabel}); |
110
|
0
|
|
|
|
|
|
$t->param('cols' => $cols); |
111
|
|
|
|
|
|
|
|
112
|
0
|
|
|
|
|
|
return $t->output; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
1; |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
__END__ |