benchmark_admin.xml 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. <?xml version="1.0" encoding='ISO-8859-1'?>
  2. <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
  3. "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd" [
  4. <!-- Include general documentation entities -->
  5. <!ENTITY % docentities SYSTEM "../../../docbook/entities.xml">
  6. %docentities;
  7. ]>
  8. <!-- Module User's Guide -->
  9. <chapter>
  10. <title>&adminguide;</title>
  11. <section>
  12. <title>Overview</title>
  13. <para>
  14. This module helps developers to benchmark their module functions. By adding
  15. this module's functions via the configuration file or through its API, &kamailio;
  16. can log profiling information for every function.
  17. </para>
  18. <para>
  19. The duration between calls to start_timer and log_timer is stored and logged
  20. via &kamailio;'s logging facility. Please note that all durations are given as
  21. microseconds (don't confuse with milliseconds!).
  22. </para>
  23. </section>
  24. <section>
  25. <title>Dependencies</title>
  26. <section>
  27. <title>&kamailio; Modules</title>
  28. <para>
  29. The following modules must be loaded before this module:
  30. <itemizedlist>
  31. <listitem>
  32. <para>
  33. <emphasis>No dependencies on other &kamailio; modules</emphasis>.
  34. </para>
  35. </listitem>
  36. </itemizedlist>
  37. </para>
  38. </section>
  39. <section>
  40. <title>External Libraries or Applications</title>
  41. <para>
  42. The following libraries or applications must be installed before running
  43. &kamailio; with this module loaded:
  44. <itemizedlist>
  45. <listitem>
  46. <para>
  47. <emphasis>None</emphasis>.
  48. </para>
  49. </listitem>
  50. </itemizedlist>
  51. </para>
  52. </section>
  53. </section>
  54. <section>
  55. <title>Parameters</title>
  56. <section>
  57. <title><varname>enable</varname> (int)</title>
  58. <para>
  59. Even when the module is loaded, benchmarking is not enabled
  60. per default. This variable may have three different values:
  61. <itemizedlist>
  62. <listitem>
  63. <para>
  64. -1 - Globally disable benchmarking
  65. </para>
  66. </listitem>
  67. <listitem>
  68. <para>
  69. 0 - Enable per-timer enabling. Single timers are inactive by default
  70. and can be activated through the MI interface as soon as that feature is
  71. implemented.
  72. </para>
  73. </listitem>
  74. <listitem>
  75. <para>
  76. 1 - Globally enable benchmarking
  77. </para>
  78. </listitem>
  79. </itemizedlist>
  80. </para>
  81. <para>
  82. <emphasis>
  83. Default value is <quote>0</quote>.
  84. </emphasis>
  85. </para>
  86. <example>
  87. <title>Set <varname>enable</varname> parameter</title>
  88. <programlisting format="linespecific">
  89. ...
  90. modparam("benchmark", "enable", 1)
  91. ...
  92. </programlisting>
  93. </example>
  94. </section>
  95. <section>
  96. <title><varname>granularity</varname> (int)</title>
  97. <para>
  98. Logging normally is not done for every reference to the log_timer()
  99. function, but only every n'th call. n is defined through this variable.
  100. A sensible granularity seems to be 100.
  101. </para>
  102. <para>
  103. <emphasis>
  104. Default value is <quote>1</quote>.
  105. </emphasis>
  106. </para>
  107. <example>
  108. <title>Set <varname>granularity</varname> parameter</title>
  109. <programlisting format="linespecific">
  110. ...
  111. modparam("benchmark", "granularity", 500)
  112. ...
  113. </programlisting>
  114. </example>
  115. </section>
  116. <section>
  117. <title><varname>loglevel</varname> (int)</title>
  118. <para>
  119. Set the log level for the benchmark logs. These levels should be used:
  120. <itemizedlist>
  121. <listitem><para>-5 - L_ALERT</para></listitem>
  122. <listitem><para>-4 - L_BUG</para></listitem>
  123. <listitem><para>-3 - L_CRIT</para></listitem>
  124. <listitem><para>-2 - L_CRIT (no prefix)</para></listitem>
  125. <listitem><para>-1 - L_ERR</para></listitem>
  126. <listitem><para>0 - L_WARN</para></listitem>
  127. <listitem><para>1 - L_NOTICE</para></listitem>
  128. <listitem><para>2 - L_INFO</para></listitem>
  129. <listitem><para>3 - L_DBG</para></listitem>
  130. </itemizedlist>
  131. </para>
  132. <para>
  133. <emphasis>
  134. Default value is <quote>3</quote> (L_INFO).
  135. </emphasis>
  136. </para>
  137. <example>
  138. <title>Set <varname>loglevel</varname> parameter</title>
  139. <programlisting format="linespecific">
  140. ...
  141. modparam("benchmark", "loglevel", 4)
  142. ...
  143. </programlisting>
  144. </example>
  145. <para>
  146. This will set the logging level to L_DBG.
  147. </para>
  148. </section>
  149. </section>
  150. <section>
  151. <title>Functions</title>
  152. <section>
  153. <title>
  154. <function moreinfo="none">bm_start_timer(name)</function>
  155. </title>
  156. <para>
  157. Start timer <quote>name</quote>. A later call to
  158. <quote>bm_log_timer()</quote> logs this timer..
  159. </para>
  160. <example>
  161. <title><function>bm_start_timer</function> usage</title>
  162. <programlisting format="linespecific">
  163. ...
  164. bm_start_timer("test");
  165. ...
  166. </programlisting>
  167. </example>
  168. </section>
  169. <section>
  170. <title>
  171. <function moreinfo="none">bm_log_timer(name)</function>
  172. </title>
  173. <para>
  174. This function logs the timer with the given ID. The following data are
  175. logged:
  176. <itemizedlist>
  177. <listitem>
  178. <para><emphasis>Last msgs</emphasis> is the number of calls in the last logging interval. This equals the granularity variable.
  179. </para>
  180. </listitem>
  181. </itemizedlist>
  182. <itemizedlist>
  183. <listitem>
  184. <para><emphasis>Last sum</emphasis> is the accumulated duration in the current logging interval (i.e. for the last <quote>granularity</quote> calls).
  185. </para>
  186. </listitem>
  187. </itemizedlist>
  188. <itemizedlist>
  189. <listitem>
  190. <para><emphasis>Last min</emphasis> is the minimum duration between start/log_timer calls during the last interval.
  191. </para>
  192. </listitem>
  193. </itemizedlist>
  194. <itemizedlist>
  195. <listitem>
  196. <para><emphasis>Last max</emphasis> - maximum duration.
  197. </para>
  198. </listitem>
  199. </itemizedlist>
  200. <itemizedlist>
  201. <listitem>
  202. <para><emphasis>Last average</emphasis> is the average duration between
  203. bm_start_timer() and bm_log_timer() since the last logging.
  204. </para>
  205. </listitem>
  206. </itemizedlist>
  207. <itemizedlist>
  208. <listitem>
  209. <para><emphasis>Global msgs</emphasis> number of calls to log_timer.
  210. </para>
  211. </listitem>
  212. </itemizedlist>
  213. <itemizedlist>
  214. <listitem>
  215. <para><emphasis>Global sum</emphasis> total duration in microseconds.
  216. </para>
  217. </listitem>
  218. </itemizedlist>
  219. <itemizedlist>
  220. <listitem>
  221. <para><emphasis>Global min</emphasis>... You get the point. :)
  222. </para>
  223. </listitem>
  224. </itemizedlist>
  225. <itemizedlist>
  226. <listitem>
  227. <para><emphasis>Global max</emphasis> also obvious.
  228. </para>
  229. </listitem>
  230. </itemizedlist>
  231. <itemizedlist>
  232. <listitem>
  233. <para><emphasis>Global avg</emphasis> possibly the most interesting value.
  234. </para>
  235. </listitem>
  236. </itemizedlist>
  237. </para>
  238. <example>
  239. <title><function>bm_log_timer</function> usage</title>
  240. <programlisting format="linespecific">
  241. ...
  242. bm_log_timer("test");
  243. ...
  244. </programlisting>
  245. </example>
  246. </section>
  247. </section>
  248. <section>
  249. <title>Exported pseudo-variables</title>
  250. <para>
  251. Exported pseudo-variables are listed in the next sections.
  252. </para>
  253. <section>
  254. <title>$BM_time_diff</title>
  255. <para>
  256. <emphasis>$BM_time_diff</emphasis> - the time difference
  257. elapsed between calls of bm_start_timer(name) and
  258. bm_log_timer(name). The value is 0 if no bm_log_timer()
  259. was called.
  260. </para>
  261. </section>
  262. </section>
  263. <section>
  264. <title>MI Commands</title>
  265. <section>
  266. <title><function moreinfo="none">bm_enable_global</function></title>
  267. <para>
  268. Enables/disables the module. Parameter may be -1, 0 or 1. See
  269. discription of "enable" parameter.
  270. </para>
  271. </section>
  272. <section>
  273. <title><function moreinfo="none">bm_enable_timer</function></title>
  274. <para>
  275. Enable or disable a single timer. The following example enables
  276. timer "test" (the second parameter must be 0 to disable):
  277. </para>
  278. <example>
  279. <title>Enabling a timer</title>
  280. <programlisting format="linespecific">
  281. ...
  282. &ctltool; fifo bm_enable_timer test 1
  283. ...
  284. </programlisting>
  285. </example>
  286. </section>
  287. <section>
  288. <title><function moreinfo="none">bm_granularity</function></title>
  289. <para>
  290. Modifies the benchmarking granularity. See "granularity" variable.
  291. </para>
  292. </section>
  293. <section>
  294. <title><function moreinfo="none">bm_loglevel</function></title>
  295. <para>
  296. Modifies the module log level. See "loglevel" variable.
  297. </para>
  298. </section>
  299. </section>
  300. <section>
  301. <title>Example of usage</title>
  302. <para>
  303. Measure the duration of user location lookup.
  304. </para>
  305. <example>
  306. <title>benchmark usage</title>
  307. <programlisting format="linespecific">
  308. ...
  309. bm_start_timer("usrloc-lookup");
  310. lookup("location");
  311. bm_log_timer("usrloc-lookup");
  312. ...
  313. </programlisting>
  314. </example>
  315. </section>
  316. </chapter>