leak 2.8 KB

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