Commit d3dfc664 authored by Vadim B. Mikheev's avatar Vadim B. Mikheev

PrintBufferUsage() changed to report about shared, local and direct

blocks transfferes.
parent 55f53543
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/buf_init.c,v 1.8 1997/03/28 07:04:52 scrappy Exp $ * $Header: /cvsroot/pgsql/src/backend/storage/buffer/buf_init.c,v 1.9 1997/04/18 02:53:15 vadim Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -120,9 +120,12 @@ long *CommitInfoNeedsSave; /* to write buffers where we have filled in */ ...@@ -120,9 +120,12 @@ long *CommitInfoNeedsSave; /* to write buffers where we have filled in */
SPINLOCK BufMgrLock; SPINLOCK BufMgrLock;
int ReadBufferCount; long int ReadBufferCount;
int BufferHitCount; long int ReadLocalBufferCount;
int BufferFlushCount; long int BufferHitCount;
long int LocalBufferHitCount;
long int BufferFlushCount;
long int LocalBufferFlushCount;
/* /*
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.11 1997/03/28 07:05:03 scrappy Exp $ * $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.12 1997/04/18 02:53:23 vadim Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -75,9 +75,12 @@ ...@@ -75,9 +75,12 @@
#include "catalog/catalog.h" #include "catalog/catalog.h"
extern SPINLOCK BufMgrLock; extern SPINLOCK BufMgrLock;
extern int ReadBufferCount; extern long int ReadBufferCount;
extern int BufferHitCount; extern long int ReadLocalBufferCount;
extern int BufferFlushCount; extern long int BufferHitCount;
extern long int LocalBufferHitCount;
extern long int BufferFlushCount;
extern long int LocalBufferFlushCount;
static int WriteMode = BUFFER_LATE_WRITE; /* Delayed write is default */ static int WriteMode = BUFFER_LATE_WRITE; /* Delayed write is default */
...@@ -217,7 +220,9 @@ ReadBufferWithBufferLock(Relation reln, ...@@ -217,7 +220,9 @@ ReadBufferWithBufferLock(Relation reln,
isLocalBuf = reln->rd_islocal; isLocalBuf = reln->rd_islocal;
if (isLocalBuf) { if (isLocalBuf) {
ReadLocalBufferCount++;
bufHdr = LocalBufferAlloc(reln, blockNum, &found); bufHdr = LocalBufferAlloc(reln, blockNum, &found);
if (found) LocalBufferHitCount++;
} else { } else {
ReadBufferCount++; ReadBufferCount++;
...@@ -473,7 +478,6 @@ BufferAlloc(Relation reln, ...@@ -473,7 +478,6 @@ BufferAlloc(Relation reln,
} }
else else
{ {
BufferFlushCount++;
/* /*
* BM_JUST_DIRTIED cleared by BufferReplace and shouldn't * BM_JUST_DIRTIED cleared by BufferReplace and shouldn't
* be setted by anyone. - vadim 01/17/97 * be setted by anyone. - vadim 01/17/97
...@@ -760,6 +764,7 @@ FlushBuffer(Buffer buffer, bool release) ...@@ -760,6 +764,7 @@ FlushBuffer(Buffer buffer, bool release)
bufHdr->tag.blockNum, bufHdr->sb_relname); bufHdr->tag.blockNum, bufHdr->sb_relname);
return (STATUS_ERROR); return (STATUS_ERROR);
} }
BufferFlushCount++;
SpinAcquire(BufMgrLock); SpinAcquire(BufMgrLock);
/* /*
...@@ -955,6 +960,7 @@ BufferSync() ...@@ -955,6 +960,7 @@ BufferSync()
elog(WARN, "BufferSync: cannot write %u for %s", elog(WARN, "BufferSync: cannot write %u for %s",
bufHdr->tag.blockNum, bufHdr->sb_relname); bufHdr->tag.blockNum, bufHdr->sb_relname);
} }
BufferFlushCount++;
/* /*
* If this buffer was marked by someone as DIRTY while * If this buffer was marked by someone as DIRTY while
* we were flushing it out we must not clear DIRTY flag * we were flushing it out we must not clear DIRTY flag
...@@ -1052,16 +1058,24 @@ void ...@@ -1052,16 +1058,24 @@ void
PrintBufferUsage(FILE *statfp) PrintBufferUsage(FILE *statfp)
{ {
float hitrate; float hitrate;
float localhitrate;
if (ReadBufferCount==0) if (ReadBufferCount==0)
hitrate = 0.0; hitrate = 0.0;
else else
hitrate = (float)BufferHitCount * 100.0/ReadBufferCount; hitrate = (float)BufferHitCount * 100.0/ReadBufferCount;
fprintf(statfp, "!\t%ld blocks read, %ld blocks written, buffer hit rate = %.2f%%\n", if (ReadLocalBufferCount==0)
ReadBufferCount - BufferHitCount + NDirectFileRead, localhitrate = 0.0;
BufferFlushCount + NDirectFileWrite, else
hitrate); localhitrate = (float)LocalBufferHitCount * 100.0/ReadLocalBufferCount;
fprintf(statfp, "!\tShared blocks: %10ld read, %10ld written, buffer hit rate = %.2f%%\n",
ReadBufferCount - BufferHitCount, BufferFlushCount, hitrate);
fprintf(statfp, "!\tLocal blocks: %10ld read, %10ld written, buffer hit rate = %.2f%%\n",
ReadLocalBufferCount - LocalBufferHitCount, LocalBufferFlushCount, localhitrate);
fprintf(statfp, "!\tDirect blocks: %10ld read, %10ld written\n",
NDirectFileRead, NDirectFileWrite);
} }
void void
...@@ -1070,6 +1084,9 @@ ResetBufferUsage() ...@@ -1070,6 +1084,9 @@ ResetBufferUsage()
BufferHitCount = 0; BufferHitCount = 0;
ReadBufferCount = 0; ReadBufferCount = 0;
BufferFlushCount = 0; BufferFlushCount = 0;
LocalBufferHitCount = 0;
ReadLocalBufferCount = 0;
LocalBufferFlushCount = 0;
NDirectFileRead = 0; NDirectFileRead = 0;
NDirectFileWrite = 0; NDirectFileWrite = 0;
} }
...@@ -1264,6 +1281,8 @@ BufferReplace(BufferDesc *bufHdr, bool bufferLockHeld) ...@@ -1264,6 +1281,8 @@ BufferReplace(BufferDesc *bufHdr, bool bufferLockHeld)
if (status == SM_FAIL) if (status == SM_FAIL)
return (FALSE); return (FALSE);
BufferFlushCount++;
return (TRUE); return (TRUE);
} }
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/localbuf.c,v 1.5 1997/01/16 08:13:14 vadim Exp $ * $Header: /cvsroot/pgsql/src/backend/storage/buffer/localbuf.c,v 1.6 1997/04/18 02:53:37 vadim Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -47,6 +47,8 @@ ...@@ -47,6 +47,8 @@
#include "executor/execdebug.h" /* for NDirectFileRead */ #include "executor/execdebug.h" /* for NDirectFileRead */
#include "catalog/catalog.h" #include "catalog/catalog.h"
extern long int LocalBufferFlushCount;
int NLocBuffer = 64; int NLocBuffer = 64;
BufferDesc *LocalBufferDescriptors = NULL; BufferDesc *LocalBufferDescriptors = NULL;
long *LocalRefCount = NULL; long *LocalRefCount = NULL;
...@@ -118,6 +120,7 @@ LocalBufferAlloc(Relation reln, BlockNumber blockNum, bool *foundPtr) ...@@ -118,6 +120,7 @@ LocalBufferAlloc(Relation reln, BlockNumber blockNum, bool *foundPtr)
/* flush this page */ /* flush this page */
smgrwrite(bufrel->rd_rel->relsmgr, bufrel, bufHdr->tag.blockNum, smgrwrite(bufrel->rd_rel->relsmgr, bufrel, bufHdr->tag.blockNum,
(char *) MAKE_PTR(bufHdr->data)); (char *) MAKE_PTR(bufHdr->data));
LocalBufferFlushCount++;
} }
/* /*
...@@ -192,6 +195,7 @@ FlushLocalBuffer(Buffer buffer, bool release) ...@@ -192,6 +195,7 @@ FlushLocalBuffer(Buffer buffer, bool release)
Assert(bufrel != NULL); Assert(bufrel != NULL);
smgrflush(bufrel->rd_rel->relsmgr, bufrel, bufHdr->tag.blockNum, smgrflush(bufrel->rd_rel->relsmgr, bufrel, bufHdr->tag.blockNum,
(char *) MAKE_PTR(bufHdr->data)); (char *) MAKE_PTR(bufHdr->data));
LocalBufferFlushCount++;
Assert(LocalRefCount[bufid] > 0); Assert(LocalRefCount[bufid] > 0);
if ( release ) if ( release )
...@@ -261,6 +265,7 @@ LocalBufferSync(void) ...@@ -261,6 +265,7 @@ LocalBufferSync(void)
smgrwrite(bufrel->rd_rel->relsmgr, bufrel, buf->tag.blockNum, smgrwrite(bufrel->rd_rel->relsmgr, bufrel, buf->tag.blockNum,
(char *) MAKE_PTR(buf->data)); (char *) MAKE_PTR(buf->data));
LocalBufferFlushCount++;
buf->tag.relId.relId = InvalidOid; buf->tag.relId.relId = InvalidOid;
buf->flags &= ~BM_DIRTY; buf->flags &= ~BM_DIRTY;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment