Git Product home page Git Product logo

rack-speedtracer's Introduction

Rack::SpeedTracer

Blog post: Speed Tracer Server-side Tracing with Rack

Rack::SpeedTracer middleware provides server-side tracing capabilities to any Rack compatible app. Include the middleware, instrument your application, and then load it in your Google Chrome + SpeedTracer to view detailed breakdown of your JavaScript/CSS load times, GC cycles, as well as, server side performance data provided by this middleware - you can preview both server side and client side performance data all within the same view in SpeedTracer!

Preview of a sample, server side Rails trace (see below for setup) in SpeedTracer: rails trace

Features

  • Auto Rails 3 instrumentation (see example below)
  • Memory, or Redis storage backend
    • Redis backend allows trace expiration (via :trace_ttl), and custom namespaces (via :namespace)

Todo / Wishlist

  • Authentication / optional enable, ala rack-bug: IP-based, password based
    • At the moment, every request will record & store a trace
    • Could also do conditional tracing based on a request header: 'X-SpeedTracer: true'

Without authentication, I wouldn't recommend running this middleware in production, unless you add some extra logic. For a capped memory footprint, use Redis backend with a TTL to expire your traces after some reasonable amount of time.

How it works

Rack::SpeedTracer provides a Tracer class which you can use to instrument your code. From there, the trace details are stored as a JSON blob, and a special X-TraceUrl header is sent back to the client. If the user clicks on the network resource that corresponds to a request which returned a X-TraceUrl header, then SpeedTracer will make a request to our app to load the server side trace. Rack::SpeedTracer responds to this request and returns the full trace - aka, the data is provided on demand.

Quickstart Guide with Rack

gem install rack-speedtracer

# in your rack app / rackup file
use Rack::SpeedTracer

# in your app
env['st.tracer'].run('name of operation') do
  ... your code ...
end

Check out a full sample rack app: examples/runner.rb

Instrumenting Rails 3 application

Rails 3 provides new Notifications API, which we can use to automatically instrument your Rails applications! It's as easy as:

# in your Gemfile
gem 'rack-speedtracer', :require => 'rack/speedtracer'

# in development.rb environment
config.middleware.use Rack::SpeedTracer

Manually instrumenting Rails

To produce a server-side trace equivalent to one in the screenshot above:

# in your Gemfile
gem 'rack-speedtracer', :require => 'rack/speedtracer'

# in development.rb environment
config.middleware.use Rack::SpeedTracer

# define a widgets controller
class WidgetsController < ApplicationController
  def index
    env['st.tracer'].run('Widgets#index') do
      env['st.tracer'].run("ActiveRecord: Widgets.all") do
        Widget.all
      end

      env['st.tracer'].run('Render') { render :text => 'oh hai' }
    end
  end
end

Speed Tracer

Speed Tracer is a Google Chrome extension to help you identify and fix performance problems in your web applications. It visualizes metrics that are taken from low level instrumentation points inside of the browser and analyzes them as your application runs. Speed Tracer is available as a Chrome extension and works on all platforms where extensions are currently supported (Windows and Linux).

Using Speed Tracer you are able to get a better picture of where time is being spent in your application. This includes problems caused by JavaScript parsing and execution, layout, CSS style recalculation and selector matching, DOM event handling, network resource loading, timer fires, XMLHttpRequest callbacks, painting, and more.

License

(The MIT License)

Copyright © 2010 Ilya Grigorik

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.

rack-speedtracer's People

Contributors

igrigorik avatar simonjefford avatar halorgium avatar phlipper avatar

Stargazers

 avatar Rogério Zambon avatar Minh-Triet Pham Tran avatar JeongHoon Baek avatar Joe Wang avatar Angus H. avatar Lixiang Ding avatar Tom Hensel avatar Johannes Wachter avatar Grégory Horion avatar John Riviello avatar Marc Cuarno avatar Sridatta Thatipamala avatar James Welsh avatar Keenan Brock avatar Raphael Randschau avatar Anuj Dutta avatar Michael Lopez avatar 大野 avatar bony avatar  avatar  avatar Govinda Fichtner avatar Matthias Jakel avatar  avatar Evan Marell avatar 丁宇 avatar Richard Michael avatar eric avatar Andrew Eberbach avatar  avatar Volodymyr Melnyk avatar Paul Meserve avatar  avatar  avatar Anderson Freitas avatar  avatar Edmund Salvacion avatar Sebastian Korfmann avatar Gimi Liang avatar Alex avatar Judson Lester avatar Fabio Yamate avatar David Billskog avatar Blake Gentry avatar  avatar Leandro López avatar Brandon Black avatar  avatar Chris Kelly avatar Kostas avatar Stephano Zanzin Ferreira avatar José Ignacio Costa avatar Yung Hwa Kwon avatar Haifeng Cao avatar Thomas Shelton avatar Guillaume avatar Jorge Queiruga avatar Mike Javorski avatar Max Clark avatar Stone Gao avatar Gus Becciu avatar Dzmitry Ilyashevich avatar Daniel Lehmann avatar Matt Southerden avatar Marcin Kalita avatar Hiroyuki Nakamura avatar Artiom Diomin avatar Konstantin Haase avatar Steve Agalloco avatar Rolly avatar Jesse Storimer avatar Chris Hoffman avatar Kirill Nikitin avatar Jonathan Pliske avatar Stephen St. Martin avatar Graeme Nelson avatar Matt Yoho avatar terrcin avatar Rodrigo Tassinari de Oliveira avatar Duncan Gough avatar Nelson Yee avatar Shane Sherman avatar Tiago Bastos avatar Paco Guzmán avatar Edgard Arakaki avatar  avatar Roger Leite avatar Lin Jen-Shin (godfat) avatar Jordi Romero avatar Szymon Nowak avatar gk avatar Joshua Hull avatar Joaquin Rivera Padron avatar Joris Machielse avatar Renaud Morvan avatar Keith Larrimore avatar Lalit Shandilya avatar Elmer Rivera avatar Stephen Haberman avatar

Watchers

 avatar Nicolaus Copernicus avatar James Cloos avatar  avatar  avatar

rack-speedtracer's Issues

Redis storage support

A few issues / to-do's to look into:

  1. redis> keys *
  1. "speedtracer_098d9f40-852a-012d-4c73-00264a017222"
  2. "speedtracer_0a305390-852a-012d-4c73-00264a017222"
  3. "speedtracer_09dd20c0-852a-012d-4c73-00264a017222"

Haven't dug in why, but 3 keys are created in Redis for every request.

  1. SystemTimer failed to build on ruby 1.9.2dev (2010-05-31 revision 28117) [x86_64-darwin10.3.0]

  2. Graceful fail on redis down/missing (don't store)?

  3. MemoryStorage, thread local?

  4. Configuration syntax for middleware? :storage => :redis

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.