|
4 | 4 | * A simple benchmark program for PostgreSQL |
5 | 5 | * Originally written by Tatsuo Ishii and enhanced by many contributors. |
6 | 6 | * |
7 | | - * $PostgreSQL: pgsql/contrib/pgbench/pgbench.c,v 1.89 2009/08/0315:18:14 ishii Exp $ |
| 7 | + * $PostgreSQL: pgsql/contrib/pgbench/pgbench.c,v 1.90 2009/08/03 18:30:55 tgl Exp $ |
8 | 8 | * Copyright (c) 2000-2009, PostgreSQL Global Development Group |
9 | 9 | * ALL RIGHTS RESERVED; |
10 | 10 | * |
|
71 | 71 | /* Use native win32 threads on Windows */ |
72 | 72 | typedefstructwin32_pthread*pthread_t; |
73 | 73 | typedefintpthread_attr_t; |
| 74 | + |
74 | 75 | staticintpthread_create(pthread_t*thread,pthread_attr_t*attr,void* (*start_routine)(void*),void*arg); |
75 | 76 | staticintpthread_join(pthread_tth,void**thread_return); |
76 | 77 |
|
77 | 78 | #elif defined(ENABLE_THREAD_SAFETY) |
78 | | -/* Use platform-dependent pthread */ |
| 79 | +/* Use platform-dependent pthreadcapability*/ |
79 | 80 | #include<pthread.h> |
80 | 81 |
|
81 | 82 | #else |
| 83 | +/* Use emulation with fork. Rename pthread identifiers to avoid conflicts */ |
82 | 84 |
|
83 | 85 | #include<sys/wait.h> |
84 | | -/* Use emulation with fork. Rename pthread idendifiers to avoid conflictions */ |
| 86 | + |
85 | 87 | #definepthread_tpg_pthread_t |
86 | 88 | #definepthread_attr_tpg_pthread_attr_t |
87 | 89 | #definepthread_createpg_pthread_create |
88 | 90 | #definepthread_joinpg_pthread_join |
| 91 | + |
89 | 92 | typedefstructfork_pthread*pthread_t; |
90 | 93 | typedefintpthread_attr_t; |
| 94 | + |
91 | 95 | staticintpthread_create(pthread_t*thread,pthread_attr_t*attr,void* (*start_routine)(void*),void*arg); |
92 | 96 | staticintpthread_join(pthread_tth,void**thread_return); |
93 | 97 |
|
@@ -136,7 +140,7 @@ FILE *LOGFILE = NULL; |
136 | 140 |
|
137 | 141 | booluse_log;/* log transaction latencies to a file */ |
138 | 142 |
|
139 | | -intis_connect;/* establish connectionfor each transaction */ |
| 143 | +intis_connect;/* establish connection for each transaction */ |
140 | 144 |
|
141 | 145 | char*pghost=""; |
142 | 146 | char*pgport=""; |
@@ -185,7 +189,7 @@ typedef struct |
185 | 189 | { |
186 | 190 | pthread_tthread;/* thread handle */ |
187 | 191 | CState*state;/* array of CState */ |
188 | | -intnstate;/* length of state */ |
| 192 | +intnstate;/* length of state[] */ |
189 | 193 | instr_timestart_time;/* thread start time */ |
190 | 194 | }TState; |
191 | 195 |
|
@@ -647,20 +651,25 @@ doCustom(CState *st, instr_time *conn_time) |
647 | 651 | */ |
648 | 652 | if (use_log&&commands[st->state+1]==NULL) |
649 | 653 | { |
| 654 | +instr_timenow; |
650 | 655 | instr_timediff; |
651 | | -doublesec; |
652 | | -doublemsec; |
653 | 656 | doubleusec; |
654 | 657 |
|
655 | | -INSTR_TIME_SET_CURRENT(diff); |
| 658 | +INSTR_TIME_SET_CURRENT(now); |
| 659 | +diff=now; |
656 | 660 | INSTR_TIME_SUBTRACT(diff,st->txn_begin); |
657 | | -sec=INSTR_TIME_GET_DOUBLE(diff); |
658 | | -msec=INSTR_TIME_GET_MILLISEC(diff); |
659 | 661 | usec= (double)INSTR_TIME_GET_MICROSEC(diff); |
660 | 662 |
|
661 | | -fprintf(LOGFILE,"%d %d %.0f %d %.0f %.0f\n", |
| 663 | +#ifndefWIN32 |
| 664 | +/* This is more than we really ought to know about instr_time */ |
| 665 | +fprintf(LOGFILE,"%d %d %.0f %d %ld %ld\n", |
662 | 666 | st->id,st->cnt,usec,st->use_file, |
663 | | -sec,usec-sec*1000.0); |
| 667 | +(long)now.tv_sec, (long)now.tv_usec); |
| 668 | +#else |
| 669 | +/* On Windows, instr_time doesn't provide a timestamp anyway */ |
| 670 | +fprintf(LOGFILE,"%d %d %.0f %d 0 0\n", |
| 671 | +st->id,st->cnt,usec,st->use_file); |
| 672 | +#endif |
664 | 673 | } |
665 | 674 |
|
666 | 675 | if (commands[st->state]->type==SQL_COMMAND) |
@@ -1269,15 +1278,17 @@ process_commands(char *buf) |
1269 | 1278 | } |
1270 | 1279 |
|
1271 | 1280 | /* |
1272 | | - * Split argument into number and unitfor"sleep 1ms"or so. |
| 1281 | + * Split argument into number and unitto allow"sleep 1ms"etc. |
1273 | 1282 | * We don't have to terminate the number argument with null |
1274 | | - * because it will parsed with atoi,that ignores trailing |
| 1283 | + * because it willbeparsed with atoi,which ignores trailing |
1275 | 1284 | * non-digit characters. |
1276 | 1285 | */ |
1277 | 1286 | if (my_commands->argv[1][0]!=':') |
1278 | 1287 | { |
1279 | 1288 | char*c=my_commands->argv[1]; |
1280 | | -while (isdigit(*c)) {c++; } |
| 1289 | + |
| 1290 | +while (isdigit((unsignedchar)*c)) |
| 1291 | +c++; |
1281 | 1292 | if (*c) |
1282 | 1293 | { |
1283 | 1294 | my_commands->argv[2]=c; |
@@ -1772,7 +1783,7 @@ main(int argc, char **argv) |
1772 | 1783 |
|
1773 | 1784 | if (nclients %nthreads!=0) |
1774 | 1785 | { |
1775 | | -fprintf(stderr,"number of clients (%d) must be a multiple number of threads (%d)\n",nclients,nthreads); |
| 1786 | +fprintf(stderr,"number of clients (%d) must be a multipleofnumber of threads (%d)\n",nclients,nthreads); |
1776 | 1787 | exit(1); |
1777 | 1788 | } |
1778 | 1789 |
|
|