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

Commitf755f2f

Browse files
committed
Fix tps calculation when -C supplied. Per Yoshiyuki Asaba.
Change Copyright owner from mine to PostgreSQL Global Development GroupFix minor message typo
1 parent2f2b58d commitf755f2f

File tree

1 file changed

+80
-31
lines changed

1 file changed

+80
-31
lines changed

‎contrib/pgbench/pgbench.c

Lines changed: 80 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,30 @@
11
/*
2-
*$PostgreSQL: pgsql/contrib/pgbench/pgbench.c,v 1.77 2008/03/12 02:18:33 tgl Exp $
2+
* pgbench.c
33
*
4-
*pgbench: a simple benchmark program for PostgreSQL
5-
* written by Tatsuo Ishii
4+
*A simple benchmark program for PostgreSQL
5+
*Originallywritten by Tatsuo Ishii and enhanced by many contributors.
66
*
7-
* Copyright (c) 2000-2007Tatsuo Ishii
7+
* $PostgreSQL: pgsql/contrib/pgbench/pgbench.c,v 1.78 2008/03/19 00:29:35 ishii Exp $
8+
* Copyright (c) 2000-2008, PostgreSQL Global Development Group
9+
* ALL RIGHTS RESERVED;
10+
*
11+
* Permission to use, copy, modify, and distribute this software and its
12+
* documentation for any purpose, without fee, and without a written agreement
13+
* is hereby granted, provided that the above copyright notice and this
14+
* paragraph and the following two paragraphs appear in all copies.
15+
*
16+
* IN NO EVENT SHALL THE AUTHOR OR DISTRIBUTORS BE LIABLE TO ANY PARTY FOR
17+
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING
18+
* LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
19+
* DOCUMENTATION, EVEN IF THE AUTHOR OR DISTRIBUTORS HAVE BEEN ADVISED OF THE
20+
* POSSIBILITY OF SUCH DAMAGE.
21+
*
22+
* THE AUTHOR AND DISTRIBUTORS SPECIFICALLY DISCLAIMS ANY WARRANTIES,
23+
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
24+
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
25+
* ON AN "AS IS" BASIS, AND THE AUTHOR AND DISTRIBUTORS HAS NO OBLIGATIONS TO
26+
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
827
*
9-
* Permission to use, copy, modify, and distribute this software and
10-
* its documentation for any purpose and without fee is hereby
11-
* granted, provided that the above copyright notice appear in all
12-
* copies and that both that copyright notice and this permission
13-
* notice appear in supporting documentation, and that the name of the
14-
* author not be used in advertising or publicity pertaining to
15-
* distribution of the software without specific, written prior
16-
* permission. The author makes no representations about the
17-
* suitability of this software for any purpose. It is provided "as
18-
* is" without express or implied warranty.
1928
*/
2029
#include"postgres_fe.h"
2130

@@ -184,6 +193,39 @@ static char *select_only = {
184193
"SELECT abalance FROM accounts WHERE aid = :aid;\n"
185194
};
186195

196+
/* Connection overhead time */
197+
staticstructtimevalconn_total_time= {0,0};
198+
199+
/* Calculate total time */
200+
staticvoid
201+
addTime(structtimeval*t1,structtimeval*t2,structtimeval*result)
202+
{
203+
intsec=t1->tv_sec+t2->tv_sec;
204+
intusec=t1->tv_usec+t2->tv_usec;
205+
if (usec >=1000000)
206+
{
207+
usec-=1000000;
208+
sec++;
209+
}
210+
result->tv_sec=sec;
211+
result->tv_usec=usec;
212+
}
213+
214+
/* Calculate time difference */
215+
staticvoid
216+
diffTime(structtimeval*t1,structtimeval*t2,structtimeval*result)
217+
{
218+
intsec=t1->tv_sec-t2->tv_sec;
219+
intusec=t1->tv_usec-t2->tv_usec;
220+
if (usec<0)
221+
{
222+
usec+=1000000;
223+
sec--;
224+
}
225+
result->tv_sec=sec;
226+
result->tv_usec=usec;
227+
}
228+
187229
staticvoid
188230
usage(void)
189231
{
@@ -564,6 +606,9 @@ doCustom(CState * state, int n, int debug)
564606

565607
if (st->con==NULL)
566608
{
609+
structtimevalt1,t2,t3;
610+
611+
gettimeofday(&t1,NULL);
567612
if ((st->con=doConnect())==NULL)
568613
{
569614
fprintf(stderr,"Client %d aborted in establishing connection.\n",
@@ -573,6 +618,9 @@ doCustom(CState * state, int n, int debug)
573618
st->con=NULL;
574619
return;
575620
}
621+
gettimeofday(&t2,NULL);
622+
diffTime(&t2,&t1,&t3);
623+
addTime(&conn_total_time,&t3,&conn_total_time);
576624
}
577625

578626
if (use_log&&st->state==0)
@@ -1193,8 +1241,7 @@ process_builtin(char *tb)
11931241
staticvoid
11941242
printResults(
11951243
intttype,CState*state,
1196-
structtimeval*tv1,structtimeval*tv2,
1197-
structtimeval*tv3)
1244+
structtimeval*start_time,structtimeval*end_time)
11981245
{
11991246
doublet1,
12001247
t2;
@@ -1205,10 +1252,11 @@ printResults(
12051252
for (i=0;i<nclients;i++)
12061253
normal_xacts+=state[i].cnt;
12071254

1208-
t1= (tv3->tv_sec-tv1->tv_sec)*1000000.0+ (tv3->tv_usec-tv1->tv_usec);
1255+
t1= (end_time->tv_sec-start_time->tv_sec)*1000000.0+ (end_time->tv_usec-start_time->tv_usec);
12091256
t1=normal_xacts*1000000.0 /t1;
12101257

1211-
t2= (tv3->tv_sec-tv2->tv_sec)*1000000.0+ (tv3->tv_usec-tv2->tv_usec);
1258+
t2= (end_time->tv_sec-start_time->tv_sec-conn_total_time.tv_sec)*1000000.0+
1259+
(end_time->tv_usec-start_time->tv_usec-conn_total_time.tv_usec);
12121260
t2=normal_xacts*1000000.0 /t2;
12131261

12141262
if (ttype==0)
@@ -1244,10 +1292,8 @@ main(int argc, char **argv)
12441292

12451293
CState*state;/* status of clients */
12461294

1247-
structtimevaltv1;/* start up time */
1248-
structtimevaltv2;/* after establishing all connections to the
1249-
* backend */
1250-
structtimevaltv3;/* end time */
1295+
structtimevalstart_time;/* start up time */
1296+
structtimevalend_time;/* end time */
12511297

12521298
inti;
12531299

@@ -1561,26 +1607,29 @@ main(int argc, char **argv)
15611607
PQfinish(con);
15621608

15631609
/* set random seed */
1564-
gettimeofday(&tv1,NULL);
1565-
srandom((unsignedint)tv1.tv_usec);
1610+
gettimeofday(&start_time,NULL);
1611+
srandom((unsignedint)start_time.tv_usec);
15661612

15671613
/* get start up time */
1568-
gettimeofday(&tv1,NULL);
1614+
gettimeofday(&start_time,NULL);
15691615

15701616
if (is_connect==0)
15711617
{
1618+
structtimevalt,now;
1619+
15721620
/* make connections to the database */
15731621
for (i=0;i<nclients;i++)
15741622
{
15751623
state[i].id=i;
15761624
if ((state[i].con=doConnect())==NULL)
15771625
exit(1);
15781626
}
1627+
/* time after connections set up */
1628+
gettimeofday(&now,NULL);
1629+
diffTime(&now,&start_time,&t);
1630+
addTime(&conn_total_time,&t,&conn_total_time);
15791631
}
15801632

1581-
/* time after connections set up */
1582-
gettimeofday(&tv2,NULL);
1583-
15841633
/* process bultin SQL scripts */
15851634
switch (ttype)
15861635
{
@@ -1627,8 +1676,8 @@ main(int argc, char **argv)
16271676
{/* all done ? */
16281677
disconnect_all(state);
16291678
/* get end time */
1630-
gettimeofday(&tv3,NULL);
1631-
printResults(ttype,state,&tv1,&tv2,&tv3);
1679+
gettimeofday(&end_time,NULL);
1680+
printResults(ttype,state,&start_time,&end_time);
16321681
if (LOGFILE)
16331682
fclose(LOGFILE);
16341683
exit(0);
@@ -1728,7 +1777,7 @@ main(int argc, char **argv)
17281777

17291778
if (state[i].ecnt>prev_ecnt&&commands[state[i].state]->type==META_COMMAND)
17301779
{
1731-
fprintf(stderr,"Client %d aborted in state %d. Execution meta-command failed.\n",i,state[i].state);
1780+
fprintf(stderr,"Client %d aborted in state %d. Executionofmeta-command failed.\n",i,state[i].state);
17321781
remains--;/* I've aborted */
17331782
PQfinish(state[i].con);
17341783
state[i].con=NULL;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp