stats.c
上传用户:blenddy
上传日期:2007-01-07
资源大小:6495k
文件大小:9k
源码类别:

数据库系统

开发平台:

Unix_Linux

  1. /*-------------------------------------------------------------------------
  2.  *
  3.  * stats.c
  4.  *   heap access method debugging statistic collection routines
  5.  *
  6.  * Copyright (c) 1994, Regents of the University of California
  7.  *
  8.  *
  9.  * IDENTIFICATION
  10.  *   $Header: /usr/local/cvsroot/pgsql/src/backend/access/heap/stats.c,v 1.16.2.2 1999/08/02 05:56:37 scrappy Exp $
  11.  *
  12.  * NOTES
  13.  *   initam should be moved someplace else.
  14.  *
  15.  *-------------------------------------------------------------------------
  16.  */
  17. #include <time.h>
  18. #include "postgres.h"
  19. #include "access/heapam.h"
  20. static void InitHeapAccessStatistics(void);
  21. /* ----------------
  22.  * InitHeapAccessStatistics
  23.  * ----------------
  24.  */
  25. HeapAccessStatistics heap_access_stats = (HeapAccessStatistics) NULL;
  26. static void
  27. InitHeapAccessStatistics()
  28. {
  29. MemoryContext oldContext;
  30. HeapAccessStatistics stats;
  31. /* ----------------
  32.  * make sure we don't initialize things twice
  33.  * ----------------
  34.  */
  35. if (heap_access_stats != NULL)
  36. return;
  37. /* ----------------
  38.  * allocate statistics structure from the top memory context
  39.  * ----------------
  40.  */
  41. oldContext = MemoryContextSwitchTo(TopMemoryContext);
  42. stats = (HeapAccessStatistics)
  43. palloc(sizeof(HeapAccessStatisticsData));
  44. /* ----------------
  45.  * initialize fields to default values
  46.  * ----------------
  47.  */
  48. stats->global_open = 0;
  49. stats->global_openr = 0;
  50. stats->global_close = 0;
  51. stats->global_beginscan = 0;
  52. stats->global_rescan = 0;
  53. stats->global_endscan = 0;
  54. stats->global_getnext = 0;
  55. stats->global_fetch = 0;
  56. stats->global_insert = 0;
  57. stats->global_delete = 0;
  58. stats->global_replace = 0;
  59. stats->global_mark4update = 0;
  60. stats->global_markpos = 0;
  61. stats->global_restrpos = 0;
  62. stats->global_BufferGetRelation = 0;
  63. stats->global_RelationIdGetRelation = 0;
  64. stats->global_RelationIdGetRelation_Buf = 0;
  65. stats->global_getreldesc = 0;
  66. stats->global_heapgettup = 0;
  67. stats->global_RelationPutHeapTuple = 0;
  68. stats->global_RelationPutLongHeapTuple = 0;
  69. stats->local_open = 0;
  70. stats->local_openr = 0;
  71. stats->local_close = 0;
  72. stats->local_beginscan = 0;
  73. stats->local_rescan = 0;
  74. stats->local_endscan = 0;
  75. stats->local_getnext = 0;
  76. stats->local_fetch = 0;
  77. stats->local_insert = 0;
  78. stats->local_delete = 0;
  79. stats->local_replace = 0;
  80. stats->local_mark4update = 0;
  81. stats->local_markpos = 0;
  82. stats->local_restrpos = 0;
  83. stats->local_BufferGetRelation = 0;
  84. stats->local_RelationIdGetRelation = 0;
  85. stats->local_RelationIdGetRelation_Buf = 0;
  86. stats->local_getreldesc = 0;
  87. stats->local_heapgettup = 0;
  88. stats->local_RelationPutHeapTuple = 0;
  89. stats->local_RelationPutLongHeapTuple = 0;
  90. stats->local_RelationNameGetRelation = 0;
  91. stats->global_RelationNameGetRelation = 0;
  92. /* ----------------
  93.  * record init times
  94.  * ----------------
  95.  */
  96. time(&stats->init_global_timestamp);
  97. time(&stats->local_reset_timestamp);
  98. time(&stats->last_request_timestamp);
  99. /* ----------------
  100.  * return to old memory context
  101.  * ----------------
  102.  */
  103. MemoryContextSwitchTo(oldContext);
  104. heap_access_stats = stats;
  105. }
  106. #ifdef NOT_USED
  107. /* ----------------
  108.  * ResetHeapAccessStatistics
  109.  * ----------------
  110.  */
  111. void
  112. ResetHeapAccessStatistics()
  113. {
  114. HeapAccessStatistics stats;
  115. /* ----------------
  116.  * do nothing if stats aren't initialized
  117.  * ----------------
  118.  */
  119. if (heap_access_stats == NULL)
  120. return;
  121. stats = heap_access_stats;
  122. /* ----------------
  123.  * reset local counts
  124.  * ----------------
  125.  */
  126. stats->local_open = 0;
  127. stats->local_openr = 0;
  128. stats->local_close = 0;
  129. stats->local_beginscan = 0;
  130. stats->local_rescan = 0;
  131. stats->local_endscan = 0;
  132. stats->local_getnext = 0;
  133. stats->local_fetch = 0;
  134. stats->local_insert = 0;
  135. stats->local_delete = 0;
  136. stats->local_replace = 0;
  137. stats->local_mark4update = 0;
  138. stats->local_markpos = 0;
  139. stats->local_restrpos = 0;
  140. stats->local_BufferGetRelation = 0;
  141. stats->local_RelationIdGetRelation = 0;
  142. stats->local_RelationIdGetRelation_Buf = 0;
  143. stats->local_getreldesc = 0;
  144. stats->local_heapgettup = 0;
  145. stats->local_RelationPutHeapTuple = 0;
  146. stats->local_RelationPutLongHeapTuple = 0;
  147. /* ----------------
  148.  * reset local timestamps
  149.  * ----------------
  150.  */
  151. time(&stats->local_reset_timestamp);
  152. time(&stats->last_request_timestamp);
  153. }
  154. #endif
  155. #ifdef NOT_USED
  156. /* ----------------
  157.  * GetHeapAccessStatistics
  158.  * ----------------
  159.  */
  160. HeapAccessStatistics
  161. GetHeapAccessStatistics()
  162. {
  163. HeapAccessStatistics stats;
  164. /* ----------------
  165.  * return nothing if stats aren't initialized
  166.  * ----------------
  167.  */
  168. if (heap_access_stats == NULL)
  169. return NULL;
  170. /* ----------------
  171.  * record the current request time
  172.  * ----------------
  173.  */
  174. time(&heap_access_stats->last_request_timestamp);
  175. /* ----------------
  176.  * allocate a copy of the stats and return it to the caller.
  177.  * ----------------
  178.  */
  179. stats = (HeapAccessStatistics)
  180. palloc(sizeof(HeapAccessStatisticsData));
  181. memmove(stats,
  182. heap_access_stats,
  183. sizeof(HeapAccessStatisticsData));
  184. return stats;
  185. }
  186. #endif
  187. #ifdef NOT_USED
  188. /* ----------------
  189.  * PrintHeapAccessStatistics
  190.  * ----------------
  191.  */
  192. void
  193. PrintHeapAccessStatistics(HeapAccessStatistics stats)
  194. {
  195. /* ----------------
  196.  * return nothing if stats aren't valid
  197.  * ----------------
  198.  */
  199. if (stats == NULL)
  200. return;
  201. printf("======== heap am statistics ========n");
  202. printf("init_global_timestamp:      %s",
  203.    ctime(&(stats->init_global_timestamp)));
  204. printf("local_reset_timestamp:      %s",
  205.    ctime(&(stats->local_reset_timestamp)));
  206. printf("last_request_timestamp:     %s",
  207.    ctime(&(stats->last_request_timestamp)));
  208. printf("local/global_open:                        %6d/%6dn",
  209.    stats->local_open, stats->global_open);
  210. printf("local/global_openr:                       %6d/%6dn",
  211.    stats->local_openr, stats->global_openr);
  212. printf("local/global_close:                       %6d/%6dn",
  213.    stats->local_close, stats->global_close);
  214. printf("local/global_beginscan:                   %6d/%6dn",
  215.    stats->local_beginscan, stats->global_beginscan);
  216. printf("local/global_rescan:                      %6d/%6dn",
  217.    stats->local_rescan, stats->global_rescan);
  218. printf("local/global_endscan:                     %6d/%6dn",
  219.    stats->local_endscan, stats->global_endscan);
  220. printf("local/global_getnext:                     %6d/%6dn",
  221.    stats->local_getnext, stats->global_getnext);
  222. printf("local/global_fetch:                       %6d/%6dn",
  223.    stats->local_fetch, stats->global_fetch);
  224. printf("local/global_insert:                      %6d/%6dn",
  225.    stats->local_insert, stats->global_insert);
  226. printf("local/global_delete:                      %6d/%6dn",
  227.    stats->local_delete, stats->global_delete);
  228. printf("local/global_replace:                     %6d/%6dn",
  229.    stats->local_replace, stats->global_replace);
  230. printf("local/global_mark4update:                     %6d/%6dn",
  231.    stats->local_mark4update, stats->global_mark4update);
  232. printf("local/global_markpos:                     %6d/%6dn",
  233.    stats->local_markpos, stats->global_markpos);
  234. printf("local/global_restrpos:                    %6d/%6dn",
  235.    stats->local_restrpos, stats->global_restrpos);
  236. printf("================n");
  237. printf("local/global_BufferGetRelation:             %6d/%6dn",
  238.    stats->local_BufferGetRelation,
  239.    stats->global_BufferGetRelation);
  240. printf("local/global_RelationIdGetRelation:         %6d/%6dn",
  241.    stats->local_RelationIdGetRelation,
  242.    stats->global_RelationIdGetRelation);
  243. printf("local/global_RelationIdGetRelation_Buf:     %6d/%6dn",
  244.    stats->local_RelationIdGetRelation_Buf,
  245.    stats->global_RelationIdGetRelation_Buf);
  246. printf("local/global_getreldesc:                    %6d/%6dn",
  247.    stats->local_getreldesc, stats->global_getreldesc);
  248. printf("local/global_heapgettup:                    %6d/%6dn",
  249.    stats->local_heapgettup, stats->global_heapgettup);
  250. printf("local/global_RelationPutHeapTuple:          %6d/%6dn",
  251.    stats->local_RelationPutHeapTuple,
  252.    stats->global_RelationPutHeapTuple);
  253. printf("local/global_RelationPutLongHeapTuple:      %6d/%6dn",
  254.    stats->local_RelationPutLongHeapTuple,
  255.    stats->global_RelationPutLongHeapTuple);
  256. printf("===================================n");
  257. printf("n");
  258. }
  259. #endif
  260. #ifdef NOT_USED
  261. /* ----------------
  262.  * PrintAndFreeHeapAccessStatistics
  263.  * ----------------
  264.  */
  265. void
  266. PrintAndFreeHeapAccessStatistics(HeapAccessStatistics stats)
  267. {
  268. PrintHeapAccessStatistics(stats);
  269. if (stats != NULL)
  270. pfree(stats);
  271. }
  272. #endif
  273. /* ----------------------------------------------------------------
  274.  * access method initialization
  275.  * ----------------------------------------------------------------
  276.  */
  277. /* ----------------
  278.  * initam should someday be moved someplace else.
  279.  * ----------------
  280.  */
  281. void
  282. initam(void)
  283. {
  284. /* ----------------
  285.  * initialize heap statistics.
  286.  * ----------------
  287.  */
  288. InitHeapAccessStatistics();
  289. }