home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / apps / database / postgres / postgre4.z / postgre4 / src / access / heap / stats.c < prev   
Encoding:
C/C++ Source or Header  |  1992-08-27  |  9.4 KB  |  339 lines

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