Code Monkey home page Code Monkey logo

ruby-usdt's Introduction

ruby-usdt

Native DTrace probes for ruby apps

Ruby bindings for libusdt.

Applications, Libraries, and Frameworks can consume ruby-usdt to define USDT
providers at runtime for instrumentation and analysis by the DTrace framework.

Install

gem install ruby-usdt

When using Bundler to integrate ruby-usdt into a Ruby or Rails project, you will need to specify that there are git submodule dependencies:

gem "ruby-usdt", :submodules => true

Usage

# Provider.create <provider>, <module>
#
# Creates a probe
#
# returns USDT::Provider object
provider = USDT::Provider.create :ruby, :mymod

# Provider#probe *args
#
# args must be either :integer, or :string
# max 6 args (dtrace provides this many), additional args will be ignored
# returns USDT::Probe object
probe = provider.probe(:myfn, :probe, :string, :string, :integer)

# Provider#enable
# enables the probes defined with #probe
provider.enable

while true
  if probe.enabled?
    probe.fire("omg", "probe!!", 12345)
  end
  sleep 0.5
end

To see the above probe working, the following dtrace script can be used:

sudo dtrace -n 'ruby*:mymod:myfn:probe { printf("%s %s %d",
  copyinstr(arg0),
  copyinstr(arg1),
  args[2])
}'

Probes in Ruby

Introspection can be done on a probe from within Ruby using the following commands:

probe.function  => :myfn
probe.name      => :probe
probe.arguments => [:string, :string, :integer]

Interoperability

On systems with DTrace, this gem will compile C extensions that hook into USDT. On systems without DTrace, the gem should install with a noop implementation, so that probes can be added to projects without losing the ability to deploy to non-dtraceable platforms.

Additional Resources

License

The MIT License

Copyright (C) 2012 Kevin Chan

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.

ruby-usdt's People

Contributors

thekvn avatar chrisa avatar sax avatar

Stargazers

Marcin Nowicki avatar Krzysztof Wilczyński avatar Filip Zrůst avatar Andrew Newdigate avatar Denis Defreyne avatar  avatar Balázs Kutil avatar Max Surkov avatar Sergey Avseyev avatar Yunzheng avatar Drew Miller avatar Angus H. avatar Juanito Fatas avatar Alex Zolotko avatar  avatar  avatar John D'Agostino avatar  avatar Eric West avatar Aaron Zauner avatar Paweł Pacana avatar Stig Kleppe-Jørgensen avatar Oleg Kovalenko avatar dzrw avatar  avatar  avatar

Watchers

 avatar  avatar Stig Kleppe-Jørgensen avatar  avatar James Cloos avatar

ruby-usdt's Issues

License missing from gemspec

RubyGems.org doesn't report a license for your gem. This is because it is not specified in the gemspec of your last release.

via e.g.

  spec.license = 'MIT'
  # or
  spec.licenses = ['MIT', 'GPL-2']

Including a license in your gemspec is an easy way for rubygems.org and other tools to check how your gem is licensed. As you can imagine, scanning your repository for a LICENSE file or parsing the README, and then attempting to identify the license or licenses is much more difficult and more error prone. So, even for projects that already specify a license, including a license in your gemspec is a good practice. See, for example, how rubygems.org uses the gemspec to display the rails gem license.

There is even a License Finder gem to help companies/individuals ensure all gems they use meet their licensing needs. This tool depends on license information being available in the gemspec. This is an important enough issue that even Bundler now generates gems with a default 'MIT' license.

I hope you'll consider specifying a license in your gemspec. If not, please just close the issue with a nice message. In either case, I'll follow up. Thanks for your time!

Appendix:

If you need help choosing a license (sorry, I haven't checked your readme or looked for a license file), GitHub has created a license picker tool. Code without a license specified defaults to 'All rights reserved'-- denying others all rights to use of the code.
Here's a list of the license names I've found and their frequencies

p.s. In case you're wondering how I found you and why I made this issue, it's because I'm collecting stats on gems (I was originally looking for download data) and decided to collect license metadata,too, and make issues for gemspecs not specifying a license as a public service :). See the previous link or my blog post about this project for more information.

Update to latest libusdt

Chris Andrews has made some updates in the last few months. He's added support for different platforms, and removed restrictions on the type of arguments passed to probes.

Updating usdt.c to accommodate the latter is a bit of a struggle for me, at my current comfort level with Ruby's internals. Particularly since values need to be type checked and cast using RSTRING_PTR, FIX2INT or ID2SYM, I'm not sure of the safest way to do this.

ruby-usdt should be installable on platforms that don't include DTrace

I don't know how complicated this would be, but it should be possible to include ruby-usdt in a project that will be installed on OSs that don't include DTrace.

For instance, if I'm writing code that will be deployed to an Illumos host, I may run tests in TravisCI, which will run in some Linux distro.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.