Tutorial :How to determine where code spends a lot of time in a kernel space (system calls)


I noticed that 10% my code run is system space. However I do NOT know which system calls. I suspect, though, it is either has to do files or timestamps.

Is there a tool to figure out which system calls are the culprits? Also, I want to know the frequency of (and location) of calls (and callee) .

I am on AS3



Both strace and truss will help you see which system calls are taking time. Two useful options for strace are:

  1. -T to show the time spent in each system call,
  2. -c to summarize syscall counts, calls, error counts as a table.

The two options are mutually exclusive though.

You may want a full system profiling tool, to allow you to profile the kernel in more detail. DTrace is probably the best if you have it on your platform.

By platform, here are some options:

DTrace can even help you profile your C/C++ code with the pid provider, e.g. see here.


If you are on Linux have a look at strace.

If you're on one of the other Unixes see if truss is available.


If your system has it then the truss command should do what you want.


If it is 10% then try this method for 30 samples. You will see the exact calls on ~3 samples, maybe 2, maybe 4.


Again on Linux, you could try the oprofile profiler. Make sure you have debug symbols available for libc and the kernel (many distributions have these on separate packages). It profiles entire systems, not (just) single processes. I've gotten valuable information from it.


On Solaris, you can use dtrace.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »