mirror of
https://github.com/postgres/postgres.git
synced 2025-07-14 08:21:07 +03:00
Turned high-frequently called pgstat functions into macros
for speed. Jan
This commit is contained in:
@ -19,7 +19,7 @@
|
|||||||
*
|
*
|
||||||
* Copyright (c) 2001, PostgreSQL Global Development Group
|
* Copyright (c) 2001, PostgreSQL Global Development Group
|
||||||
*
|
*
|
||||||
* $Id: pgstat.c,v 1.1 2001/06/22 19:18:35 wieck Exp $
|
* $Id: pgstat.c,v 1.2 2001/06/29 16:29:37 wieck Exp $
|
||||||
* ----------
|
* ----------
|
||||||
*/
|
*/
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@ -757,230 +757,6 @@ pgstat_initstats(PgStat_Info *stats, Relation rel)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ----------
|
|
||||||
* pgstat_reset_heap_scan() -
|
|
||||||
*
|
|
||||||
* Called from heap_rescan() to reset the heap_scan_counted flag.
|
|
||||||
* Since the optimizer usually does a beginscan()/endscan() without
|
|
||||||
* really doing a scan, we cannot count those calls. We have to wait
|
|
||||||
* if after a beginscan() or rescan() really a call to the getnext()
|
|
||||||
* function happens.
|
|
||||||
* ----------
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
pgstat_reset_heap_scan(PgStat_Info *stats)
|
|
||||||
{
|
|
||||||
if (stats->tabentry == NULL)
|
|
||||||
return;
|
|
||||||
|
|
||||||
stats->heap_scan_counted = FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* ----------
|
|
||||||
* pgstat_count_heap_scan() -
|
|
||||||
*
|
|
||||||
* Called from heap_getnext() to tell us that now the relation
|
|
||||||
* really is scanned.
|
|
||||||
* ----------
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
pgstat_count_heap_scan(PgStat_Info *stats)
|
|
||||||
{
|
|
||||||
if (stats->tabentry == NULL)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (!stats->heap_scan_counted)
|
|
||||||
{
|
|
||||||
((PgStat_TableEntry *)(stats->tabentry))->t_numscans++;
|
|
||||||
stats->heap_scan_counted = TRUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* ----------
|
|
||||||
* pgstat_count_heap_getnext() -
|
|
||||||
*
|
|
||||||
* Called from heap_getnext() whenever a valid tuple is returned
|
|
||||||
* from a sequential scan. The above cannot get combined into this,
|
|
||||||
* because if a heap scan didn't return any tuples, the scan itself
|
|
||||||
* would be missing in the stats.
|
|
||||||
* ----------
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
pgstat_count_heap_getnext(PgStat_Info *stats)
|
|
||||||
{
|
|
||||||
if (stats->tabentry == NULL)
|
|
||||||
return;
|
|
||||||
|
|
||||||
((PgStat_TableEntry *)(stats->tabentry))->t_tuples_returned++;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* ----------
|
|
||||||
* pgstat_count_heap_fetch() -
|
|
||||||
*
|
|
||||||
* Called from heap_fetch() if this is caused by a heap lookup
|
|
||||||
* for an actually done index scan.
|
|
||||||
* ----------
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
pgstat_count_heap_fetch(PgStat_Info *stats)
|
|
||||||
{
|
|
||||||
if (stats->tabentry == NULL)
|
|
||||||
return;
|
|
||||||
|
|
||||||
((PgStat_TableEntry *)(stats->tabentry))->t_tuples_fetched++;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* ----------
|
|
||||||
* pgstat_count_heap_insert() -
|
|
||||||
*
|
|
||||||
* Called from heap_insert().
|
|
||||||
* ----------
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
pgstat_count_heap_insert(PgStat_Info *stats)
|
|
||||||
{
|
|
||||||
if (stats->tabentry == NULL)
|
|
||||||
return;
|
|
||||||
|
|
||||||
((PgStat_TableEntry *)(stats->tabentry))->t_tuples_inserted++;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* ----------
|
|
||||||
* pgstat_count_heap_update() -
|
|
||||||
*
|
|
||||||
* Called from heap_update().
|
|
||||||
* ----------
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
pgstat_count_heap_update(PgStat_Info *stats)
|
|
||||||
{
|
|
||||||
if (stats->tabentry == NULL)
|
|
||||||
return;
|
|
||||||
|
|
||||||
((PgStat_TableEntry *)(stats->tabentry))->t_tuples_updated++;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* ----------
|
|
||||||
* pgstat_count_heap_delete() -
|
|
||||||
*
|
|
||||||
* Called from heap_delete().
|
|
||||||
* ----------
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
pgstat_count_heap_delete(PgStat_Info *stats)
|
|
||||||
{
|
|
||||||
if (stats->tabentry == NULL)
|
|
||||||
return;
|
|
||||||
|
|
||||||
((PgStat_TableEntry *)(stats->tabentry))->t_tuples_deleted++;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* ----------
|
|
||||||
* pgstat_reset_index_scan() -
|
|
||||||
*
|
|
||||||
* See pgstat_reset_heap_scan().
|
|
||||||
* ----------
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
pgstat_reset_index_scan(PgStat_Info *stats)
|
|
||||||
{
|
|
||||||
if (stats->tabentry == NULL)
|
|
||||||
return;
|
|
||||||
|
|
||||||
stats->index_scan_counted = FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* ----------
|
|
||||||
* pgstat_count_index_scan() -
|
|
||||||
*
|
|
||||||
* See pgstat_count_heap_scan().
|
|
||||||
* ----------
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
pgstat_count_index_scan(PgStat_Info *stats)
|
|
||||||
{
|
|
||||||
if (stats->tabentry == NULL)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (!stats->index_scan_counted)
|
|
||||||
{
|
|
||||||
((PgStat_TableEntry *)(stats->tabentry))->t_numscans++;
|
|
||||||
stats->index_scan_counted = TRUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* ----------
|
|
||||||
* pgstat_reset_index_getnext() -
|
|
||||||
*
|
|
||||||
* See pgstat_count_heap_getnext().
|
|
||||||
* ----------
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
pgstat_count_index_getnext(PgStat_Info *stats)
|
|
||||||
{
|
|
||||||
if (stats->tabentry == NULL)
|
|
||||||
return;
|
|
||||||
|
|
||||||
((PgStat_TableEntry *)(stats->tabentry))->t_tuples_returned++;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* ----------
|
|
||||||
* pgstat_count_buffer_read() -
|
|
||||||
*
|
|
||||||
* Called from bufmgr.c when a buffer is looked up in the shared buffer
|
|
||||||
* cache. The real number of buffers read from the disk (or at least the
|
|
||||||
* OSs or drives cache) is this minus buffer_hit_count below.
|
|
||||||
* ----------
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
pgstat_count_buffer_read(PgStat_Info *stats, Relation rel)
|
|
||||||
{
|
|
||||||
if (stats->tabentry == NULL)
|
|
||||||
{
|
|
||||||
if (stats->no_stats)
|
|
||||||
return;
|
|
||||||
pgstat_initstats(stats, rel);
|
|
||||||
if (stats->tabentry == NULL)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
((PgStat_TableEntry *)(stats->tabentry))->t_blocks_fetched++;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* ----------
|
|
||||||
* pgstat_count_buffer_hit() -
|
|
||||||
*
|
|
||||||
* Counts how many buffer per relation (or index) have been found
|
|
||||||
* in the buffer cache.
|
|
||||||
* ----------
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
pgstat_count_buffer_hit(PgStat_Info *stats, Relation rel)
|
|
||||||
{
|
|
||||||
if (stats->tabentry == NULL)
|
|
||||||
{
|
|
||||||
if (stats->no_stats)
|
|
||||||
return;
|
|
||||||
pgstat_initstats(stats, rel);
|
|
||||||
if (stats->tabentry == NULL)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
((PgStat_TableEntry *)(stats->tabentry))->t_blocks_hit++;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* ----------
|
/* ----------
|
||||||
* pgstat_count_xact_commit() -
|
* pgstat_count_xact_commit() -
|
||||||
*
|
*
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
*
|
*
|
||||||
* Copyright (c) 2001, PostgreSQL Global Development Group
|
* Copyright (c) 2001, PostgreSQL Global Development Group
|
||||||
*
|
*
|
||||||
* $Id: pgstat.h,v 1.1 2001/06/22 19:18:36 wieck Exp $
|
* $Id: pgstat.h,v 1.2 2001/06/29 16:29:37 wieck Exp $
|
||||||
* ----------
|
* ----------
|
||||||
*/
|
*/
|
||||||
#ifndef PGSTAT_H
|
#ifndef PGSTAT_H
|
||||||
@ -347,22 +347,65 @@ extern void pgstat_reset_counters(void);
|
|||||||
|
|
||||||
extern void pgstat_initstats(PgStat_Info *stats, Relation rel);
|
extern void pgstat_initstats(PgStat_Info *stats, Relation rel);
|
||||||
|
|
||||||
extern void pgstat_reset_heap_scan(PgStat_Info *stats);
|
|
||||||
extern void pgstat_count_heap_scan(PgStat_Info *stats);
|
|
||||||
extern void pgstat_count_heap_getnext(PgStat_Info *stats);
|
|
||||||
extern void pgstat_count_heap_fetch(PgStat_Info *stats);
|
|
||||||
extern void pgstat_count_heap_insert(PgStat_Info *stats);
|
|
||||||
extern void pgstat_count_heap_update(PgStat_Info *stats);
|
|
||||||
extern void pgstat_count_heap_delete(PgStat_Info *stats);
|
|
||||||
|
|
||||||
extern void pgstat_reset_index_scan(PgStat_Info *stats);
|
#define pgstat_reset_heap_scan(s) \
|
||||||
extern void pgstat_count_index_scan(PgStat_Info *stats);
|
if ((s)->tabentry != NULL) \
|
||||||
extern void pgstat_count_index_getnext(PgStat_Info *stats);
|
(s)->heap_scan_counted = FALSE
|
||||||
|
#define pgstat_count_heap_scan(s) \
|
||||||
|
if ((s)->tabentry != NULL && !(s)->heap_scan_counted) { \
|
||||||
|
((PgStat_TableEntry *)((s)->tabentry))->t_numscans++; \
|
||||||
|
(s)->heap_scan_counted = TRUE; \
|
||||||
|
}
|
||||||
|
#define pgstat_count_heap_getnext(s) \
|
||||||
|
if ((s)->tabentry != NULL) \
|
||||||
|
((PgStat_TableEntry *)((s)->tabentry))->t_tuples_returned++
|
||||||
|
#define pgstat_count_heap_fetch(s) \
|
||||||
|
if ((s)->tabentry != NULL) \
|
||||||
|
((PgStat_TableEntry *)((s)->tabentry))->t_tuples_fetched++
|
||||||
|
#define pgstat_count_heap_insert(s) \
|
||||||
|
if ((s)->tabentry != NULL) \
|
||||||
|
((PgStat_TableEntry *)((s)->tabentry))->t_tuples_inserted++
|
||||||
|
#define pgstat_count_heap_update(s) \
|
||||||
|
if ((s)->tabentry != NULL) \
|
||||||
|
((PgStat_TableEntry *)((s)->tabentry))->t_tuples_updated++
|
||||||
|
#define pgstat_count_heap_delete(s) \
|
||||||
|
if ((s)->tabentry != NULL) \
|
||||||
|
((PgStat_TableEntry *)((s)->tabentry))->t_tuples_deleted++
|
||||||
|
|
||||||
|
#define pgstat_reset_index_scan(s) \
|
||||||
|
if ((s)->tabentry != NULL) \
|
||||||
|
(s)->index_scan_counted = FALSE
|
||||||
|
#define pgstat_count_index_scan(s) \
|
||||||
|
if ((s)->tabentry != NULL && !(s)->index_scan_counted) { \
|
||||||
|
((PgStat_TableEntry *)((s)->tabentry))->t_numscans++; \
|
||||||
|
(s)->index_scan_counted = TRUE; \
|
||||||
|
}
|
||||||
|
#define pgstat_count_index_getnext(s) \
|
||||||
|
if ((s)->tabentry != NULL) \
|
||||||
|
((PgStat_TableEntry *)((s)->tabentry))->t_tuples_returned++
|
||||||
|
|
||||||
|
#define pgstat_count_buffer_read(s,r) \
|
||||||
|
if ((s)->tabentry != NULL) \
|
||||||
|
((PgStat_TableEntry *)((s)->tabentry))->t_blocks_fetched++; \
|
||||||
|
else { \
|
||||||
|
if (!(s)->no_stats) { \
|
||||||
|
pgstat_initstats((s), (r)); \
|
||||||
|
if ((s)->tabentry != NULL) \
|
||||||
|
((PgStat_TableEntry *)((s)->tabentry))->t_blocks_fetched++; \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
#define pgstat_count_buffer_hit(s,r) \
|
||||||
|
if ((s)->tabentry != NULL) \
|
||||||
|
((PgStat_TableEntry *)((s)->tabentry))->t_blocks_hit++; \
|
||||||
|
else { \
|
||||||
|
if (!(s)->no_stats) { \
|
||||||
|
pgstat_initstats((s), (r)); \
|
||||||
|
if ((s)->tabentry != NULL) \
|
||||||
|
((PgStat_TableEntry *)((s)->tabentry))->t_blocks_hit++; \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
extern void pgstat_count_buffer_read(PgStat_Info *stats,
|
|
||||||
Relation rel);
|
|
||||||
extern void pgstat_count_buffer_hit(PgStat_Info *stats,
|
|
||||||
Relation rel);
|
|
||||||
extern void pgstat_count_xact_commit(void);
|
extern void pgstat_count_xact_commit(void);
|
||||||
extern void pgstat_count_xact_rollback(void);
|
extern void pgstat_count_xact_rollback(void);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user