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