1 /*-------------------------------------------------------------------------
4 * heap access method debugging statistic collection routines
6 * Copyright (c) 1994, Regents of the University of California
10 * $Header: /cvsroot/pgsql/src/backend/access/heap/Attic/stats.c,v 1.6 1996/11/03 12:34:55 scrappy Exp $
13 * initam should be moved someplace else.
15 *-------------------------------------------------------------------------
22 #include "access/relscan.h"
24 #include "access/heapam.h"
26 #include "nodes/memnodes.h"
28 #include "utils/mcxt.h"
30 #include "utils/palloc.h"
33 # include "regex/utils.h"
39 * InitHeapAccessStatistics
42 HeapAccessStatistics heap_access_stats = (HeapAccessStatistics) NULL;
45 InitHeapAccessStatistics()
47 MemoryContext oldContext;
48 HeapAccessStatistics stats;
51 * make sure we don't initialize things twice
54 if (heap_access_stats != NULL)
58 * allocate statistics structure from the top memory context
61 oldContext = MemoryContextSwitchTo(TopMemoryContext);
63 stats = (HeapAccessStatistics)
64 palloc(sizeof(HeapAccessStatisticsData));
67 * initialize fields to default values
70 stats->global_open = 0;
71 stats->global_openr = 0;
72 stats->global_close = 0;
73 stats->global_beginscan = 0;
74 stats->global_rescan = 0;
75 stats->global_endscan = 0;
76 stats->global_getnext = 0;
77 stats->global_fetch = 0;
78 stats->global_insert = 0;
79 stats->global_delete = 0;
80 stats->global_replace = 0;
81 stats->global_markpos = 0;
82 stats->global_restrpos = 0;
83 stats->global_BufferGetRelation = 0;
84 stats->global_RelationIdGetRelation = 0;
85 stats->global_RelationIdGetRelation_Buf = 0;
86 stats->global_getreldesc = 0;
87 stats->global_heapgettup = 0;
88 stats->global_RelationPutHeapTuple = 0;
89 stats->global_RelationPutLongHeapTuple = 0;
91 stats->local_open = 0;
92 stats->local_openr = 0;
93 stats->local_close = 0;
94 stats->local_beginscan = 0;
95 stats->local_rescan = 0;
96 stats->local_endscan = 0;
97 stats->local_getnext = 0;
98 stats->local_fetch = 0;
99 stats->local_insert = 0;
100 stats->local_delete = 0;
101 stats->local_replace = 0;
102 stats->local_markpos = 0;
103 stats->local_restrpos = 0;
104 stats->local_BufferGetRelation = 0;
105 stats->local_RelationIdGetRelation = 0;
106 stats->local_RelationIdGetRelation_Buf = 0;
107 stats->local_getreldesc = 0;
108 stats->local_heapgettup = 0;
109 stats->local_RelationPutHeapTuple = 0;
110 stats->local_RelationPutLongHeapTuple = 0;
111 stats->local_RelationNameGetRelation = 0;
112 stats->global_RelationNameGetRelation = 0;
118 time(&stats->init_global_timestamp);
119 time(&stats->local_reset_timestamp);
120 time(&stats->last_request_timestamp);
123 * return to old memory context
126 (void) MemoryContextSwitchTo(oldContext);
128 heap_access_stats = stats;
132 * ResetHeapAccessStatistics
136 ResetHeapAccessStatistics()
138 HeapAccessStatistics stats;
141 * do nothing if stats aren't initialized
144 if (heap_access_stats == NULL)
147 stats = heap_access_stats;
153 stats->local_open = 0;
154 stats->local_openr = 0;
155 stats->local_close = 0;
156 stats->local_beginscan = 0;
157 stats->local_rescan = 0;
158 stats->local_endscan = 0;
159 stats->local_getnext = 0;
160 stats->local_fetch = 0;
161 stats->local_insert = 0;
162 stats->local_delete = 0;
163 stats->local_replace = 0;
164 stats->local_markpos = 0;
165 stats->local_restrpos = 0;
166 stats->local_BufferGetRelation = 0;
167 stats->local_RelationIdGetRelation = 0;
168 stats->local_RelationIdGetRelation_Buf = 0;
169 stats->local_getreldesc = 0;
170 stats->local_heapgettup = 0;
171 stats->local_RelationPutHeapTuple = 0;
172 stats->local_RelationPutLongHeapTuple = 0;
175 * reset local timestamps
178 time(&stats->local_reset_timestamp);
179 time(&stats->last_request_timestamp);
183 * GetHeapAccessStatistics
186 HeapAccessStatistics GetHeapAccessStatistics()
188 HeapAccessStatistics stats;
191 * return nothing if stats aren't initialized
194 if (heap_access_stats == NULL)
198 * record the current request time
201 time(&heap_access_stats->last_request_timestamp);
204 * allocate a copy of the stats and return it to the caller.
207 stats = (HeapAccessStatistics)
208 palloc(sizeof(HeapAccessStatisticsData));
212 sizeof(HeapAccessStatisticsData));
218 * PrintHeapAccessStatistics
222 PrintHeapAccessStatistics(HeapAccessStatistics stats)
225 * return nothing if stats aren't valid
231 printf("======== heap am statistics ========\n");
232 printf("init_global_timestamp: %s",
233 ctime(&(stats->init_global_timestamp)));
235 printf("local_reset_timestamp: %s",
236 ctime(&(stats->local_reset_timestamp)));
238 printf("last_request_timestamp: %s",
239 ctime(&(stats->last_request_timestamp)));
241 printf("local/global_open: %6d/%6d\n",
242 stats->local_open, stats->global_open);
244 printf("local/global_openr: %6d/%6d\n",
245 stats->local_openr, stats->global_openr);
247 printf("local/global_close: %6d/%6d\n",
248 stats->local_close, stats->global_close);
250 printf("local/global_beginscan: %6d/%6d\n",
251 stats->local_beginscan, stats->global_beginscan);
253 printf("local/global_rescan: %6d/%6d\n",
254 stats->local_rescan, stats->global_rescan);
256 printf("local/global_endscan: %6d/%6d\n",
257 stats->local_endscan, stats->global_endscan);
259 printf("local/global_getnext: %6d/%6d\n",
260 stats->local_getnext, stats->global_getnext);
262 printf("local/global_fetch: %6d/%6d\n",
263 stats->local_fetch, stats->global_fetch);
265 printf("local/global_insert: %6d/%6d\n",
266 stats->local_insert, stats->global_insert);
268 printf("local/global_delete: %6d/%6d\n",
269 stats->local_delete, stats->global_delete);
271 printf("local/global_replace: %6d/%6d\n",
272 stats->local_replace, stats->global_replace);
274 printf("local/global_markpos: %6d/%6d\n",
275 stats->local_markpos, stats->global_markpos);
277 printf("local/global_restrpos: %6d/%6d\n",
278 stats->local_restrpos, stats->global_restrpos);
280 printf("================\n");
282 printf("local/global_BufferGetRelation: %6d/%6d\n",
283 stats->local_BufferGetRelation,
284 stats->global_BufferGetRelation);
286 printf("local/global_RelationIdGetRelation: %6d/%6d\n",
287 stats->local_RelationIdGetRelation,
288 stats->global_RelationIdGetRelation);
290 printf("local/global_RelationIdGetRelation_Buf: %6d/%6d\n",
291 stats->local_RelationIdGetRelation_Buf,
292 stats->global_RelationIdGetRelation_Buf);
294 printf("local/global_getreldesc: %6d/%6d\n",
295 stats->local_getreldesc, stats->global_getreldesc);
297 printf("local/global_heapgettup: %6d/%6d\n",
298 stats->local_heapgettup, stats->global_heapgettup);
300 printf("local/global_RelationPutHeapTuple: %6d/%6d\n",
301 stats->local_RelationPutHeapTuple,
302 stats->global_RelationPutHeapTuple);
304 printf("local/global_RelationPutLongHeapTuple: %6d/%6d\n",
305 stats->local_RelationPutLongHeapTuple,
306 stats->global_RelationPutLongHeapTuple);
308 printf("===================================\n");
314 * PrintAndFreeHeapAccessStatistics
318 PrintAndFreeHeapAccessStatistics(HeapAccessStatistics stats)
320 PrintHeapAccessStatistics(stats);
325 /* ----------------------------------------------------------------
326 * access method initialization
327 * ----------------------------------------------------------------
330 * initam should someday be moved someplace else.
337 * initialize heap statistics.
340 InitHeapAccessStatistics();