Search code examples
macosperformancedebuggingdtraceenergy

Mac OS X: What is making my system slow RIGHT NOW?


Question: is there a utility (command line or GUI) that will answer "what is making my Mac slow RIGHT NOW?"

I can see CPU percentage and RPRVT with top or ActivityMonitor.app. And Activity Monitor will show me aggregate i/o info – but it won't show me per-process i/o, or i/o latencies. There are dtrace scripts, like iotop, iosnoop, and dtruss that will show me i/o info. And, of course, there is fs_usage. And stackshot. And etc., etc. !!!

Note: I am posting this question here on StackOverflow -- instead of, say AskDifferent or SuperUser -- because I see this as a programming question, not just a user/sysadmin question. Extra points for: command line, open source, hackable, and/or dtrace scripts.

Summarizing, per discussion in comments:

I want a utility that monitors recent & instantaneous CPU and I/O load (quantity, latency) in a way that is both:

unified (i.e., both in the same display), and

actionable (by telling me which processes are incurring the aforementioned loads).


Solution

  • Have a look at this slideshow from Brendan Gregg for some strategies: http://www.slideshare.net/brendangregg/analyzing-os-x-systems-performance-with-the-use-method

    Though I believe that you have answered your own question. dtrace is exactly the tool you are looking for.

    dtrace allows you to observe pretty much everything that is happening with your system.

    It operates on the principle of dynamically inserted probes in running software that can report all kinds of data about whats happening.

    The scripts you mention are only a small, but useful, starting point. I dont think there is a dtrace script that is already that will do exactly what you want, however it would not be terribly difficult to write one. What you need to do is learn how to write D scripts, and learn what probes you want to use to get at the info you seek. You can write probes that aggregate data, and you can write probes that provide realtime info. Its up to you, and the sky's really the limit.

    I would start by looking some of the tools here: http://www.brendangregg.com/dtracetoolkit.html and learning what they do and how they work, and you should be able to build yourself the tool you need shortly.

    The D language itself is somewhat like C, so fairly easy to pick up if you're familiar with any C based languages. But even if you arent writing in D, there are some extremely useful one liners that can reach into your system and give you the information you seek.

    An additional advantage to learning how to use dtrace and D is that there are probes for many, many application layer things out there, such as mysql, php, javascript, ruby, perl, java etc etc etc. Its like a performance analysis tool that can get really deep. For example: this simple oneliner showed me all of the mysql queries my server was running:

    sudo dtrace -n 'mysql*:::query-start { trace(copyinstr(arg0)) }'
    

    TL;DR dtrace can tell you anything that is happening on your OSX system. You just have to learn how to ask it.