How to determine where code spends a lot of time i

2019-07-21 00:12发布

问题:

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

thx

回答1:

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:

  • Linux: strace, oprofile, SystemTap.
  • Solaris: dtrace (the original)
  • FreeBSD: dtrace
  • OS X: dtrace and Instruments; the latter is a graphical UI over DTrace and comes with Xcode.

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



回答2:

If you are on Linux have a look at strace.

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



回答3:

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



回答4:

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



回答5:

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.



回答6:

On Solaris, you can use dtrace.