16 # Documentation browser under "/perldoc"
21 $self->render('index');
24 get '/jit_tree/:id/:depth' => sub {
26 my $id = $self->stash('id');
27 my $depth = $self->stash('depth');
28 warn "jit_tree $id $depth";
29 my $node_tree = _fetch_node_tree($id, $depth);
30 my $jit_tree = _transform_node_tree($node_tree, sub {
32 my $children = delete $node->{children}; # XXX edits the src tree
33 $node->{'$area'} = $node->{self_size}+$node->{kids_size};
36 name => $node->{name},
39 $jit_node->{children} = $children if $children;
44 use Data::Dump qw(pp);
45 local $jit_tree->{children};
48 $self->render_json($jit_tree);
51 sub _fetch_node_tree {
52 my ($id, $depth) = @_;
53 my $node = MemView->selectrow_hashref("select * from node where id = ?", undef, $id)
54 or die "Node '$id' not found";
55 if ($node->{child_seqns}) {
56 my @child_seqns = split /,/, $node->{child_seqns};
58 if (@child_seqns == 1) {
59 my $child = _fetch_node_tree($child_seqns[0], $depth); # same depth
60 # merge node into child
61 # XXX id, depth, parent_seqn
62 warn "Merged $node->{name} #$node->{id} with only child $child->{name} #$child->{id}\n";
63 $child->{name} = "$node->{name} + $child->{name}";
64 $child->{$_} += $node->{$_} for (qw(self_size));
65 $child->{$_} = $node->{$_} for (qw(parent_seqn));
69 $children = [ map { _fetch_node_tree($_, $depth-1) } @child_seqns ];
70 $node->{children} = $children;
71 $node->{child_count} = @$children;
77 sub _transform_node_tree { # recurse depth first
78 my ($node, $transform) = @_;
79 if (my $children = $node->{children}) {
80 $_ = _transform_node_tree($_, $transform) for @$children;
82 return $transform->($node);
91 Welcome to the Mojolicious real-time web framework!
93 @@ layouts/default.html.ep
96 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
97 <title>Perl Memory Treemap</title>
100 <link type="text/css" href="css/base.css" rel="stylesheet" />
101 <link type="text/css" href="css/Treemap.css" rel="stylesheet" />
103 <!--[if IE]><script language="javascript" type="text/javascript" src="excanvas.js"></script><![endif]-->
105 <!-- JIT Library File -->
106 <script language="javascript" type="text/javascript" src="jit.js"></script>
107 <script language="javascript" type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
109 <!-- Example File -->
110 <script language="javascript" type="text/javascript" src="sprintf.js"></script>
111 <script language="javascript" type="text/javascript" src="tm.js"></script>
114 <body onload="init();">
117 <div id="left-container">
123 Clicking on a node will show a new TreeMap with the contents of that node.<br /><br />
126 <a id="back" href="#" class="theme button white">Go to Parent</a>
129 <div id="center-container">
130 <div id="infovis"></div>
133 <div id="right-container">
135 <div id="inner-details"></div>