What's New on the Leopard Command Line?

Author: Drew McCormack
Web Site: www.macccoremac.com

Each new release of Mac OS X brings with it a range of new command-line tools, many of which go unnoticed. Not only are these tools useful, they also tell the story of the evolution of the OS. Leopard is no exception, so armed with a couple of old and unevolved commands, ls and diff, I set about finding out what’s new in /usr/bin on Leopard. What follows is far from comprehensive, but I hope it at least touches on some of the more interesting developments. For those who want more, there’s always ls and diff. Here’s what I found…

Performance, Performance, Performance

Many have made the observation that Leopard is more a developer’s release than a end user’s release, and looking at the improvements in the new developer tools, it’s hard to deny. From Xcode to Interface Builder and Instruments, developing software on Leopard is a whole lot more attractive than it was on Tiger, and there are just as many improvements under the cover.

One of biggest changes is the introduction of DTrace, which is a platform for profiling your software — and the system — without having to compile with special flags or anything like that.

One way to access DTrace is to use the new Instruments graphical tool (formerly X-Ray). You may not realize it, but Instruments has a command-line counterpart called — wait for it — instruments, which allows you to use the tools you create in the application in your command-line scripts.

Aside from Instruments, DTrace is used in many other tools on Leopard. List the /usr/bin directory and you will see many files with the extension .d, which are DTrace scripts. To run one, you can start up the dtrace command with the -s option, but most of the scripts will take care of this for you in the she-bang, so you can just run the script directly, e.g.,

sudo httpdstat.d

Note that you have to use the sudo command, because only superusers can run dtrace.

Here are some of the DTrace scripts you will find that may be of use in profiling your system:

  • bitesize.d – Analyse disk I/O size by process.
  • creatbyproc.d – File creates by process name.
  • httpdstat.d – Realtime httpd statistics.
  • hotspot.d – Plot disk event by location, look for hotspots.
  • cpuwalk.d – Measure which CPUs a process runs on.
  • weblatency.d – Measures web latency.

The weblatency.d script is fun to play with: start it up, and then navigate to a web site in Safari or Firefox. Now use Cmd-C to stop the script, and it will print the latency on each of the web site downloads. Pretty cool, even if it is more for web developers than scientists.

In addition to the DTrace scripts, Apple has utilized DTrace to provided a number of new commands. These commands do not have a .d extension, but they do use DTrace, and must be run as superuser.

  • dappprof – Profile user and lib function usage.
  • dapptrace – Trace user and library function usage.
  • diskhits – Disk access by file offset.
  • dtruss – Process syscall details.
  • iosnoop – Snoop I/O events as they occur.
  • iotop – Display top disk I/O events by process.
  • fddist – File descriptor usage distributions.
  • opensnoop – Snoop file opens as they occur.
  • plockstat – Front-end to DTrace to print statistics about POSIX mutexes and read/write locks.
  • procsystime – Analyse system call times.
  • rwsnoop – Snoop read/write events.
  • sampleproc – Sample processes on the CPUs.
  • topsyscall – Top syscalls by syscall name.
  • topsysproc – Top syscalls by process name.

This list includes quite a few tools, but the ‘top-like’ ones caught my eye: iotop, topsyscall, and topsysproc. top is a very useful command for getting continuously-updated data on what is occupying your CPU, and the new tools allow you to do the same thing at the system call and the file levels. Have you ever wondered why your hard disk suddenly burst into life for no apparent reason? In the past, I have used fs_usage to discover the culprit, but from now on, I think I will use iotop to find out which process is thrashing the disk.

Parallelism Rules

Apple and other vendors are starting to take parallelism more seriously. Cocoa includes new classes for parallelizing applications, and Leopard now has OpenMPI built in. OpenMPI is an implementation of the Message-Passing Interface (MPI), which allows for SPMD parallel applications to be written for shared- and distributed-memory systems. OpenMPI commands include mpic++, mpicc, and mpicxx for compiling, and mpiexec and mpirun for executing MPI apps. Unfortunately, Mac OS X doesn’t include a standard Fortran compiler, so although you will find mpif77 and mpif90, they don’t do anything. There is also the ompi_info command, which prints information about the OpenMPI installation.

