gc_tracer 1.2.1 → 1.3.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: f51c53293509fec6925050bd2a7777d21a7e5c5f
4
- data.tar.gz: ee101027412970ae77e73377e06218da4b00033a
3
+ metadata.gz: fc71d8de7bf981a27b8cb3859ed6134fd275d2ec
4
+ data.tar.gz: 25ab4eee36db92b7280d2a270556e7b3ea699af9
5
5
  SHA512:
6
- metadata.gz: 506e6d6ed2206e9e03ba8081434eac2a33472c1cb0c911d9a917db0a571c7890e43ca6ea3ebb572467dae54c02e31cc817e0f0c611d64c070417e4679dcc1628
7
- data.tar.gz: 803962c62b75c2f97994705e12452e3e2682e1de434d165f3d531615e6bf997ba5d306b3ad64d763cf1b7d89e3b049ea03dd6828e82caeaad0ff8c4c56dd1787
6
+ metadata.gz: f85092b780785d3a414b1343e5542516446f507485c7d3304a4e2ffa81c3101010ed4cf11bd5bb4693b72e066be8e66f45787b0eb3502ff72c68f816bb4f8c6a
7
+ data.tar.gz: 95e5f65dcd28c70365241b3b5e7c622b243307265b4ed86767881c6a99a2da981eba3dfe7e9e2635233c767372ee7ead5ad6fe0877c5ec8300dcf451342b3649
data/README.md CHANGED
@@ -50,6 +50,10 @@ ensure
50
50
  end
51
51
  ```
52
52
 
53
+ If `ENV['GC_TRACER_LOGFILE']` is given, then this value and `pid` (concatenated with '-') is used as filename.
54
+
55
+ If filename is not given, then all of logs puts onto `stderr`.
56
+
53
57
  ### Setup
54
58
 
55
59
  In the stored file (filename), you can get tab separated values of:
@@ -57,6 +61,7 @@ In the stored file (filename), you can get tab separated values of:
57
61
  * `GC.stat()`
58
62
  * `GC.latest_gc_info()`
59
63
  * `getrusage()` (if supported by system)
64
+ * Custom fields (described bloew)
60
65
 
61
66
  at each events, there are one of:
62
67
 
@@ -152,6 +157,29 @@ This method is useful to trace where the GC events occur in your
152
157
  application.
153
158
 
154
159
 
160
+ ## Rack middleware
161
+
162
+ You can insert Rack middleware to record and view GC Tracer log.
163
+
164
+ ```ruby
165
+ require 'rack'
166
+ require 'sinatra'
167
+ require 'rack/gc_tracer'
168
+
169
+ use Rack::GCTracerMiddleware, view_page_path: '/gc_tracer'
170
+
171
+ get '/' do
172
+ 'foo'
173
+ end
174
+ ```
175
+
176
+ You can pass two options.
177
+
178
+ * logging_filename: File name of GC Tracer log
179
+ * 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
+
181
+ And also you can pass all options (except filename) of `GC::Tracer.start_logging`.
182
+
155
183
  ## Contributing
156
184
 
157
185
  1. Fork it ( http://github.com/ko1/gc_tracer/fork )
@@ -138,6 +138,12 @@ out_terminate(FILE *out)
138
138
  fprintf(out, "\n");
139
139
  }
140
140
 
141
+ static void
142
+ out_flush(FILE *out)
143
+ {
144
+ fflush(out);
145
+ }
146
+
141
147
  static void
142
148
  out_sizet(FILE *out, size_t size)
143
149
  {
@@ -683,6 +689,20 @@ gc_tracer_stop_logging(VALUE self)
683
689
  return self;
684
690
  }
685
691
 
692
+ static VALUE
693
+ gc_tracer_flush_logging(VALUE self)
694
+ {
695
+ struct gc_logging *logging = &trace_logging;
696
+
697
+ if (logging->enabled) {
698
+ out_flush(logging->out);
699
+ }
700
+ else {
701
+ rb_raise(rb_eRuntimeError, "GC tracer is not enabled.");
702
+ }
703
+ return self;
704
+ }
705
+
686
706
  static VALUE
687
707
  gc_tracer_custom_event_logging(VALUE self, VALUE event_str)
688
708
  {
@@ -703,6 +723,7 @@ Init_gc_tracer_logging(VALUE mod)
703
723
  {
704
724
  rb_define_module_function(mod, "start_logging_", gc_tracer_start_logging, 0);
705
725
  rb_define_module_function(mod, "stop_logging", gc_tracer_stop_logging, 0);
726
+ rb_define_module_function(mod, "flush_logging", gc_tracer_flush_logging, 0);
706
727
 
707
728
  /* setup */
708
729
  rb_define_module_function(mod, "setup_logging_out", gc_tracer_setup_logging_out, 1);
data/lib/gc_tracer.rb CHANGED
@@ -3,6 +3,14 @@ require 'gc_tracer/gc_tracer'
3
3
 
4
4
  module GC
5
5
  module Tracer
6
+ def self.env_logging_filename
7
+ if fn = ENV['GC_TRACER_LOGFILE']
8
+ "#{fn}-#{Process.pid}"
9
+ else
10
+ nil
11
+ end
12
+ end
13
+
6
14
  def self.start_logging(filename_opt = nil,
7
15
  filename: nil,
8
16
  # event filter
@@ -17,7 +25,7 @@ module GC
17
25
  )
18
26
  # setup
19
27
  raise "do not specify two fienames" if filename && filename_opt
20
- setup_logging_out(filename_opt || filename)
28
+ setup_logging_out(filename_opt || filename || env_logging_filename)
21
29
  setup_logging_events(*events)
22
30
 
23
31
  self.setup_logging_gc_stat = gc_stat
@@ -1,3 +1,3 @@
1
1
  module GC::Tracer
2
- VERSION = "1.2.1"
2
+ VERSION = "1.3.0"
3
3
  end
@@ -0,0 +1,28 @@
1
+ #
2
+ # Rack middleware
3
+ #
4
+
5
+ require 'gc_tracer'
6
+
7
+ module Rack
8
+ class GCTracerMiddleware
9
+ def initialize app, view_page_path: nil, logging_filename: nil, **kw
10
+ @app = app
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
14
+ GC::Tracer.start_logging @logging_filename, custom_fields: %i(accesses), **kw
15
+ end
16
+
17
+ def call env
18
+ if @has_view_page && env["PATH_INFO"] == @has_view_page
19
+ GC::Tracer.flush_logging
20
+ [200, {"Content-Type" => "text/plain"}, [open(@logging_filename).read]]
21
+ else
22
+ GC::Tracer.custom_field_increment(0)
23
+ @app.call(env)
24
+ end
25
+ end
26
+ end
27
+ end
28
+
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.2.1
4
+ version: 1.3.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-13 00:00:00.000000000 Z
11
+ date: 2015-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -90,6 +90,7 @@ files:
90
90
  - lib/gc_tracer/allocation_trace.rb
91
91
  - lib/gc_tracer/version.rb
92
92
  - lib/gc_tracer/viewer.html.erb
93
+ - lib/rack/gc_tracer.rb
93
94
  - public/jquery-2.1.0.min.js
94
95
  - spec/gc_tracer_spec.rb
95
96
  - spec/spec_helper.rb