Diagnosing Ruby require_relative issues with DTrace on OSX

Ruby, like many programming languages, has a C-like mechanism for using code defined in other files. It’s critical for the development of any serious program, but it’s also prone to weird errors when files aren’t included in the proper order, or not included at all. It’s usually pretty obvious which file you’re not require_relativeing, but there are times when the only way to make sense of things is to trace the system calls.

On Windows, Process Monitor is by far the best way to diagnose this sort of problem. It gives a useful trace of just about everything a process does. I’ve used it many times before to diagnose file loading issues, and weird compiler errors. Similarly, strace on Linux traces every system call.

But what about OSX?

OSX has it’s own tracing utility (well, it was ported to OSX) called DTrace. It’s an awful lot like strace, and honestly, I’d have trouble noticing the differences in the outputs if you didn’t tell me so.

DTrace is kinda awkward to use on it’s own, so it comes with a whole bunch of scripts (archived) to help you find the information that you’re looking for. Here, I’m using the opensnoop script.

Usage is pretty simple. “sudo opensnoop -n ruby”, and then you run your ruby application in a different window. You’ll get an output like this:

Screen Shot 2019-06-19 at 4.53.36 PM

Trust me, most of that doesn’t matter right now.

 

I’m running a really basic and contrived application, where I’m failing to include a file before using functions in that file. There’s still an awful lot going on, because modern computers are built on the shoulders of giants. See also:

abstraction.png

 

ANYWAYS

 

Running opensnoop will likely produce several terminal-pages of output, but don’t worry too much about that. It’s normal for an interpreted language to be doing an awful lot of file reads when initializing the standard library and execution environment. What we’re interested is towards the end:

Screen Shot 2019-06-19 at 5.11.45 PM

 

See towards the bottom where it opens bin/run.rb? That’s where ruby is actually starting to parse my code. Everything after that is gonna be the require_relatives.

First, ruby hits the require_relative for environment.rb​, and then begins parsing that one. Since environment.rb has a require_relativefor file_one.rb, ruby opens that file. Since environment.rb​` has a require_relative for file_two.rb …it should open that file?

Screen Shot 2019-06-20 at 10.31.32 AM

In software, the answer to “which idiot did that” is almost always “you did”.

And there’s the problem. <span style="color:var(--color-text);">require_relative "app/file_two.rb" in file_two.rb is commented out. Which idiot did that? Probably me.

 

Code is available on my alternate (for a school account) GitHub here: https://github.com/ariccio-learn-co-alternate/june_blog_repo

~ by Alexander Riccio on June 20, 2019.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

 
Shelly L. Miller

I am an environmental engineer. I teach and research urban air pollution.

Lucky's Notes

Notes on math, coding, and other stuff

AbandonedNYC

Abandoned places and history in the five boroughs

Open Mind

KIDS' LIVES MATTER so let's stop climate change

I learned it. I share it.

A software engineering blog by György Balássy

Kitware Inc

Delivering Innovation

The Electric Chronicles: Power in Flux

If someone ever tells you that you don't need more power, walk away. You don't need that kind of negativity in your life.

Ted's Energy Tips

Practical tips for making your home more comfortable, efficient and safe

love n grace

feel happy, be happy

Recognition, Evaluation, Control

News and views from Diamond Environmental Ltd.

greg tinkers

Sharing the successes and disasters.

Sam Thursfield

Software and technology from Galicia, Spain

Cranraspberry Blog

Sharing the things I love

Biosingularity

Advances in biological systems.

The Embedded Code

Designing From Scratch

Sean Heelan's Blog

Software Exploitation and Optimisation

EduResearcher

Connecting Research, Policy, and Practice in Education

Popehat

A Group Complaint about Law, Liberty, and Leisure

warnersstellian.wordpress.com/

Home & Kitchen Appliance Blog

Bad Science Debunked

Debunking dangerous junk science found on the Internet. Non-scientist friendly!

4 gravitons

The trials and tribulations of four gravitons and a physicist

Strange Quark In London

A blog about physics, citylive and much procastination

The Lumber Room

"Consign them to dust and damp by way of preserving them"

In the Dark

A blog about the Universe, and all that surrounds it

andrea elizabeth

passionate - vibrant - ambitious

Probably Dance

I can program and like games

a totally unnecessary blog

paolo severini's waste of bandwidth

Musing Mortoray

Programming and Life

PJ Naughter's space

Musings on Native mode development on Windows using C++

  Bartosz Milewski's Programming Cafe

Category Theory, Haskell, Concurrency, C++

Brandon's Thoughts

Thoughts on programming

David Crocker's Verification Blog

Formal verification of C/C++ code for critical systems

10 Minute Astronomy

Stargazing for people who think they don't have time for stargazing.

One Dev Job

notes of an interactive developer

Chief Cloud Architect & DevSecOps SME, Enterprise Architect, Agile Coach, Digital Transformation Leader, Presales & Tech Evangelist, Development Manager, Agilist, Mentor, Speaker and Author

TOGAF Certified Enterprise Architect • AWS Cloud Certified Solutions Architect • Azure Cloud Certified Solutions Architect • Scrum Alliance: Certified Scrum Professional (CSP), Certified Agile Leadership I (CAL 1), CSM, ACSM • Kanban Management Professional (KMP I & KMP II), Certified Enterprise Agility Coach (CEAC) • SAFe: Certified SAFe Architect, SAFe DevOps, Release Train Engineer (RTE), SAFe Consultant (SPC) • Certified Less Practitioner (CLP), Six Sigma (Greenbelt), Training from the Back of the Room (TBR) Trainer • Certified Agile Coach & Facilitator: ICP-ACF & ICP-ACC

The Angry Technician

No, the Internet is not broken.

Kenny Kerr

Creator of C++/WinRT and the Windows crate for Rust • Engineer on the Windows team at Microsoft • Romans 1:16

IT affinity!

The Ultimate Question of Life, the Universe, and Everything is answered somewhere else. This is just about IT.

Eat/Play/Hate

The ramblings of a crazed mind

Molecular Musings

Development blog of the Molecule Engine

%d bloggers like this: