prof 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. .TH PROF 1
  2. .SH NAME
  3. prof, tprof, kprof \- display profiling data
  4. .SH SYNOPSIS
  5. .B prof
  6. [
  7. .B -dr
  8. ]
  9. [
  10. .I program
  11. ]
  12. [
  13. .I profile
  14. ]
  15. .PP
  16. .B tprof
  17. .I pid
  18. .PP
  19. .B kprof
  20. .I kernel
  21. .I kpdata
  22. .SH DESCRIPTION
  23. .I Prof
  24. interprets files produced automatically by programs loaded using the
  25. .B -p
  26. option of
  27. .IR 2l (1)
  28. or other loader.
  29. The symbol table in the
  30. named program file
  31. .RL ( 2.out
  32. etc., according to
  33. .BR $objtype ,
  34. by default)
  35. is read and correlated with the
  36. profile file
  37. .RL ( prof.out
  38. by default).
  39. For each symbol, the percentage
  40. of time (in seconds) spent executing between that symbol
  41. and the next
  42. is printed (in decreasing order),
  43. together with the time spent there and
  44. the number of times that routine was called.
  45. .PP
  46. Under option
  47. .BR -d ,
  48. .I prof
  49. prints the dynamic call graph of the target program,
  50. annotating the calls with the time spent in each routine
  51. and those it calls, recursively. The output is indented
  52. two spaces for each call, and is formatted as
  53. .EX
  54. symbol:time/ncall
  55. .EE
  56. where
  57. .I symbol
  58. is the entry point of the call,
  59. .I time
  60. is in milliseconds,
  61. and
  62. .I ncall
  63. is the number of times that entry point was called at that
  64. point in the call graph. If
  65. .I ncall
  66. is one, the
  67. .B /ncall
  68. is elided.
  69. Normally recursive calls are compressed to keep the output brief;
  70. option
  71. .B -r
  72. prints the full call graph.
  73. .PP
  74. The size of the buffer
  75. in
  76. .I program
  77. used to hold the profiling
  78. data, by default 2000 entries,
  79. may be controlled by setting the environment variable
  80. .B profsize
  81. before running
  82. .IR program .
  83. If the buffer fills, subsequent function calls may not be recorded.
  84. .PP
  85. The profiling code provided by the linker initializes itself to profile the current pid,
  86. producing a file called
  87. .B prof.\f2pid\fP.
  88. If a process forks, only the parent will continue to be profiled. Forked children
  89. can cause themselves to be profile by calling
  90. .EX
  91. prof(fn, arg, entries, what)
  92. .EE
  93. which causes the function \f2fn\fP(\f2arg\fP) to be profiled. When \f2fn\fP
  94. returns
  95. .B prof.\f2pid\fP
  96. is produced for the current process pid.
  97. .PP
  98. The environment variable
  99. .B proftype
  100. can be set to one of
  101. .BR user ,
  102. .BR kernel ,
  103. .BR elapsed ,
  104. or
  105. .BR sample ,
  106. to profile time measured spent in user mode, time spent in user+kernel mode, or elapsed time,
  107. using the cycle counter, or the time in user mode using the kernel's HZ clock. The cycle counter
  108. is currently only available on modern PCs and on the PowerPC. Default profiling measures user
  109. time, using the cycle counter if it is available.
  110. .PP
  111. .I Tprof
  112. is similar to
  113. .IR prof ,
  114. but is intended for profiling multiprocess programs.
  115. It uses the
  116. .BI /proc/ pid /profile
  117. file to collect instruction frequency counts for the text image associated with the process,
  118. for all processes that share that text.
  119. It must be run while the program is still active, since the data is stored with the running program.
  120. To enable
  121. .I tprof
  122. profiling for a given process,
  123. .EX
  124. echo profile > /proc/\f2pid\f1/ctl
  125. .EE
  126. and then, after the program has run for a while, execute
  127. .EX
  128. tprof \f2pid\f1
  129. .EE
  130. Since the data collected for
  131. .I tprof
  132. is based on interrupt-time sampling of the program counter,
  133. .I tprof
  134. has no
  135. .B -d
  136. or
  137. .B -r
  138. options.
  139. .PP
  140. .I Kprof
  141. is similar to
  142. .IR prof ,
  143. but presents the data accumulated by the kernel
  144. profiling device,
  145. .IR kprof (3) .
  146. The symbol table file, that of the operating system kernel,
  147. and the data file, typically
  148. .BR /dev/kpdata ,
  149. must be provided.
  150. .I Kprof
  151. has no options and cannot present dynamic data.
  152. .SH SOURCE
  153. .B /sys/src/cmd/prof.c
  154. .br
  155. .B /sys/src/cmd/kprof.c
  156. .SH SEE ALSO
  157. .IR 2l (1),
  158. .IR kprof (3)