Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf6ee99a

Browse files
committed
Clean up usage-statistics display code (ShowUsage and friends). StatFp
is gone, usage messages now go through elog(DEBUG).
1 parent0c1669c commitf6ee99a

File tree

7 files changed

+67
-75
lines changed

7 files changed

+67
-75
lines changed

‎src/backend/access/nbtree/nbtree.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Portions Copyright (c) 1994, Regents of the University of California
1313
*
1414
* IDENTIFICATION
15-
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtree.c,v 1.84 2001/11/05 17:46:24 momjian Exp $
15+
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtree.c,v 1.85 2001/11/10 23:51:13 tgl Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -171,8 +171,7 @@ btbuild(PG_FUNCTION_ARGS)
171171
#ifdefBTREE_BUILD_STATS
172172
if (Show_btree_build_stats)
173173
{
174-
fprintf(stderr,"BTREE BUILD STATS\n");
175-
ShowUsage();
174+
ShowUsage("BTREE BUILD STATS");
176175
ResetUsage();
177176
}
178177
#endif/* BTREE_BUILD_STATS */

‎src/backend/access/nbtree/nbtsort.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
* Portions Copyright (c) 1994, Regents of the University of California
3636
*
3737
* IDENTIFICATION
38-
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtsort.c,v 1.62 2001/11/05 17:46:24 momjian Exp $
38+
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtsort.c,v 1.63 2001/11/10 23:51:13 tgl Exp $
3939
*
4040
*-------------------------------------------------------------------------
4141
*/
@@ -160,8 +160,7 @@ _bt_leafbuild(BTSpool *btspool, BTSpool *btspool2)
160160
#ifdefBTREE_BUILD_STATS
161161
if (Show_btree_build_stats)
162162
{
163-
fprintf(StatFp,"BTREE BUILD (Spool) STATISTICS\n");
164-
ShowUsage();
163+
ShowUsage("BTREE BUILD (Spool) STATISTICS");
165164
ResetUsage();
166165
}
167166
#endif/* BTREE_BUILD_STATS */

‎src/backend/executor/spi.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/executor/spi.c,v 1.61 2001/11/05 19:41:56 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/executor/spi.c,v 1.62 2001/11/10 23:51:14 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -18,6 +18,7 @@
1818
#include"catalog/heap.h"
1919
#include"commands/command.h"
2020
#include"executor/spi_priv.h"
21+
#include"tcop/tcopprot.h"
2122

2223

2324
uint32SPI_processed=0;
@@ -47,11 +48,6 @@ static MemoryContext _SPI_execmem(void);
4748
staticMemoryContext_SPI_procmem(void);
4849
staticbool_SPI_checktuples(void);
4950

50-
#ifdefSPI_EXECUTOR_STATS
51-
externintShowExecutorStats;
52-
externvoidResetUsage(void);
53-
externvoidShowUsage(void);
54-
#endif
5551

5652
/* =================== interface functions =================== */
5753

@@ -1180,10 +1176,7 @@ _SPI_pquery(QueryDesc *queryDesc, EState *state, int tcount)
11801176

11811177
#ifdefSPI_EXECUTOR_STATS
11821178
if (ShowExecutorStats)
1183-
{
1184-
fprintf(stderr,"! Executor Stats:\n");
1185-
ShowUsage();
1186-
}
1179+
ShowUsage("SPI EXECUTOR STATS");
11871180
#endif
11881181

11891182
if (dest==SPI)

‎src/backend/storage/buffer/bufmgr.c

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.119 2001/11/05 17:46:27 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.120 2001/11/10 23:51:14 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -46,6 +46,7 @@
4646
#include<math.h>
4747
#include<signal.h>
4848

49+
#include"lib/stringinfo.h"
4950
#include"miscadmin.h"
5051
#include"storage/buf_internals.h"
5152
#include"storage/bufmgr.h"
@@ -869,14 +870,21 @@ WaitIO(BufferDesc *buf)
869870

870871
longNDirectFileRead;/* some I/O's are direct file access.
871872
* bypass bufmgr */
872-
longNDirectFileWrite;/* e.g., I/O in psort and hashjoin.*/
873+
longNDirectFileWrite;/* e.g., I/O in psort and hashjoin.*/
873874

