Skip to content

Instantly share code, notes, and snippets.

View ecin's full-sized avatar
🐶
Woof!

ecin ecin

🐶
Woof!
View GitHub Profile
|-------| |-------|
| 12345 | | 67890 | } web application processes
|-------| |-------|
| |
| |
\ / \
\ / \ } dtrace probes firing
|----| |----|
|rack| | ?? | } rack: rack interface to web applications
|----| |----| ??: consumer process for dtrace probes
// Hi, I'm Safari 4 and I throw a parse error at this!
p.import = function import(lib){
eval(p.ajax(lib));
}
def consume(*types, &block)
filter_types(types)
@t.buf_consumer(buf_consumer)
begin
while(true) do
@t.sleep # the tricky little trickster
work = @t.work(probe_consumer, rec_consumer(block))
if (@done || work > 0)
break
end
/*
* Sleep until we need to wake up to honour D options controlling
* consumption rates.
*/
VALUE dtrace_hdl_sleep(VALUE self)
{
dtrace_handle_t *handle;
Data_Get_Struct(self, dtrace_handle_t, handle);
dtrace_sleep(handle->hdl);
#!/usr/bin/env ruby
# Hi! Welcome to your new weight-loss program, tenplustwo.
# First thing's first. We need a way to communicate.
def shout( msg ); `growlnotify -s -m "#{msg}"`; end
# Put on your running shoes.
running = true
# Our IRS (Internal Request Service) agent
require 'rack/probe'
# Let's add some nice phrases to our app's repertoire
responses = ['Clap clap clap!', 'Oh noes, oh noes, oh noes!', 'Oh yeah, oh yeah, oh yeah!']
# Our friendly app. He's a cheery fellow, get's easily agitated
app = Proc.new{ [200, {'Content-Type' => 'text/html'}, responses[rand(3)] }
# The agent slips in between the paper trail
// Save the time a request comes in
rack*:::request_start
{
self->start = timestamp;
}
// Save the difference between the request's start and finish
rack*:::request_finish
{
@length[self->path] = quantize(timestamp - self->start);
// Save the time a request comes in
rack*:::request_start
{
self->start = timestamp;
self->flip = 1;
}
// Save the request's path
rack*:::path
/ self->flip == 1 /
config.gem 'rack-probe'
config.middleware.use 'Rack::Probe'
require 'rack'
require 'rack/builder'
require 'rack/lobster'
class MagLevTransactionWrapper
def initialize(app)
@app = app
end
def call(env)