Cornichon

Posted: March 17th, 2010 | Author: | Filed under: Cornichon, macOS | Tags: , , , , , , , , | No Comments »

Cornichon is a powerful tool you can use to dynamically profile Mac OS X applications on the system and track the process’ performance over time.

Figure 1: Profiling Safari with Cornichon

screenshot-small

The Cornichon application includes the ability to:

  • Profile Mac OS X applications
  • Profile iPhone applications running in the iPhone simulator
  • Examine the behavior of one or more processes
  • See the different collected data of a process in real time in a graph
  • Export the data as TAB files that you can later easily import in Apple Numbers or Microsoft Excel

With the Cornichon application, you can inspect different aspects of a process’ behavior:

  • CPU usage
  • Resident memory size (RSIZE)
  • Resident private address space size (RPRVT)
  • Total memory size (VSIZE)
  • Number of threads

Why using Cornichon?

Apple provides several tools that allow you to profile Mac OS X applications: Activity Monitor, Instruments, and some command line tools like ‘top’ or ‘ps’.
But none of these tools provide a real-time graph to profile a specific application:

  • Activity Monitor has no graph view which makes it difficult to see how the process’ performance evolves over time.
  • The ‘Activity Monitor’ template of Instruments only monitors the system workload but not the workload of a specific application.

Cornichon System Requirements

  • Mac OS X 10.5.8 or later.
  • Universal application (for both Intel and PowerPC-based Macs).

FAQ


Determining the running kernel mode on 10.6

Posted: March 6th, 2010 | Author: | Filed under: macOS, Programming | Tags: , , , , , , , | 1 Comment »

It might be useful in some cases to know if the MacOS kernel is running in the 32-bit or 64-bit (K64) mode. This is useful for example if you write an application like ‘System Profiler’ that displays the details of the currently running system:

'System Software Overview' in the 'System Profiler' app

Obviously this post only applies to intel machines running on Snow Leopard (see my previous post ‘Intel 64-bit summary’). To simplify the code, I assume that you compiled your application with the 10.6 SDK.

In the IOKit framework on 10.6 the function OSKextGetRunningKernelArchitecture is defined as followed in the OSKext.h header:


/*!
 * @function OSKextGetRunningKernelArchitecture
 * @abstract Returns the architecture of the running kernel.
 *
 * @result
 * The architecture of the running kernel.
 * The caller does not own the returned pointer and should not free it.
 *
 * @discussion
 * This function consults the kernel task and returns a pointer to the
 * NXArchInfo struct representing its architecture.
 * The running kernel's architecture does not necessarily match that
 * of user space tasks (for example, a 32-bit user space task could be
 * running with a 64-bit kernel, or vice-versa).
 */
CF_EXPORT const NXArchInfo *
OSKextGetRunningKernelArchitecture(void)
                AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER;

This function is the one I use to determine the current running kernel mode:

#import <Foundation/Foundation.h>
#import <mach-o/arch.h>

// OSKextGetRunningKernelArchitecture is not available in
// the 10.6 SDK headers, but exported since 10.6.
extern const NXArchInfo *OSKextGetRunningKernelArchitecture(void);

static BOOL Is64BitKernel()
{
	BOOL isK64 = NO;
	
	const NXArchInfo *archInfo = OSKextGetRunningKernelArchitecture();
	if (archInfo != NULL)
	{
		isK64 = ((archInfo->cputype & CPU_ARCH_ABI64) != 0);
	}
	
    return isK64;
}

int main (int argc, const char * argv[])
{
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
	
	fprintf(stderr, "Is 64-bit kernel: %d\n", Is64BitKernel());
   
    [pool drain];
    return 0;
}

And don’t forget to link against the IOKit framework.

Also note that it is quite easy to make the previous code compiling with the 10.5 (or earlier) SDK by dynamically getting the address of the OSKextGetRunningKernelArchitecture function and checking if the address is not NULL.


Intel 64-bit summary

Posted: January 8th, 2010 | Author: | Filed under: macOS | Tags: , , , , , , , , , , | 6 Comments »

Since people are confused regarding Intel 64-bit, here is a brief summary of what can run on which Intel processor.

To run a 64-bit application, you obviously need a 64-bit processor. All the machines that Apple currently ships have a 64-bit processor.

  • Only the ‘Intel Core Solo‘ and ‘Intel Core Duo‘ processors are 32-bit. On such machines, you won’t be able to run 64-bit apps.
  • The ‘Intel Core 2 Duo‘ and ‘Xeon‘ processors are 64-bit.

Useful link on Apple Support: How to tell if your Intel-based Mac has a 32-bit or 64-bit processor.

If you have a 64-bit processor (‘Intel Core 2 Duo’ or better), there are 3 levels of 64-bit applications:

  • to run a 64-bit faceless application: you need 10.4 and later.
  • to run a 64-bit application with UI (Cocoa): you need 10.5 and later.
  • to run the 64-bit kernel (and run 64-bit kernel extensions): you need 10.6 and later and a K64-capable machine (the EFI needs to be 64-bit). By default only the Xserve (2008 and later) will run the 64-bit kernel. On other K64-capable machines, you have to explicitely turn on the 64-bit kernel to use it.

Useful link on Apple Developer: Introduction to 64-Bit Transition Guide.