874-
void
875-
PrintBufferUsage(FILE*statfp)
875+
876+
/*
877+
* Return a palloc'd string containing buffer usage statistics.
878+
*/
879+
char*
880+
ShowBufferUsage(void)
876881
{
882+
StringInfoDatastr;
877883
floathitrate;
878884
floatlocalhitrate;
879885

886+
initStringInfo(&str);
887+
880888
if (ReadBufferCount==0)
881889
hitrate=0.0;
882890
else
@@ -887,16 +895,21 @@ PrintBufferUsage(FILE *statfp)
887895
else
888896
localhitrate= (float)LocalBufferHitCount*100.0 /ReadLocalBufferCount;
889897

890-
fprintf(statfp,"!\tShared blocks: %10ld read, %10ld written, buffer hit rate = %.2f%%\n",
898+
appendStringInfo(&str,
899+
"!\tShared blocks: %10ld read, %10ld written, buffer hit rate = %.2f%%\n",
891900
ReadBufferCount-BufferHitCount,BufferFlushCount,hitrate);
892-
fprintf(statfp,"!\tLocal blocks: %10ld read, %10ld written, buffer hit rate = %.2f%%\n",
901+
appendStringInfo(&str,
902+
"!\tLocal blocks: %10ld read, %10ld written, buffer hit rate = %.2f%%\n",
893903
ReadLocalBufferCount-LocalBufferHitCount,LocalBufferFlushCount,localhitrate);
894-
fprintf(statfp,"!\tDirect blocks: %10ld read, %10ld written\n",
904+
appendStringInfo(&str,
905+
"!\tDirect blocks: %10ld read, %10ld written\n",
895906
NDirectFileRead,NDirectFileWrite);
907+
908+
returnstr.data;
896909
}
897910

898911
void
899-
ResetBufferUsage()
912+
ResetBufferUsage(void)
900913
{
901914
BufferHitCount=0;
902915
ReadBufferCount=0;

‎src/backend/tcop/postgres.c

Lines changed: 33 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.241 2001/11/05 17:46:28 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.242 2001/11/10 23:51:14 tgl Exp $
1212
*
1313
* NOTES
1414
* this is the "main" module of the postgres backend and
@@ -86,7 +86,6 @@ boolWarn_restart_ready = false;
8686
boolInError= false;
8787

8888
staticboolEchoQuery= false;/* default don't echo */
89-
FILE*StatFp=NULL;
9089

9190
/* ----------------
9291
*people who want to use EOF should #define DONTUSENEWLINE in
@@ -378,10 +377,7 @@ pg_parse_query(char *query_string, Oid *typev, int nargs)
378377
raw_parsetree_list=parser(query_string,typev,nargs);
379378

380379
if (Show_parser_stats)
381-
{
382-
fprintf(StatFp,"PARSER STATISTICS\n");
383-
ShowUsage();
384-
}
380+
ShowUsage("PARSER STATISTICS");
385381

386382
returnraw_parsetree_list;
387383
}
@@ -413,8 +409,7 @@ pg_analyze_and_rewrite(Node *parsetree)
413409

414410
if (Show_parser_stats)
415411
{
416-
fprintf(StatFp,"PARSE ANALYSIS STATISTICS\n");
417-
ShowUsage();
412+
ShowUsage("PARSE ANALYSIS STATISTICS");
418413
ResetUsage();
419414
}
420415

@@ -457,10 +452,7 @@ pg_analyze_and_rewrite(Node *parsetree)
457452
querytree_list=new_list;
458453

459454
if (Show_parser_stats)
460-
{
461-
fprintf(StatFp,"REWRITER STATISTICS\n");
462-
ShowUsage();
463-
}
455+
ShowUsage("REWRITER STATISTICS");
464456

465457
#ifdefCOPY_PARSE_PLAN_TREES
466458

@@ -520,10 +512,7 @@ pg_plan_query(Query *querytree)
520512
plan=planner(querytree);
521513

522514
if (Show_planner_stats)
523-
{
524-
fprintf(StatFp,"PLANNER STATISTICS\n");
525-
ShowUsage();
526-
}
515+
ShowUsage("PLANNER STATISTICS");
527516

528517
#ifdefCOPY_PARSE_PLAN_TREES
529518
/* Optional debugging check: pass plan output through copyObject() */
@@ -794,10 +783,7 @@ pg_exec_query_string(char *query_string,/* string to execute */
794783
}
795784

796785
if (Show_executor_stats)
797-
{
798-
fprintf(StatFp,"EXECUTOR STATISTICS\n");
799-
ShowUsage();
800-
}
786+
ShowUsage("EXECUTOR STATISTICS");
801787
}
802788

803789
/*
@@ -1155,7 +1141,6 @@ PostgresMain(int argc, char *argv[], const char *username)
11551141
ResetAllOptions(true);
11561142
potential_DataDir=getenv("PGDATA");
11571143
}
1158-
StatFp=stderr;
11591144

11601145
/* Check for PGDATESTYLE environment variable */
11611146
set_default_datestyle();
@@ -1642,7 +1627,7 @@ PostgresMain(int argc, char *argv[], const char *username)
16421627
if (!IsUnderPostmaster)
16431628
{
16441629
puts("\nPOSTGRES backend interactive interface ");
1645-
puts("$Revision: 1.241 $ $Date: 2001/11/05 17:46:28 $\n");
1630+
puts("$Revision: 1.242 $ $Date: 2001/11/10 23:51:14 $\n");
16461631
}
16471632

16481633
/*
@@ -1867,10 +1852,7 @@ PostgresMain(int argc, char *argv[], const char *username)
18671852
QueryContext);
18681853

18691854
if (Show_query_stats)
1870-
{
1871-
fprintf(StatFp,"QUERY STATISTICS\n");
1872-
ShowUsage();
1873-
}
1855+
ShowUsage("QUERY STATISTICS");
18741856
}
18751857
break;
18761858

@@ -1933,18 +1915,20 @@ ResetUsage(void)
19331915
}
19341916

19351917
void
1936-
ShowUsage(void)
1918+
ShowUsage(constchar*title)
19371919
{
1920+
StringInfoDatastr;
19381921
structtimevaluser,
19391922
sys;
19401923
structtimevalelapse_t;
19411924
structtimezonetz;
19421925
structrusager;
1926+
char*bufusage;
19431927

19441928
getrusage(RUSAGE_SELF,&r);
19451929
gettimeofday(&elapse_t,&tz);
1946-
memmove((char*)&user, (char*)&r.ru_utime,sizeof(user));
1947-
memmove((char*)&sys, (char*)&r.ru_stime,sizeof(sys));
1930+
memcpy((char*)&user, (char*)&r.ru_utime,sizeof(user));
1931+
memcpy((char*)&sys, (char*)&r.ru_stime,sizeof(sys));
19481932
if (elapse_t.tv_usec<Save_t.tv_usec)
19491933
{
19501934
elapse_t.tv_sec--;
@@ -1961,12 +1945,6 @@ ShowUsage(void)
19611945
r.ru_stime.tv_usec+=1000000;
19621946
}
19631947

1964-
/*
1965-
* Set output destination if not otherwise set
1966-
*/
1967-
if (StatFp==NULL)
1968-
StatFp=stderr;
1969-
19701948
/*
19711949
* the only stats we don't show here are for memory usage -- i can't
19721950
* figure out how to interpret the relevant fields in the rusage
@@ -1975,53 +1953,63 @@ ShowUsage(void)
19751953
* resident set size, shared text size, and unshared data and stack
19761954
* sizes.
19771955
*/
1956+
initStringInfo(&str);
19781957

1979-
fprintf(StatFp,"! system usage stats:\n");
1980-
fprintf(StatFp,
1958+
appendStringInfo(&str,"! system usage stats:\n");
1959+
appendStringInfo(&str,
19811960
"!\t%ld.%06ld elapsed %ld.%06ld user %ld.%06ld system sec\n",
19821961
(longint)elapse_t.tv_sec-Save_t.tv_sec,
19831962
(longint)elapse_t.tv_usec-Save_t.tv_usec,
19841963
(longint)r.ru_utime.tv_sec-Save_r.ru_utime.tv_sec,
19851964
(longint)r.ru_utime.tv_usec-Save_r.ru_utime.tv_usec,
19861965
(longint)r.ru_stime.tv_sec-Save_r.ru_stime.tv_sec,
19871966
(longint)r.ru_stime.tv_usec-Save_r.ru_stime.tv_usec);
1988-
fprintf(StatFp,
1967+
appendStringInfo(&str,
19891968
"!\t[%ld.%06ld user %ld.%06ld sys total]\n",
19901969
(longint)user.tv_sec,
19911970
(longint)user.tv_usec,
19921971
(longint)sys.tv_sec,
19931972
(longint)sys.tv_usec);
19941973
/* BeOS has rusage but only has some fields, and not these... */
19951974
#if defined(HAVE_GETRUSAGE)
1996-
fprintf(StatFp,
1975+
appendStringInfo(&str,
19971976
"!\t%ld/%ld [%ld/%ld] filesystem blocks in/out\n",
19981977
r.ru_inblock-Save_r.ru_inblock,
19991978
/* they only drink coffee at dec */
20001979
r.ru_oublock-Save_r.ru_oublock,
20011980
r.ru_inblock,r.ru_oublock);
2002-
fprintf(StatFp,
1981+
appendStringInfo(&str,
20031982
"!\t%ld/%ld [%ld/%ld] page faults/reclaims, %ld [%ld] swaps\n",
20041983
r.ru_majflt-Save_r.ru_majflt,
20051984
r.ru_minflt-Save_r.ru_minflt,
20061985
r.ru_majflt,r.ru_minflt,
20071986
r.ru_nswap-Save_r.ru_nswap,
20081987
r.ru_nswap);
2009-
fprintf(StatFp,
1988+
appendStringInfo(&str,
20101989
"!\t%ld [%ld] signals rcvd, %ld/%ld [%ld/%ld] messages rcvd/sent\n",
20111990
r.ru_nsignals-Save_r.ru_nsignals,
20121991
r.ru_nsignals,
20131992
r.ru_msgrcv-Save_r.ru_msgrcv,
20141993
r.ru_msgsnd-Save_r.ru_msgsnd,
20151994
r.ru_msgrcv,r.ru_msgsnd);
2016-
fprintf(StatFp,
1995+
appendStringInfo(&str,
20171996
"!\t%ld/%ld [%ld/%ld] voluntary/involuntary context switches\n",
20181997
r.ru_nvcsw-Save_r.ru_nvcsw,
20191998
r.ru_nivcsw-Save_r.ru_nivcsw,
20201999
r.ru_nvcsw,r.ru_nivcsw);
20212000
#endif/* HAVE_GETRUSAGE */
2022-
fprintf(StatFp,"! postgres usage stats:\n");
2023-
PrintBufferUsage(StatFp);
2024-
/* DisplayTupleCount(StatFp); */
2001+
2002+
bufusage=ShowBufferUsage();
2003+
appendStringInfo(&str,"! postgres usage stats:\n%s",bufusage);
2004+
pfree(bufusage);
2005+
2006+
/* remove trailing newline */
2007+
if (str.data[str.len-1]=='\n')
2008+
str.data[--str.len]='\0';
2009+
2010+
elog(DEBUG,"%s\n%s",title,str.data);
2011+
2012+
pfree(str.data);
20252013
}
20262014

20272015
#ifdefNOT_USED

‎src/include/storage/bufmgr.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: bufmgr.h,v 1.56 2001/10/28 06:26:08 momjian Exp $
10+
* $Id: bufmgr.h,v 1.57 2001/11/10 23:51:14 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -164,7 +164,7 @@ extern intFlushBuffer(Buffer buffer, bool sync, bool release);
164164

165165
externvoidInitBufferPool(void);
166166
externvoidInitBufferPoolAccess(void);
167-
externvoidPrintBufferUsage(FILE*statfp);
167+
externchar*ShowBufferUsage(void);
168168
externvoidResetBufferUsage(void);
169169
externvoidResetBufferPool(boolisCommit);
170170
externboolBufferPoolCheckLeak(void);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp