leak 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. .TH LEAK 1
  2. .SH NAME
  3. leak, kmem \- help find memory leaks
  4. .SH SYNOPSIS
  5. .B leak
  6. [
  7. .B -bs
  8. ]
  9. [
  10. .B -f
  11. .I binary
  12. ]
  13. [
  14. .B -r
  15. .I res
  16. ]
  17. [
  18. .B -x
  19. .I width
  20. ]
  21. .I pid ...
  22. .PP
  23. .B kmem
  24. [
  25. .I kernel
  26. ]
  27. .SH DESCRIPTION
  28. .I Leak
  29. examines the named processes, which
  30. should be sharing their data and bss segments,
  31. for memory leaks.
  32. It uses a mark and sweep-style algorithm to
  33. determine which allocated blocks are no longer
  34. reachable from the set of root pointers.
  35. The set of root pointers is created by looking through
  36. the shared bss segment as well as each process's registers.
  37. .PP
  38. Unless directed otherwise,
  39. .I leak
  40. prints, for each block, a line with five space-separated fields:
  41. the string
  42. .BR block ,
  43. the address of the block,
  44. the size of the block,
  45. and the first two words of the block.
  46. Usually, the first two words of the block
  47. contain the malloc and realloc tags
  48. (see
  49. .IR malloc (2)),
  50. useful for finding who allocated the leaked blocks.
  51. .PP
  52. If the
  53. .B -s
  54. option is given,
  55. .I leak
  56. will instead present a sequence of
  57. .IR acid (1)
  58. commands that show each leaky allocation site.
  59. A comment appears next to each command to
  60. indicate how many lost blocks were allocated
  61. at that point in the program.
  62. .PP
  63. If the
  64. .B -b
  65. option is given,
  66. .I leak
  67. will print a Plan 9 image file
  68. graphically summarizing the memory arenas.
  69. In the image, each pixel represents
  70. .I res
  71. (default 8)
  72. bytes.
  73. The color code is:
  74. .TP "\w'\fIbright blue\fR 'u
  75. .I "dark blue
  76. Completely allocated.
  77. .TP
  78. .I "bright blue
  79. Contains malloc headers.
  80. .TP
  81. .I "bright red
  82. Contains malloc headers for leaked memory.
  83. .TP
  84. .I "dark red
  85. Contains leaked memory.
  86. .TP
  87. .I "yellow
  88. Completely free
  89. .TP
  90. .I "white
  91. Padding to fill out the image.
  92. .PD
  93. The bright pixels representing headers help in
  94. counting the number of blocks.
  95. Magnifying the images with
  96. .IR lens (1)
  97. is often useful.
  98. .PP
  99. If given a name rather than a list of process ids,
  100. .I leak
  101. echoes back a command-line with process ids of every process
  102. with that name.
  103. .PP
  104. The
  105. .B -f
  106. option specifies a binary to go on the
  107. .IR acid (1)
  108. command-line used to inspect the
  109. processes, and is only necessary
  110. when inspecting processes started
  111. from stripped binaries.
  112. .PP
  113. .I Kmem
  114. prints a summary of all allocated blocks in the running kernel.
  115. Each line of the summary gives
  116. the count and total size of blocks allocated at an allocation point.
  117. The list is sorted by count in decreasing order.
  118. .SH EXAMPLES
  119. List lost blocks in
  120. .IR 8.out .
  121. This depends on the fact that there is only
  122. once instance of
  123. .I 8.out
  124. running; if there were more, the output of
  125. .B "leak -s 8.out
  126. would need editing before sending to the shell.
  127. .IP
  128. .EX
  129. % leak -s 8.out
  130. leak -s 229 230
  131. % leak -s 8.out | rc
  132. src(0x0000bf1b); // 64
  133. src(0x000016f5); // 7
  134. src(0x0000a988); // 7
  135. %
  136. .EE
  137. .LP
  138. View the memory usage graphic for the window system.
  139. .IP
  140. .EX
  141. % leak -b rio | rc | page
  142. .EE
  143. .PP
  144. List the top allocation points in the kernel,
  145. first by count and then by total size:
  146. .IP
  147. .EX
  148. % kmem | sed 10q
  149. % kmem | sort -nr +1 | sed 10q
  150. .EE
  151. .SH SOURCE
  152. .B /sys/lib/acid/leak
  153. .br
  154. .B /sys/src/cmd/aux/acidleak.c
  155. .br
  156. .B /rc/bin/leak
  157. .br
  158. .B /rc/bin/kmem
  159. .SH BUGS
  160. .I Leak
  161. and
  162. .I kmem
  163. depend on the internal structure of the
  164. libc pool memory allocator (see
  165. .IR pool (2)).
  166. Since the ANSI/POSIX environment uses a different
  167. allocator,
  168. .I leak
  169. will not work on APE programs.