space_observatory 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +25 -0
- data/.rspec +4 -0
- data/.yardopts +2 -0
- data/Gemfile +27 -0
- data/LICENSE.txt +19 -0
- data/README.md +28 -0
- data/Rakefile +69 -0
- data/exec/with-space-observatory.rb +125 -0
- data/lib/space_observatory.rb +28 -0
- data/lib/space_observatory/base_station.rb +163 -0
- data/lib/space_observatory/version.rb +25 -0
- data/space_observatory.gemspec +54 -0
- metadata +198 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c33aabad489c6d4e3fe00a0d270daaf7694450aa
|
4
|
+
data.tar.gz: 2c22ce59b2d4d6c2aba4310d931261eae95f4d03
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5056147bf38a148f8a28c6a35af85f6a691b4073507291224ec8d45630cf1a9556da97e5788453fb2164369554e2a9bcfd8151016b018e76580af2909d3974e6
|
7
|
+
data.tar.gz: df671b5081f41a0418ccf499860cb7c16b7732a36de3b6a013ab5f04df857e3a61907515eccc4e47a9202f14eb76e4fca33e85c1faa335c6ad7d319c7ec3fa40
|
data/.gitignore
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
.ruby-version
|
7
|
+
Gemfile.lock
|
8
|
+
InstalledFiles
|
9
|
+
_yardoc
|
10
|
+
bin/
|
11
|
+
coverage
|
12
|
+
doc/
|
13
|
+
lib/bundler/man
|
14
|
+
pkg
|
15
|
+
rdoc
|
16
|
+
spec/reports
|
17
|
+
test/tmp
|
18
|
+
test/version_tmp
|
19
|
+
tmp
|
20
|
+
vendor/
|
21
|
+
*.bundle
|
22
|
+
*.so
|
23
|
+
*.o
|
24
|
+
*.a
|
25
|
+
mkmf.log
|
data/.rspec
ADDED
data/.yardopts
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
#! /your/favourite/path/to/bundler
|
2
|
+
# -*- coding: utf-8; mode: ruby; ruby-indent-level: 2 -*-
|
3
|
+
#
|
4
|
+
# Copyright (c) 2014 Urabe, Shyouhei
|
5
|
+
#
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
# of this software and associated documentation files (the "Software"), to deal
|
8
|
+
# in the Software without restriction, including without limitation the rights
|
9
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
# copies of the Software, and to permit persons to whom the Software is
|
11
|
+
# furnished to do so, subject to the following conditions:
|
12
|
+
#
|
13
|
+
# The above copyright notice and this permission notice shall be
|
14
|
+
# included in all copies or substantial portions of the Software.
|
15
|
+
#
|
16
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
22
|
+
# SOFTWARE.
|
23
|
+
|
24
|
+
source 'https://rubygems.org'
|
25
|
+
|
26
|
+
# Specify your gem's dependencies in space_observatory.gemspec
|
27
|
+
gemspec
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2014 Urabe, Shyouhei
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
4
|
+
this software and associated documentation files (the "Software"), to deal in
|
5
|
+
the Software without restriction, including without limitation the rights to
|
6
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
7
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
8
|
+
so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be
|
11
|
+
included in all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# SpaceObservatory
|
2
|
+
|
3
|
+
This is an easy add-on for you to observe your ObjectSpace.
|
4
|
+
|
5
|
+
## Main Features
|
6
|
+
|
7
|
+
- Pure ruby. NO C extensions.
|
8
|
+
- Drop-in design that requires NO modifications to your program.
|
9
|
+
- Minimal overhead. Does all jobs except data collection in a separate process.
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
As usual.
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
```bash
|
18
|
+
bundle exec with-space-observatory.rb --port=1234 -- ruby bin/rails server --port=5678
|
19
|
+
```
|
20
|
+
|
21
|
+
This command starts two HTTP servers on ports 1234 and 5678 each. 1234 (for this case) is for probing object space of rails server which listens port 5678.
|
22
|
+
|
23
|
+
`with-space-observatory.rb --help` might expose more option(s).
|
24
|
+
|
25
|
+
## TODOs
|
26
|
+
|
27
|
+
- Probing is slow. Should cache.
|
28
|
+
- JSON is valid, but not that pretty.
|
data/Rakefile
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
#! /your/favourite/path/to/rake
|
2
|
+
# -*- coding: utf-8; mode: ruby; ruby-indent-level: 2 -*-
|
3
|
+
#
|
4
|
+
# Copyright (c) 2014 Urabe, Shyouhei
|
5
|
+
#
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
# of this software and associated documentation files (the "Software"), to deal
|
8
|
+
# in the Software without restriction, including without limitation the rights
|
9
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
# copies of the Software, and to permit persons to whom the Software is
|
11
|
+
# furnished to do so, subject to the following conditions:
|
12
|
+
#
|
13
|
+
# The above copyright notice and this permission notice shall be
|
14
|
+
# included in all copies or substantial portions of the Software.
|
15
|
+
#
|
16
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
22
|
+
# SOFTWARE.
|
23
|
+
|
24
|
+
require 'rubygems'
|
25
|
+
require 'bundler/setup'
|
26
|
+
require 'rake'
|
27
|
+
Bundler.setup :default
|
28
|
+
|
29
|
+
begin
|
30
|
+
require "bundler/gem_tasks"
|
31
|
+
Bundler.setup :default, :development
|
32
|
+
rescue Bundler::BundlerError => e
|
33
|
+
$stderr.puts e.message
|
34
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
35
|
+
exit e.status_code
|
36
|
+
end
|
37
|
+
|
38
|
+
begin
|
39
|
+
Bundler.require :development
|
40
|
+
require 'rspec/core/rake_task'
|
41
|
+
|
42
|
+
YARD::Rake::YardocTask.new
|
43
|
+
|
44
|
+
RSpec::Core::RakeTask.new :spec do |spec|
|
45
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
46
|
+
end
|
47
|
+
|
48
|
+
task default: :spec
|
49
|
+
rescue LoadError, NameError
|
50
|
+
# OK, they can be absent on non-development mode.
|
51
|
+
end
|
52
|
+
|
53
|
+
desc "a la rails console"
|
54
|
+
task :console do
|
55
|
+
require_relative "lib/space_observatory"
|
56
|
+
require 'irb'
|
57
|
+
require 'irb/completion'
|
58
|
+
ARGV.clear
|
59
|
+
IRB.start
|
60
|
+
end
|
61
|
+
task :c => :console
|
62
|
+
|
63
|
+
desc "pry console"
|
64
|
+
task :pry do
|
65
|
+
require_relative "lib/space_observatory"
|
66
|
+
require 'pry'
|
67
|
+
ARGV.clear
|
68
|
+
Pry.start
|
69
|
+
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
#! /your/favourite/path/to/ruby
|
2
|
+
# -*- coding: utf-8; mode: ruby; ruby-indent-level: 2 -*-
|
3
|
+
#
|
4
|
+
# Copyright (c) 2014 Urabe, Shyouhei
|
5
|
+
#
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
# of this software and associated documentation files (the "Software"), to deal
|
8
|
+
# in the Software without restriction, including without limitation the rights
|
9
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
# copies of the Software, and to permit persons to whom the Software is
|
11
|
+
# furnished to do so, subject to the following conditions:
|
12
|
+
#
|
13
|
+
# The above copyright notice and this permission notice shall be
|
14
|
+
# included in all copies or substantial portions of the Software.
|
15
|
+
#
|
16
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
22
|
+
# SOFTWARE.
|
23
|
+
|
24
|
+
# This file is ultra tricky because it can be both executed as a script, AND
|
25
|
+
# required as a library. PLUS, when required, it shall not leak any objects
|
26
|
+
# because that should affect its probing result.
|
27
|
+
#
|
28
|
+
# The cause of this evilness is that we cannot assume our helper routines
|
29
|
+
# are on the load path. So the only safe assumption is the existance of
|
30
|
+
# this exact file. Thank goodness we can know the path of ourself by
|
31
|
+
# querying __FILE__. Requiring this should solve this wire-puzzle
|
32
|
+
# situation.
|
33
|
+
|
34
|
+
if __FILE__ == $0
|
35
|
+
# This case we are executed as a script (first stage). Our mission here is
|
36
|
+
# to spawn a process that acts as JSONRPC server, then exec the original
|
37
|
+
# projectile, with injecting two file descriptors that connect to the spawned
|
38
|
+
# server.
|
39
|
+
|
40
|
+
# SIGINT shall interrupt us properly.
|
41
|
+
Signal.trap "INT" do
|
42
|
+
Process.exit false # false indicates failure.
|
43
|
+
end
|
44
|
+
|
45
|
+
require 'rubygems'
|
46
|
+
require 'space_observatory/base_station'
|
47
|
+
|
48
|
+
tx, rx, pid, argw = SpaceObservatory::BaseStation.rackup! ARGV
|
49
|
+
|
50
|
+
# Wait for spawned process to parse ARGV...
|
51
|
+
|
52
|
+
case line = rx.gets
|
53
|
+
when "space_observatory ok\n" then
|
54
|
+
# Normal. Propel second stage.
|
55
|
+
path = File.expand_path __FILE__
|
56
|
+
argh = { 7 => tx, 8 => rx } # FDs < 7 happen to be reserved somehow in ruby
|
57
|
+
arge = {
|
58
|
+
'RUBYOPT' => (ENV['RUBYOPT'] || '') + " -r #{path}",
|
59
|
+
'BASE_PID' => pid.to_s,
|
60
|
+
}
|
61
|
+
Process.exec arge, *argw, argh
|
62
|
+
# /* NOTREACHED */
|
63
|
+
|
64
|
+
when "space_observatory norun\n" then
|
65
|
+
# No need to run, or no runnable projectile specified
|
66
|
+
STDOUT.write rx.read # dump if any
|
67
|
+
Process.exit true
|
68
|
+
|
69
|
+
else
|
70
|
+
# Something went wrong
|
71
|
+
STDOUT.puts line
|
72
|
+
STDOUT.write rx.read # dump if any
|
73
|
+
Process.exit false
|
74
|
+
end
|
75
|
+
|
76
|
+
else
|
77
|
+
# We are `require`d here (second stage). This case we SNEAK INTO the
|
78
|
+
# projectile. So to minimize the impact of our presence, we require nothing
|
79
|
+
# but `objspace.so`.
|
80
|
+
#
|
81
|
+
# This part is a hand-crafted state-of-art sh*t that I believe is unable to
|
82
|
+
# unit-test. Just feel it. It works. For me.
|
83
|
+
|
84
|
+
begin
|
85
|
+
# File descriptor number 7 and 8 should have been passed (see 1st stage).
|
86
|
+
tx = IO.for_fd 7, 'wb:binary:binary'
|
87
|
+
rx = IO.for_fd 8, 'rb:binary:binary'
|
88
|
+
th = Thread.start do
|
89
|
+
begin
|
90
|
+
tx.puts 'space_observatory hello' # handshake
|
91
|
+
tx.flush
|
92
|
+
loop do
|
93
|
+
case rx.gets
|
94
|
+
when "space_observatory setup\n" then
|
95
|
+
require 'objspace'
|
96
|
+
when "space_observatory probe\n" then
|
97
|
+
# This is the key part of this entire lib.
|
98
|
+
Thread.exclusive do
|
99
|
+
tx.puts 'space_observatory begin_objspace'
|
100
|
+
ObjectSpace.dump_all output: tx
|
101
|
+
tx.puts 'space_observatory end_objspace'
|
102
|
+
tx.flush
|
103
|
+
end
|
104
|
+
when "space_observatory teardown\n", NilClass then
|
105
|
+
Thread.exit
|
106
|
+
end
|
107
|
+
end
|
108
|
+
rescue Errno::EPIPE
|
109
|
+
# Abnormal end of peer
|
110
|
+
end
|
111
|
+
end
|
112
|
+
at_exit do
|
113
|
+
Thread.exclusive do
|
114
|
+
tx.puts 'space_observatory projectile_eof'
|
115
|
+
tx.flush
|
116
|
+
end
|
117
|
+
th.join
|
118
|
+
tx.close_write
|
119
|
+
rx.close_read
|
120
|
+
Process.waitpid ENV['BASE_PID'].to_i if ENV['BASE_PID']
|
121
|
+
end
|
122
|
+
rescue Errno::EBADF, Errno::EINVAL
|
123
|
+
# Maybe a grand-child process. Just leave nothing.
|
124
|
+
end
|
125
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
#! /your/favourite/path/to/ruby
|
2
|
+
# -*- coding: utf-8; mode: ruby; ruby-indent-level: 2 -*-
|
3
|
+
#
|
4
|
+
# Copyright (c) 2014 Urabe, Shyouhei
|
5
|
+
#
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
# of this software and associated documentation files (the "Software"), to deal
|
8
|
+
# in the Software without restriction, including without limitation the rights
|
9
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
# copies of the Software, and to permit persons to whom the Software is
|
11
|
+
# furnished to do so, subject to the following conditions:
|
12
|
+
#
|
13
|
+
# The above copyright notice and this permission notice shall be
|
14
|
+
# included in all copies or substantial portions of the Software.
|
15
|
+
#
|
16
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
22
|
+
# SOFTWARE.
|
23
|
+
|
24
|
+
require_relative "space_observatory/version"
|
25
|
+
|
26
|
+
module SpaceObservatory
|
27
|
+
# Your code goes here...
|
28
|
+
end
|
@@ -0,0 +1,163 @@
|
|
1
|
+
#! /your/favourite/path/to/ruby
|
2
|
+
# -*- coding: utf-8; mode: ruby; ruby-indent-level: 2 -*-
|
3
|
+
#
|
4
|
+
# Copyright (c) 2014 Urabe, Shyouhei
|
5
|
+
#
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
# of this software and associated documentation files (the "Software"), to deal
|
8
|
+
# in the Software without restriction, including without limitation the rights
|
9
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
# copies of the Software, and to permit persons to whom the Software is
|
11
|
+
# furnished to do so, subject to the following conditions:
|
12
|
+
#
|
13
|
+
# The above copyright notice and this permission notice shall be
|
14
|
+
# included in all copies or substantial portions of the Software.
|
15
|
+
#
|
16
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
22
|
+
# SOFTWARE.
|
23
|
+
|
24
|
+
require 'rubygems'
|
25
|
+
require 'open3'
|
26
|
+
require 'sync'
|
27
|
+
require 'rack'
|
28
|
+
require 'slop'
|
29
|
+
require_relative '../space_observatory'
|
30
|
+
|
31
|
+
class SpaceObservatory::BaseStation
|
32
|
+
# Fork a base station process
|
33
|
+
# @param [Array] argv The ::ARGV
|
34
|
+
# @return [IO, IO, Integer, Array] child's socket, pid, and argv.
|
35
|
+
def self.rackup! argv
|
36
|
+
_, a = parse argv
|
37
|
+
path = File.expand_path __FILE__
|
38
|
+
cmdline = %W"-r #{path} -e SpaceObservatory::BaseStation.construct --"
|
39
|
+
i, o, t = Open3.popen2 %w'ruby ruby', *cmdline, *argv
|
40
|
+
return i, o, t.pid, a
|
41
|
+
end
|
42
|
+
|
43
|
+
# Child process entry point
|
44
|
+
def self.construct
|
45
|
+
obj = new ARGV, STDIN, STDOUT
|
46
|
+
if obj.need_rackup?
|
47
|
+
obj.start_collector
|
48
|
+
obj.rackup
|
49
|
+
else
|
50
|
+
obj.banner
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# Parse command line
|
55
|
+
# @param [Array] argv argv
|
56
|
+
# @return [Slop, Array] parsed command line parameters, and remains.
|
57
|
+
def self.parse argv
|
58
|
+
argw = argv.dup
|
59
|
+
opts = Slop.parse! argw do
|
60
|
+
on 'h', 'help', 'this message'
|
61
|
+
on 'port=', 'JSONRPC port', as: Integer
|
62
|
+
on 'ttl=', 'cache expiration (in seconds)', as: Float
|
63
|
+
end
|
64
|
+
return opts, argw
|
65
|
+
end
|
66
|
+
|
67
|
+
# @param [Array] argv the ::ARGV
|
68
|
+
# @param [IO] stdin the ::STDIN
|
69
|
+
# @param [IO] stdout the ::STDOUT
|
70
|
+
def initialize argv, stdin, stdout
|
71
|
+
@argv = argv
|
72
|
+
@stdin = stdin
|
73
|
+
@stdout = stdout
|
74
|
+
@stdout.sync = true # we need line IO
|
75
|
+
@opts, @argw = self.class.parse argv
|
76
|
+
@argw.shift if @argw.first == '--'
|
77
|
+
@started = Time.at 0
|
78
|
+
@finished = Time.at 0
|
79
|
+
@jsons = Array.new
|
80
|
+
@rwlock = Sync.new
|
81
|
+
@expires = @opts['ttl'] || 60 # 300 # 3600
|
82
|
+
end
|
83
|
+
|
84
|
+
def rackup
|
85
|
+
Rack::Handler::WEBrick.run self, Port: @opts['port']
|
86
|
+
end
|
87
|
+
|
88
|
+
def banner
|
89
|
+
@stdout.puts "space_observatory norun"
|
90
|
+
@stdout.puts @opts.help if @opts['h']
|
91
|
+
@stdout.flush
|
92
|
+
@stdout.close_write
|
93
|
+
end
|
94
|
+
|
95
|
+
def start_collector
|
96
|
+
Thread.start do
|
97
|
+
# needs handshale
|
98
|
+
@stdout.puts "space_observatory ok"
|
99
|
+
@stdin.gets # wait execve(2)
|
100
|
+
@stdout.puts "space_observatory setup"
|
101
|
+
@stdout.puts "space_observatory probe"
|
102
|
+
while line = @stdin.gets
|
103
|
+
case line
|
104
|
+
when "space_observatory projectile_eof\n"
|
105
|
+
Rack::Handler::WEBrick.shutdown rescue nil
|
106
|
+
@stdout.close
|
107
|
+
return
|
108
|
+
when "space_observatory begin_objspace\n"
|
109
|
+
@started = Time.now
|
110
|
+
@rwlock.lock Sync::EX
|
111
|
+
@jsons = Array.new
|
112
|
+
when "space_observatory end_objspace\n"
|
113
|
+
@rwlock.unlock Sync::EX
|
114
|
+
@finished = Time.now
|
115
|
+
STDERR.printf "took %fsec\n", (@finished - @started).to_f
|
116
|
+
when /\A{/o
|
117
|
+
# This is the output of ObjectSpace.dump_all
|
118
|
+
@jsons.push line
|
119
|
+
else
|
120
|
+
raise "TBW: #{line}"
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def need_rackup?
|
127
|
+
not @opts['h'] and not @argw.empty?
|
128
|
+
end
|
129
|
+
|
130
|
+
def call env
|
131
|
+
# TODO: more "proper" JSON
|
132
|
+
enum = Enumerator.new do |y|
|
133
|
+
@rwlock.synchronize Sync::EX do
|
134
|
+
if Time.now - @started >= @expires
|
135
|
+
@stdout.puts "space_observatory probe"
|
136
|
+
IO.select [@stdin], [], [], 10
|
137
|
+
@started = Time.now # prevent further probe
|
138
|
+
end
|
139
|
+
end
|
140
|
+
Thread.pass
|
141
|
+
@rwlock.synchronize Sync::SH do
|
142
|
+
id = @finished.to_i
|
143
|
+
y.yield <<-"]"
|
144
|
+
{
|
145
|
+
"jsonrpc" : "2.0",
|
146
|
+
"id" : #{id},
|
147
|
+
"result" : [
|
148
|
+
]
|
149
|
+
@jsons.each_with_index do |i, j|
|
150
|
+
y.yield "," unless j.zero?
|
151
|
+
y.yield i
|
152
|
+
end
|
153
|
+
y.yield "]\n}\n"
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
return [
|
158
|
+
200,
|
159
|
+
{ 'Content-Type' => 'application/json' },
|
160
|
+
enum
|
161
|
+
]
|
162
|
+
end
|
163
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
#! /your/favourite/path/to/ruby
|
2
|
+
# -*- coding: utf-8; mode: ruby; ruby-indent-level: 2 -*-
|
3
|
+
#
|
4
|
+
# Copyright (c) 2014 Urabe, Shyouhei
|
5
|
+
#
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
# of this software and associated documentation files (the "Software"), to deal
|
8
|
+
# in the Software without restriction, including without limitation the rights
|
9
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
# copies of the Software, and to permit persons to whom the Software is
|
11
|
+
# furnished to do so, subject to the following conditions:
|
12
|
+
#
|
13
|
+
# The above copyright notice and this permission notice shall be
|
14
|
+
# included in all copies or substantial portions of the Software.
|
15
|
+
#
|
16
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
22
|
+
# SOFTWARE.
|
23
|
+
module SpaceObservatory
|
24
|
+
VERSION = "0.0.1"
|
25
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
#! /your/favourite/path/to/gem
|
2
|
+
# -*- coding: utf-8; mode: ruby; ruby-indent-level: 2 -*-
|
3
|
+
#
|
4
|
+
# Copyright (c) 2014 Urabe, Shyouhei
|
5
|
+
#
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
# of this software and associated documentation files (the "Software"), to deal
|
8
|
+
# in the Software without restriction, including without limitation the rights
|
9
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
# copies of the Software, and to permit persons to whom the Software is
|
11
|
+
# furnished to do so, subject to the following conditions:
|
12
|
+
#
|
13
|
+
# The above copyright notice and this permission notice shall be
|
14
|
+
# included in all copies or substantial portions of the Software.
|
15
|
+
#
|
16
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
22
|
+
# SOFTWARE.
|
23
|
+
|
24
|
+
require 'rubygems'
|
25
|
+
require_relative 'lib/space_observatory/version'
|
26
|
+
|
27
|
+
Gem::Specification.new do |gem|
|
28
|
+
gem.name = "space_observatory"
|
29
|
+
gem.version = SpaceObservatory::VERSION
|
30
|
+
gem.authors = ["Urabe, Shyouhei"]
|
31
|
+
gem.email = ["shyouhei@ruby-lang.org"]
|
32
|
+
gem.summary = "ObjectSpace#dump_all exposed"
|
33
|
+
gem.description = "Pure-ruby Minimal-overhead Drop-in probe to ObjectSpace."
|
34
|
+
gem.homepage = "https://github.com/shyouhei/space_observatory"
|
35
|
+
gem.license = "MIT"
|
36
|
+
|
37
|
+
gem.bindir = "exec"
|
38
|
+
gem.files = `git ls-files -z`.split("\x0")
|
39
|
+
gem.executables = gem.files.grep(%r{^exec/}) { |f| File.basename(f) }
|
40
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
41
|
+
gem.require_paths = ["lib"]
|
42
|
+
|
43
|
+
gem.required_ruby_version = '~> 2.1'
|
44
|
+
gem.add_development_dependency 'yard', '~> 0.8'
|
45
|
+
gem.add_development_dependency 'rdoc', '~> 4.0'
|
46
|
+
gem.add_development_dependency 'rspec', '~> 3.0'
|
47
|
+
gem.add_development_dependency 'rspec-its'
|
48
|
+
gem.add_development_dependency 'simplecov', '>= 0'
|
49
|
+
gem.add_development_dependency 'bundler', '~> 1.6'
|
50
|
+
gem.add_development_dependency 'rake'
|
51
|
+
gem.add_development_dependency 'pry'
|
52
|
+
gem.add_dependency 'rack' # we use pure-rack
|
53
|
+
gem.add_dependency 'slop'
|
54
|
+
end
|
metadata
ADDED
@@ -0,0 +1,198 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: space_observatory
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Urabe, Shyouhei
|
8
|
+
autorequire:
|
9
|
+
bindir: exec
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-07-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: yard
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.8'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.8'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rdoc
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '4.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec-its
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: bundler
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.6'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.6'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rake
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: pry
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rack
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: slop
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :runtime
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
description: Pure-ruby Minimal-overhead Drop-in probe to ObjectSpace.
|
154
|
+
email:
|
155
|
+
- shyouhei@ruby-lang.org
|
156
|
+
executables:
|
157
|
+
- with-space-observatory.rb
|
158
|
+
extensions: []
|
159
|
+
extra_rdoc_files: []
|
160
|
+
files:
|
161
|
+
- ".gitignore"
|
162
|
+
- ".rspec"
|
163
|
+
- ".yardopts"
|
164
|
+
- Gemfile
|
165
|
+
- LICENSE.txt
|
166
|
+
- README.md
|
167
|
+
- Rakefile
|
168
|
+
- exec/with-space-observatory.rb
|
169
|
+
- lib/space_observatory.rb
|
170
|
+
- lib/space_observatory/base_station.rb
|
171
|
+
- lib/space_observatory/version.rb
|
172
|
+
- space_observatory.gemspec
|
173
|
+
homepage: https://github.com/shyouhei/space_observatory
|
174
|
+
licenses:
|
175
|
+
- MIT
|
176
|
+
metadata: {}
|
177
|
+
post_install_message:
|
178
|
+
rdoc_options: []
|
179
|
+
require_paths:
|
180
|
+
- lib
|
181
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
182
|
+
requirements:
|
183
|
+
- - "~>"
|
184
|
+
- !ruby/object:Gem::Version
|
185
|
+
version: '2.1'
|
186
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
187
|
+
requirements:
|
188
|
+
- - ">="
|
189
|
+
- !ruby/object:Gem::Version
|
190
|
+
version: '0'
|
191
|
+
requirements: []
|
192
|
+
rubyforge_project:
|
193
|
+
rubygems_version: 2.2.2
|
194
|
+
signing_key:
|
195
|
+
specification_version: 4
|
196
|
+
summary: ObjectSpace#dump_all exposed
|
197
|
+
test_files: []
|
198
|
+
has_rdoc:
|