Implement caching of print_sockaddr_by_inode

As -yy parser, compared to -y, needs to do at least 5 extra syscalls
(getxattr, socket, sendmsg, recvmsg, close) to print socket details,
caching results of netlink conversations between strace and kernel
noticeably reduces amount of system time spent by strace.

The caching is safe since sockets do not change their addresses after
successful bind or connect syscall.

* defs.h (string_quote, print_sockaddr_by_inode_cached): New prototypes.
* socketutils.c (cache_entry): New type.
(CACHE_SIZE, CACHE_MASK): New macros.
(cache): New static array.
(cache_and_print_inode_details): New static function.
(print_sockaddr_by_inode_cached): New function.
(inet_parse_response, unix_parse_response): Use
cache_and_print_inode_details.
* util.c (printfd): Use string_quote and print_sockaddr_by_inode_cached.
(string_quote): Remove static qualifier.
* NEWS: Mention this improvement.
* tests/unix-yy.c (main): Update.
5 files changed
tree: 2e4c8c4568f19cbffe2933066e42a0c7ce937404
  1. .gitignore
  2. .mailmap
  3. .travis.yml
  4. AUTHORS
  5. COPYING
  6. CREDITS.in
  7. ChangeLog-CVS
  8. HACKING-scripts
  9. INSTALL
  10. Makefile.am
  11. NEWS
  12. README
  13. README-hacking
  14. README-linux-ptrace
  15. README-mpers
  16. access.c
  17. affinity.c
  18. aio.c
  19. alpha.c
  20. bjm.c
  21. block.c
  22. bootstrap
  23. bpf.c
  24. build_static_example.sh
  25. cacheflush.c
  26. capability.c
  27. caps0.h
  28. caps1.h
  29. chdir.c
  30. chmod.c
  31. clone.c
  32. configure.ac
  33. count.c
  34. debian/
  35. defs.h
  36. desc.c
  37. dirent.c
  38. dirent64.c
  39. empty.h
  40. epoll.c
  41. errnoent.sh
  42. evdev.c
  43. eventfd.c
  44. execve.c
  45. exit.c
  46. fadvise.c
  47. fallocate.c
  48. fanotify.c
  49. fchownat.c
  50. fcntl.c
  51. fetch_seccomp_fprog.c
  52. fetch_struct_flock.c
  53. file.c
  54. file_handle.c
  55. flock.c
  56. flock.h
  57. futex.c
  58. gcc_compat.h
  59. generate_mpers_am.sh
  60. generate_sen.sh
  61. generate_xlat_in.sh
  62. get_robust_list.c
  63. getcpu.c
  64. getcwd.c
  65. getrandom.c
  66. git-set-file-times
  67. git-version-gen
  68. gitlog-to-changelog
  69. hostname.c
  70. inotify.c
  71. io.c
  72. ioctl.c
  73. ioctlsort.c
  74. ioperm.c
  75. iopl.c
  76. ioprio.c
  77. ipc_defs.h
  78. ipc_msg.c
  79. ipc_msgctl.c
  80. ipc_sem.c
  81. ipc_shm.c
  82. ipc_shmctl.c
  83. kcmp.c
  84. kernel_types.h
  85. kexec.c
  86. keyctl.c
  87. ldt.c
  88. link.c
  89. linux/
  90. lookup_dcookie.c
  91. loop.c
  92. lseek.c
  93. m4/
  94. maint/
  95. make-dist
  96. mem.c
  97. membarrier.c
  98. memfd_create.c
  99. mknod.c
  100. mount.c
  101. mpers.awk
  102. mpers.sh
  103. mpers_test.sh
  104. mpers_type.h
  105. mq.c
  106. mtd.c
  107. native_defs.h
  108. net.c
  109. open.c
  110. or1k_atomic.c
  111. pathtrace.c
  112. perf.c
  113. personality.c
  114. poll.c
  115. prctl.c
  116. print_mq_attr.c
  117. print_msgbuf.c
  118. print_sigevent.c
  119. print_time.c
  120. print_timex.c
  121. printmode.c
  122. printrusage.c
  123. printsiginfo.c
  124. printsiginfo.h
  125. printstat.h
  126. process.c
  127. process_vm.c
  128. ptp.c
  129. ptrace.h
  130. qemu_multiarch_testing/
  131. quota.c
  132. readahead.c
  133. readlink.c
  134. reboot.c
  135. regs.h
  136. renameat.c
  137. resource.c
  138. rtc.c
  139. sched.c
  140. scsi.c
  141. seccomp.c
  142. seccomp_fprog.h
  143. sendfile.c
  144. sigaltstack.c
  145. sigevent.h
  146. signal.c
  147. signalent.sh
  148. signalfd.c
  149. sigreturn.c
  150. sock.c
  151. socketutils.c
  152. sram_alloc.c
  153. statfs.c
  154. strace-graph
  155. strace-log-merge
  156. strace.1
  157. strace.c
  158. strace.spec
  159. swapon.c
  160. sync_file_range.c
  161. syscall.c
  162. syscallent.sh
  163. sysctl.c
  164. sysinfo.c
  165. syslog.c
  166. sysmips.c
  167. term.c
  168. test/
  169. tests/
  170. time.c
  171. times.c
  172. travis-ci.sh
  173. truncate.c
  174. uid.c
  175. uid16.c
  176. umask.c
  177. umount.c
  178. uname.c
  179. unwind.c
  180. userfaultfd.c
  181. util.c
  182. utime.c
  183. utimes.c
  184. v4l2.c
  185. vsprintf.c
  186. wait.c
  187. xattr.c
  188. xlat/
  189. xlate.el
  190. xmalloc.c