Module: Kiss::Bench

Defined in:
lib/kiss/bench.rb

Overview

Generates HTML reports on exceptions raised from the app, showing the backtrace with clickable stack frames with TextMate links to source files, plus login hash, last SQL, GET/POST params, cookies, and Rack environment variables.

Instance Method Summary collapse

Instance Method Details



54
55
56
57
58
59
60
# File 'lib/kiss/bench.rb', line 54

def context_link(context)
  return nil unless context
  
  filename, line, method = context.split(/:/)
  textmate_url = "txmt://open?url=file://" + (Kiss.absolute_path(filename).html_escape) + '&line=' + line
  %Q(<a href="#{textmate_url}">#{filename}:#{line}</a> #{method})
end

#prepend_benchmarks(document) ⇒ Object



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
# File 'lib/kiss/bench.rb', line 7

def prepend_benchmarks(document)
  html = <<-EOT
<style>
.kiss_bench {
  text-align: left;
  padding: 3px 7px;
  border: 1px solid #ec4;
  border-top: 1px solid #fff4bb;
  border-bottom: 1px solid #d91;
  background-color: #ffe590;
  font-size: 12px;
  color: #101;
}
.kiss_bench a {
  color: #930;
  text-decoration: none;
}
.kiss_bench a:hover {
  color: #930;
  text-decoration: underline;
}
.kiss_bench small {
  font-family: arial, sans-serif;
  color: #a60;
  float: right;
  margin-left: 8px;
  position: relative;
  text-align: right;
  white-space: nowrap;
}
</style>
EOT
  html += @_benchmarks.map do |item|
    start_link = context_link(item[:start_context])
    end_link = context_link(item[:end_context])
    
    <<-EOT
<div class="kiss_bench">
<small style="line-height: 105%; display: block; top: -4px">kiss bench started at #{start_link}<br/>ended at #{end_link || 'request completion'}</small>
<tt><b>#{(item[:label] || 'unlabeled bench').to_s.gsub(/\</, '&lt;')} - duration: #{sprintf("%0.3f", item[:end_time].to_f - item[:start_time].to_f)} s</b></tt>
</div>
EOT
  end.join
  
  document.prepend_html(html, 'body')
end