Bridges and Scripting Languages

Another shift in the development landscape brought about by Leopard is better support for bridging to scripting languages like Python and Ruby. BridgeSupport allows developers to write Cocoa apps in languages other than Objective-C, but you can also support scripting in your own frameworks. To do this, you use the tool gen_bridge_metadata to scan the interface of your C or Objective-C framework, and generate the required XML file.

Another type of bridging also snuck under the radar: the swig tool has been included. SWIG also allows you to relatively easily bridge scripting languages to native code, and its a nice addition to the OS.

Leopard includes a number of other scripting-related commands, such as rails, for Ruby on Rails; gem, for Ruby package management; easy_install, for Python package installation; and config_data, for configuring Perl modules. Speaking of Perl, there is now support for building GUI apps with wxWidgets; for a demo, run the wxperl_demo.pl script.

Software Development

I have already discussed many tools of use to software developers, but there are many more. For example, if you want to open a file from the command line in Xcode’s editor, use the new xed command.

A couple of other tools point to the security improvements that have been made in Leopard: The codesign command allows developers to sign their code, so that it can be verified when installed on a user’s system. And the sandbox-exec command can be used to run an application in a sandbox, which can be used to restrict access to system resources.

Source control management has been improved with the inclusion of Subversion (svn) and SVK (svk), and the project management tool Maven (mvn) also got a guernsey.

Those developing Quicklook plugins will find qlmanage very useful, and anyone that wants to build text-based categorization into their apps (think Junk in Mail) need look no further than the Latent Semantic Mapping support provided by lsm.

Odds and Ends

To finish off, here are a few tools that didn’t really fit into any of the categories above: A perl-based command called lwp-download is designed for large file downloads from the web, and the xar command provides tar-like archiving in an extensible format. xmlwf can tell you if an XML file is well formatted, and xpath can be used to extract data from XML files using an approach similar to regular expressions.

All in all, Leopard’s got a lot to offer, much of it below the glossy, transparency-rich veneer that many have taken exception to. It’s the first UNIX-compliant version of Mac OS X, and as you would expect from any UNIX system, there’s plenty of command-line goodness for us all, and then some. Next week, /usr/sbin … only joking.

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

The upgrade broke mpif77 for ifort.

mpif77 was working and set to use ifort, but after the upgrade to 10.5 I get an OpenMPI warning message about how OpenMPI is not configured with Fortran support. I use MPICH2 and ifort and icc to build my app, so now I have to fix my system. I just noticed the problem today when I went to compile, so I have not fixed it yet. Anyone else with this problem?

intel fortran seg faults on Leopard

I've been in dialogue with the folks at Intel. I sent them simple fortran code that could be compiled with their so called Leopord supported 10.1 fortran compiler. These codes were compiled with both the 32bit and 64bit compilers. Both resulted in seg. faults when ran. I hope they fix the issues this month.

Broken mpif77

Leopard now includes a version of openmpi which is in /usr/bin. Make sure when you compile that you are using your own (old) version of mpi, which was compiled with fortran support. Use explicit paths to the mpi commands, for example.

Drew

---------------------------
Drew McCormack
http://www.maccoremac.com
http://www.macanics.net
http://www.macresearch.org

New version of intel compilers >10.1.006 ...

According to a source at intel, the new version of the 10.1 compiler > 10.1.006 should be out next Wed. 12/5/07. This depends on the release flowing smoothly through their release process, but that is the current estimate.

This new release has reportedly addressed the seg faults under Leopard when using the 32 bit compiler.

I was able to get the 64-bit (fce and cce) to work for my Fortran/C code with the 10.1.006 version of the compilers. It would seg fault when using fc and cc.