确定 Linux 上用户空间绑定可执行文件中导致如此多系统时间的原因
我正在开发一个项目(编程语言),并且开始进行一些分析。当我在阶乘测试中运行时间时,我得到以下信息:
burton@smokey:~/repl$ time tests/fact.repl
real 0m4.451s
user 0m1.820s
sys 0m2.620s
我的问题出在系统时间上。除了读取输入文件(没有输出)之外,我没有执行任何系统调用。这应该是一个几乎完全受用户时间限制的应用程序。我尝试运行 strace -c 来查看是否有任何错误的系统调用占用了大量时间,但一无所获。 Gprof 也没有给我任何答案。
是否有其他工具可以找出我的应用程序中是什么占用了如此多的系统时间?难道我只是被时间命令欺骗了?当我运行 sbcl 进行相同的计算时,系统时间约为 0.03 秒,这正是我所希望的。
这是 strace -c 的完整输出:
burton@smokey:~/repl$ strace -c tests/fact.repl
% time seconds usecs/call calls errors syscall
------ ----------- ----------- --------- --------- ----------------
-nan 0.000000 0 2 read
-nan 0.000000 0 3 open
-nan 0.000000 0 2 close
-nan 0.000000 0 3 fstat
-nan 0.000000 0 12 mmap
-nan 0.000000 0 4 mprotect
-nan 0.000000 0 1 munmap
-nan 0.000000 0 16 brk
-nan 0.000000 0 2 rt_sigaction
-nan 0.000000 0 4 rt_sigprocmask
-nan 0.000000 0 1 1 ioctl
-nan 0.000000 0 3 3 access
-nan 0.000000 0 1 execve
-nan 0.000000 0 1 arch_prctl
-nan 0.000000 0 2 setrlimit
------ ----------- ----------- --------- --------- ----------------
100.00 0.000000 57 4 total
I'm working on a project (programming language) and I'm starting to do some profiling. When I run time on my factorial test, I get the following:
burton@smokey:~/repl$ time tests/fact.repl
real 0m4.451s
user 0m1.820s
sys 0m2.620s
My problem is with the sys time. I am doing no system calls other than reading the input files (there is no output). This should be an almost completely user time bound application. I have tried running strace -c to see if there are any errant system calls taking up a lot of time but have found nothing. Gprof doesn't give me any answers either.
Are there any other tools to find out what is taking so much system time in my application? Am I just being tricked by the time command? When I run sbcl doing the same calculation, the sys time is around 0.03 seconds and what I am hoping for.
Here is the complete output of strace -c:
burton@smokey:~/repl$ strace -c tests/fact.repl
% time seconds usecs/call calls errors syscall
------ ----------- ----------- --------- --------- ----------------
-nan 0.000000 0 2 read
-nan 0.000000 0 3 open
-nan 0.000000 0 2 close
-nan 0.000000 0 3 fstat
-nan 0.000000 0 12 mmap
-nan 0.000000 0 4 mprotect
-nan 0.000000 0 1 munmap
-nan 0.000000 0 16 brk
-nan 0.000000 0 2 rt_sigaction
-nan 0.000000 0 4 rt_sigprocmask
-nan 0.000000 0 1 1 ioctl
-nan 0.000000 0 3 3 access
-nan 0.000000 0 1 execve
-nan 0.000000 0 1 arch_prctl
-nan 0.000000 0 2 setrlimit
------ ----------- ----------- --------- --------- ----------------
100.00 0.000000 57 4 total
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在内存中分配和分页所需的时间算作系统时间。尝试
/usr/bin/timetests/fact.repl
——它显示了页面错误的数量。顺便说一句,“除了读取输入文件之外,我没有执行任何系统调用”和“我正在分配大量内存”是矛盾的陈述。
The time it takes to allocate and page in your memory counts as system time. Try
/usr/bin/time tests/fact.repl
-- it shows the number of page faults.By the way, "I am doing no system calls other than reading the input files" and "I am allocating gobs of memory" are contradictory statements.
考虑到
time
打印的内容,这似乎不太可能。首先,在
strace -c
下运行您的程序。这将告诉您已执行了多少个系统调用,以及其中哪些调用花费了最多时间。了解“有趣的”系统调用后,您可以使用
strace -tt -T -e trace=
获取更多详细信息。有关详细信息,请参阅 strace 手册页。由于 strace -c 显示(有效)0 时间,也许您正在分叉子进程或创建线程?在这种情况下,strace -f 可能会给出有趣的输出。
That seems unlikely given what
time
prints.First, run your program under
strace -c
. This will tell you how many system calls you've executed, and which ones of them took most time.Once you know the "interesting" system calls, you can obtain additional details with
strace -tt -T -e trace=<interesting syscall>
. See strace man page for more info.Since
strace -c
shows (effectively) 0 time, perhaps you are forking subprocesses or creating threads? In that case,strace -f
might give interesting output.我没有任何线索,但是您的程序是否使用多个线程和 Posix 同步原语(例如
pthread_mutex_lock
等...)?因为这些原语是建立在一些系统调用(futex 的)之上的。I don't have any clues, but is your program using several threads and Posix synchronisation primitives (e.g.
pthread_mutex_lock
etc...)? Because these primitives are built on some system calls (the futex ones).