gc_tracer 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fc71d8de7bf981a27b8cb3859ed6134fd275d2ec
4
- data.tar.gz: 25ab4eee36db92b7280d2a270556e7b3ea699af9
3
+ metadata.gz: edb39709fa72ef674a41795d9a73c87ea8627d12
4
+ data.tar.gz: b6a6305de8e33f50ab78877f6cb5b0e7eef60e68
5
5
  SHA512:
6
- metadata.gz: f85092b780785d3a414b1343e5542516446f507485c7d3304a4e2ffa81c3101010ed4cf11bd5bb4693b72e066be8e66f45787b0eb3502ff72c68f816bb4f8c6a
7
- data.tar.gz: 95e5f65dcd28c70365241b3b5e7c622b243307265b4ed86767881c6a99a2da981eba3dfe7e9e2635233c767372ee7ead5ad6fe0877c5ec8300dcf451342b3649
6
+ metadata.gz: 33183d39bbf2a0a1a4648334d5d101ccc0101b211e555f662c840a78cfb561bfc173397c0e111922911540b6f6fa2fc4fa35105e4e06fbdc8bea03f24809bce1
7
+ data.tar.gz: 21c11cd481b69ba3aceacb08f434d7b3bf3158390cb22bda7a5aeac29a033ce02bd3eb762d6469b4104c5ac68fa790f50ceeecb006ce274778d739afd22a13ae
data/README.md CHANGED
@@ -166,19 +166,24 @@ require 'rack'
166
166
  require 'sinatra'
167
167
  require 'rack/gc_tracer'
168
168
 
169
- use Rack::GCTracerMiddleware, view_page_path: '/gc_tracer'
169
+ use Rack::GCTracerMiddleware, view_page_path: '/gc_tracer', filename: 'logging_file_name'
170
170
 
171
171
  get '/' do
172
172
  'foo'
173
173
  end
174
174
  ```
175
175
 
176
+ In this case, you can access two pages.
177
+
178
+ * http://host/gc_tracer - HTML table style page
179
+ * http://host/gc_tracer/text - plain text page
180
+
176
181
  You can pass two options.
177
182
 
178
- * logging_filename: File name of GC Tracer log
183
+ * filename: File name of GC Tracer log
179
184
  * view_page_path: You can view GC tracer log with this path *if logging_filename is given*. You should not use this option on production.
180
185
 
181
- And also you can pass all options (except filename) of `GC::Tracer.start_logging`.
186
+ And also you can pass all options of `GC::Tracer.start_logging`.
182
187
 
183
188
  ## Contributing
184
189
 
@@ -1,3 +1,3 @@
1
1
  module GC::Tracer
2
- VERSION = "1.3.0"
2
+ VERSION = "1.4.0"
3
3
  end
@@ -6,18 +6,42 @@ require 'gc_tracer'
6
6
 
7
7
  module Rack
8
8
  class GCTracerMiddleware
9
- def initialize app, view_page_path: nil, logging_filename: nil, **kw
9
+ def initialize app, view_page_path: nil, filename: nil, **kw
10
10
  @app = app
11
11
  @view_page_path = view_page_path
12
- @logging_filename = logging_filename || GC::Tracer.env_logging_filename
13
- @has_view_page = @logging_filename && @view_page_path
12
+ @logging_filename = filename || GC::Tracer.env_logging_filename
13
+
14
+ if @logging_filename && view_page_path
15
+ @view_page_pattern = /\A#{view_page_path}/
16
+ else
17
+ @view_page_pattern = nil
18
+ end
19
+
14
20
  GC::Tracer.start_logging @logging_filename, custom_fields: %i(accesses), **kw
15
21
  end
16
22
 
23
+ def make_page
24
+ header = data = nil
25
+ open(@logging_filename){|f|
26
+ header = f.gets
27
+ data = f.readlines
28
+ }
29
+ headers = "<tr>" + header.split(/\s+/).map{|e| "<th>#{e}</th>"}.join("\n") + "</tr>"
30
+ data = data.map{|line|
31
+ "<tr>" + line.split(/\s+/).map{|e| "<td>#{e}</td>"}.join + "</td>"
32
+ }.join("\n")
33
+ "<table>#{headers}\n#{data}</table>"
34
+ end
35
+
17
36
  def call env
18
- if @has_view_page && env["PATH_INFO"] == @has_view_page
37
+ if @view_page_pattern && @view_page_pattern =~ env["PATH_INFO"]
19
38
  GC::Tracer.flush_logging
20
- [200, {"Content-Type" => "text/plain"}, [open(@logging_filename).read]]
39
+ p env["PATH_INFO"]
40
+ if env["PATH_INFO"] == @view_page_path + "/text"
41
+ [200, {"Content-Type" => "text/plain"}, [open(@logging_filename).read]]
42
+ else
43
+ [200, {"Content-Type" => "text/html"}, [make_page]]
44
+ end
21
45
  else
22
46
  GC::Tracer.custom_field_increment(0)
23
47
  @app.call(env)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gc_tracer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Koichi Sasada
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-14 00:00:00.000000000 Z
11
+ date: 2015-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler