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

孤人 提交于 2019-12-11 02:28:33

问题


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.



来源:https://stackoverflow.com/questions/1588970/how-to-determine-where-code-spends-a-lot-of-time-in-a-kernel-space-system-calls

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!