github.com/bhojpur/cache@v0.0.4/templates/page.ego (about) 1 <%! func Page(w io.Writer, r *http.Request, tx *memcache.Tx, indexes []int, directID int, showUsage bool) error %> 2 3 <%% import "net/http" %%> 4 <%% import "strings" %%> 5 <%% import "unsafe" %%> 6 <%% import memcache "github.com/bhojpur/cache/pkg/memory" %%> 7 8 <% 9 p, ids, err := find(tx, directID, indexes) 10 if err != nil { 11 return err 12 } 13 14 // Generate page stats. 15 pageSize := tx.DB().Info().PageSize 16 stats := p.stats(pageSize) 17 18 // Generate histogram of all nested page usage. 19 var histogram map[int]int 20 if showUsage { 21 histogram = usage(tx, p.id) 22 } 23 %> 24 25 <!DOCTYPE html> 26 <html lang="en"> 27 <% head(w, tx) %> 28 29 <body> 30 <% nav(w, tx) %> 31 32 <h2> 33 <% for i, id := range ids { %> 34 <% if i > 0 { %>»<% } %> 35 <a href="<%= pagelink(indexes[:i+1]) %>">#<%= id %></a> 36 <% } %> 37 </h2> 38 39 <h3>Page Information</h3> 40 <p> 41 <strong>ID:</strong> <%= comma(int(p.id)) %><br/> 42 <strong>Type:</strong> <%= fmt.Sprintf("%s (%x)", p.typ(), p.flags) %><br/> 43 <strong>Overflow:</strong> <%= p.overflow %><br/><br/> 44 45 <strong>Alloc:</strong> <%= comma(stats.alloc) %><br/> 46 <strong>In Use:</strong> <%= comma(stats.inuse) %><br/> 47 <strong>Utilization:</strong> <%= fmt.Sprintf("%.2f%%", stats.utilization*100) %><br/> 48 </p> 49 50 <% if (p.flags & branchPageFlag) != 0 { %> 51 <h3>Branch Elements (<%= p.count %>)</h3> 52 <table> 53 <thead> 54 <tr> 55 <th align="left">Key</th> 56 <th align="left">Page ID</th> 57 <th align="left">Size (k)</th> 58 <th align="center">%%Util</th> 59 </tr> 60 </thead> 61 <tbody> 62 <% for i := uint16(0); i < p.count; i++ { %> 63 <% e := p.branchPageElement(i) %> 64 <% subpage := pageAt(tx, e.pgid) %> 65 <% substats := subpage.stats(pageSize) %> 66 <tr> 67 <td><%= trunc(tostr(e.key()), 40) %></td> 68 <td><a href="<%= subpagelink(indexes, int(i)) %>"><%= e.pgid %></a></td> 69 <td><%= len(e.key()) %></td> 70 <td align="right"><%= fmt.Sprintf("%.2f%%", substats.utilization*100) %></td> 71 </tr> 72 <% } %> 73 </tbody> 74 </table> 75 76 <% } else if (p.flags & leafPageFlag) != 0 { %> 77 <h3>Leaf Elements (<%= p.count %>)</h3> 78 <table> 79 <thead> 80 <tr> 81 <th align="left">Key</th> 82 <th align="left">Value</th> 83 <th align="left">Size (k/v)</th> 84 <th align="center">%%Util</th> 85 </tr> 86 </thead> 87 <tbody> 88 <% for i := uint16(0); i < p.count; i++ { %> 89 <% e := p.leafPageElement(i) %> 90 <% if (e.flags & bucketLeafFlag) != 0 { %> 91 <% b := ((*bucket)(unsafe.Pointer(&e.value()[0]))) %> 92 <% 93 util := "-" 94 if b.root != 0 { 95 substats := pageAt(tx, b.root).stats(pageSize) 96 util = fmt.Sprintf("%.2f%%", substats.utilization*100) 97 } 98 %> 99 <tr> 100 <td><strong><%= trunc(tostr(e.key()), 40) %></strong></td> 101 <td> 102 <bucket(root=<% if b.root != 0 { %><a href="<%= subpagelink(indexes, int(i)) %>"><% } %><%= b.root %><% if b.root != 0 { %></a><% } %>; seq=<%= b.sequence %>)> 103 </td> 104 <td><%= len(e.key()) %> / <%= len(e.value()) %></td> 105 <td align="right"><%= util %></td> 106 </tr> 107 <% } else { %> 108 <tr> 109 <td><%= trunc(tostr(e.key()), 40) %></td> 110 <td><%= trunc(tostr(e.value()), 40) %></td> 111 <td><%= len(e.key()) %> / <%= len(e.value()) %></td> 112 <td> </td> 113 </tr> 114 <% } %> 115 <% } %> 116 </tbody> 117 </table> 118 <% } %> 119 120 <% if showUsage { %> 121 <% 122 mins, maxs, values := bucketize(histogram) 123 vmax, maxlen := 0, 20 124 for _, v := range values { 125 if v > vmax { 126 vmax = v 127 } 128 } 129 %> 130 131 <h3>Page Usage Histogram</h3> 132 <table> 133 <thead> 134 <tr> 135 <th align="left">Usage (bytes)</th> 136 <th align="left">Count</th> 137 <th> </th> 138 </tr> 139 </thead> 140 <tbody> 141 <% for i := 0; i < len(values); i++ { %> 142 <tr> 143 <td><%= mins[i] %> - <%= maxs[i] %></th> 144 <td><%= values[i] %></th> 145 <td><%= strings.Repeat("█", int((float64(values[i])/float64(vmax))*float64(maxlen))) %></td> 146 </tr> 147 <% } %> 148 </tbody> 149 </table> 150 <% } else { %> 151 <% 152 u, q := r.URL, r.URL.Query() 153 q.Set("usage", "true") 154 u.RawQuery = q.Encode() 155 %> 156 157 <p><a href="<%= u.String() %>">Show Page Usage</a></p> 158 <% } %> 159 160 <br/><br/> 161 <form action="page" method="GET"> 162 Go to page: <input type="text" name="id"/> 163 <button type="submit">Go</button> 164 </form> 165 <hr size="1px"> 166 <center>Copyright © 2018 by <a href="https://www.bhojpur-consulting.com">Bhojpur Consulting Private Limited</a>, India. All rights reserved.</center> 167 </body> 168 </html>