我正在尝试调试使用strace -tt -f
用Python编写的多线程网络服务器,并且strace输出使我感到困惑,因为在同一线程上似乎有多个连续的使用<unfinished...>
的系统调用,并且此后未发现任何恢复:
9675 22:58:28.407844 <... recvfrom resumed> "\22RT\21Q\0\n", 7, 0, NULL, NULL) = 7
9675 22:58:28.518079 recvfrom(3, "\22RV\21Q\3\n", 7, 0, NULL, NULL) = 7
9675 22:58:28.518672 sendto(7, "\0\0\0\6\0\22RV\21Q\0\n", 12, 0, NULL, 0) = 12
9675 22:58:28.536676 poll([{fd=7, events=POLLIN|POLLPRI}], 1, 0 <unfinished ...>
9675 22:58:28.536739 <... poll resumed> ) = 1 ([{fd=7, revents=POLLIN}])
9675 22:58:28.538515 recvfrom(7, <unfinished ...>
9675 22:58:28.539400 recvfrom(7, <unfinished ...>
9675 22:58:28.539768 sendto(7, "\0\0\0\6\0\22RW\21Q\0\n", 12, 0, NULL, 0 <unfinished ...>
9675 22:58:28.540629 poll([{fd=7, events=POLLIN|POLLPRI}], 1, 0 <unfinished ...>
9675 22:58:28.540666 <... poll resumed> ) = 1 ([{fd=7, revents=POLLIN|POLLERR|POLLHUP}])
9675 22:58:28.541170 recvfrom(7, <unfinished ...>
9675 22:58:28.542603 recvfrom(7, <unfinished ...>
9675 22:58:28.543449 shutdown(7, SHUT_RDWR <unfinished ...>
9675 22:58:28.544451 close(7 <unfinished ...>
9656 22:58:28.555189 accept4(5, {sa_family=AF_INET, sin_port=htons(38282), sin_addr=inet_addr("127.0.0.1")}, [16], SOCK_CLOEXEC) = 7
9656 22:58:28.555288 ioctl(7, FIONBIO, [0]) = 0
9656 22:58:28.555338 ioctl(7, FIONBIO, [0]) = 0
9656 22:58:28.555749 getpeername(7, {sa_family=AF_INET, sin_port=htons(38282), sin_addr=inet_addr("127.0.0.1")}, [16]) = 0
9656 22:58:28.555810 getsockname(7, {sa_family=AF_INET, sin_port=htons(6000), sin_addr=inet_addr("127.0.0.1")}, [16]) = 0
9656 22:58:28.555929 getpeername(7, {sa_family=AF_INET, sin_port=htons(38282), sin_addr=inet_addr("127.0.0.1")}, [16]) = 0
9675 22:58:28.560799 sendto(7, "\0\0\0\10\0\22QP\21R\21Q\2\n", 14, 0, NULL, 0) = 14
答案 0 :(得分:0)
根据@OznOg的建议,这是因为多线程应用程序运行得太快,因此strace会降低一些结果。
作为更好的选择,我切换到了更快的perf trace ./app
并解决了问题。请注意,如果您看到perf trace
抱怨ignored trace
,则只需将事件缓冲区的大小增加sudo sh -c "echo 1032 > /proc/sys/kernel/perf_event_mlock_kb"
答案 1 :(得分:-1)
请确保您尝试使用“ recvfrom”获取数据的套接字已打开并正在返回数据,因为由于该套接字未返回任何数据,因此您的线程此时似乎卡住了。
还尝试在代码中添加异常处理以更好地对其进行调试。