-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add strace_me, a simple strace(1) wrapper
- Loading branch information
0 parents
commit d87ecda
Showing
8 changed files
with
170 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# -*- ruby -*- | ||
|
||
require 'autotest/restart' | ||
|
||
Autotest.add_hook :initialize do |at| | ||
at.testlib = 'minitest/unit' | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/TAGS | ||
/pkg | ||
/doc | ||
*.swp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
=== 1.0.0 / 2010-06-07 | ||
|
||
* Major Enhancement | ||
* Birthday! | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
History.txt | ||
Manifest.txt | ||
README.txt | ||
Rakefile | ||
lib/strace.rb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
= strace_me | ||
|
||
* http://seattlerb.rubyforge.org/strace_me | ||
|
||
== DESCRIPTION: | ||
|
||
A wrapper around strace(1) that allows you to perform targetted tracing of a | ||
block. strace_me allows you to track down problems without wading through | ||
gobs of ruby startup or other irrelevant noise. | ||
|
||
== FEATURES/PROBLEMS: | ||
|
||
* strace only | ||
|
||
== SYNOPSIS: | ||
|
||
See Strace::me | ||
|
||
== REQUIREMENTS: | ||
|
||
* strace | ||
|
||
== INSTALL: | ||
|
||
* sudo gem install strace_me | ||
|
||
== LICENSE: | ||
|
||
(The MIT License) | ||
|
||
Copyright (c) 2010 Eric Hodel | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
'Software'), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# -*- ruby -*- | ||
|
||
require 'rubygems' | ||
require 'hoe' | ||
|
||
Hoe.plugin :git | ||
Hoe.plugin :minitest | ||
|
||
Hoe.spec 'strace_me' do | ||
self.rubyforge_name = 'seattlerb' | ||
developer 'Eric Hodel', 'drbrain@segment7.net' | ||
|
||
extra_deps << ['open4', '~> 0.9'] | ||
end | ||
|
||
# vim: syntax=Ruby |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
require 'open4' | ||
|
||
## | ||
# Simple wrapper of strace(1) for targetted tracing. | ||
|
||
module Strace | ||
|
||
## | ||
# The version of strace_me you're using | ||
|
||
VERSION = '1.0' | ||
|
||
## | ||
# Runs strace(1) during the code in the block and returns an IO containing | ||
# the strace output and the exception raised by the block (if any). | ||
# | ||
# Simple example (it doesn't matter if you have a /COPYRIGHT): | ||
# | ||
# trace, err = Strace.me do | ||
# open '/COPYRIGHT' do |io| | ||
# io.read 1024 | ||
# end | ||
# end | ||
# | ||
# puts "error: #{err.message} (#{err.class})\n\n" if err | ||
# puts "trace:\n\n#{trace.read}" | ||
# | ||
# Tracing an existing library call: | ||
# | ||
# alias old_connect connect | ||
# | ||
# def connect host, user, password | ||
# connection = nil | ||
# | ||
# trace, err = Strace.me do | ||
# connection = old_connect host, user, password | ||
# end | ||
# | ||
# $stderr.puts "connect trace:\n\n#{trace.read}" | ||
# | ||
# raise err if err | ||
# connection | ||
# end | ||
|
||
def self.me | ||
pid, i, o, e = Open4.open4 'strace', '-p', $$.to_s | ||
|
||
i.close | ||
e.gets # consumes "attached" message, but we know strace is ready | ||
|
||
begin | ||
yield | ||
ensure | ||
Process.kill 'INT', pid | ||
Process.waitpid pid | ||
|
||
return [e, $!] | ||
end | ||
end | ||
|
||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
require 'rubygems' | ||
require 'minitest/autorun' | ||
require 'strace' | ||
|
||
class TestStrace < MiniTest::Unit::TestCase | ||
|
||
def test_class_me_no_strace | ||
path = ENV['PATH'] | ||
ENV['PATH'] = nil | ||
|
||
assert_raises Errno::ENOENT do | ||
Strace.me do end | ||
end | ||
|
||
ensure | ||
ENV['PATH'] = path | ||
end | ||
|
||
end | ||
|