From e574f2a029d707201aad307983fa74972aceab4a Mon Sep 17 00:00:00 2001
From: Tatsuo Ishii <ishii@postgresql.org>
Date: Fri, 6 Apr 2007 09:16:16 +0000
Subject: [PATCH] Enhance pgbench -l option to add timestamp. Patch contributed
 by Greg Smith. Along with Japanese doc updation by Tasuo Ishii.

> This patch changes the way pgbench outputs its latency log files so that
> every transaction gets a timestamp and notes which transaction type was
> executed.  It's a one-line change that just dumps some additional
> information that was already sitting in that area of code. I also made a
> couple of documentation corrections and clarifications on some of the more
> confusing features of pgbench.
>
> It's straightforward to parse log files in this format to analyze what
> happened during the test at a higher level than was possible with the
> original format.  You can find some rough sample code to convert this
> latency format into CVS files and then into graphs at
> http://www.westnet.com/~gsmith/content/postgresql/pgbench.htm which I'll
> be expanding on once I get all my little patches sent in here.
---
 contrib/pgbench/README.pgbench     | 29 ++++++++++++++++++++++++-----
 contrib/pgbench/README.pgbench_jis | 27 +++++++++++++++++++++++++--
 contrib/pgbench/pgbench.c          |  5 +++--
 3 files changed, 52 insertions(+), 9 deletions(-)

diff --git a/contrib/pgbench/README.pgbench b/contrib/pgbench/README.pgbench
index 7fc683cef03..ef040c094d7 100644
--- a/contrib/pgbench/README.pgbench
+++ b/contrib/pgbench/README.pgbench
@@ -1,4 +1,4 @@
-$PostgreSQL: pgsql/contrib/pgbench/README.pgbench,v 1.16 2007/04/06 08:49:44 ishii Exp $
+$PostgreSQL: pgsql/contrib/pgbench/README.pgbench,v 1.17 2007/04/06 09:16:15 ishii Exp $
 
 pgbench README
 
@@ -96,10 +96,14 @@ o options
 		default is 1.  NOTE: scaling factor should be at least
 		as large as the largest number of clients you intend
 		to test; else you'll mostly be measuring update contention.
+		Regular (not initializing) runs using one of the
+		built-in tests will detect scale based on the number of
+		branches in the database.  For custom (-f) runs it can
+		be manually specified with this parameter.
 
 	-D varname=value
-		Define a variable. It can be refereed to by a script
-		provided by using -f option. Multile -D options are allowed.
+		Define a variable. It can be refered to by a script
+		provided by using -f option. Multiple -D options are allowed.
 
 	-U login
 		Specify db user's login name if it is different from
@@ -141,9 +145,22 @@ o options
 		with the name "pgbench_log.xxx", where xxx is the PID
 		of the pgbench process. The format of the log is:
 
-			client_id transaction_no time
+			client_id transaction_no time file_no time-epoch time-us
 
-		where time is measured in microseconds.
+		where time is measured in microseconds, , the file_no is
+		which test file was used (useful when multiple were
+		specified with -f), and time-epoch/time-us are a
+		UNIX epoch format timestamp followed by an offset
+		in microseconds (suitable for creating a ISO 8601
+		timestamp with a fraction of a second) of when
+		the transaction completed.
+
+		Here are example outputs:
+
+		0 199 2241 0 1175850568 995598
+		0 200 2465 0 1175850568 998079
+		0 201 2513 0 1175850569 608
+		0 202 2038 0 1175850569 2663
 
 	-d
 		debug option.
@@ -165,6 +182,8 @@ o What is the "transaction" actually performed in pgbench?
 
   (7) end;
 
+If you specify -N, (4) and (5) aren't included in the transaction.
+
 o -f option
 
   This supports for reading transaction script from a specified
diff --git a/contrib/pgbench/README.pgbench_jis b/contrib/pgbench/README.pgbench_jis
index 5afa9324367..e06587a8791 100644
--- a/contrib/pgbench/README.pgbench_jis
+++ b/contrib/pgbench/README.pgbench_jis
@@ -1,4 +1,4 @@
-$PostgreSQL: pgsql/contrib/pgbench/README.pgbench_jis,v 1.17 2007/04/06 08:49:44 ishii Exp $
+$PostgreSQL: pgsql/contrib/pgbench/README.pgbench_jis,v 1.18 2007/04/06 09:16:16 ishii Exp $
 
 pgbench README
 
@@ -76,6 +76,13 @@ pgbench にはいろいろなオプションがあります.
 		デフォルトのスケーリングファクターは 1 です.
 		-f オプションで指定したファイルからスケーリングファク
 		ターを参照するには scale という変数名を使用します.
+		注意: スケーリングファクターは少なくとも -c で指定される同時接
+		続ユーザ数と同じかそれよりも大きくしてください.でないと,
+		pgbenchの結果はUPDATEの競合に大きく影響されてしまいます.
+		組込みのベンチマークパターンでは,brachesの数(=brachesテーブル
+		の行数)が自動的にスケーリングファクターに設定されます.
+		カスタムクエリ(-fオプション使用)では,スケーリングファクターは
+		自動設定されません.
 
 -D varname=value
 
@@ -130,10 +137,24 @@ pgbench にはいろいろなオプションがあります.
 		カレントディレクトリ以下のpgbench_log.xxxというファイ
 		ルです.ファイルのフォーマットは,
 		
-			クライアントID	トランザクション番号  時間
+			クライアントID	トランザクション番号  時間 ファイル番号 Unixタイム(秒) オフセット
 
 		となっています.時間はマイクロ秒単位です.
 
+		ファイル番号はテストに使われたファイルの番号です(-fオプション
+		を複数指定したときに有用です).
+
+		「Unixタイム(秒) オフセット」は,トランザクションが完了したと
+		きのUNIXエポックタイムとマイクロ秒単位のオフセットです(ISO
+		8601タイムスタンプと秒の中の端数).
+
+		ログの出力例を示します.
+
+		0 199 2241 0 1175850568 995598
+		0 200 2465 0 1175850568 998079
+		0 201 2513 0 1175850569 608
+		0 202 2038 0 1175850569 2663
+
 -d		デバッグオプション.様々な情報が表示されます.
 
 ■データベースの初期化
@@ -198,6 +219,8 @@ pgbench では,以下のシーケンスを全部完了して1トランザクションと数えて����┠�緕篁�����オプションを使用すると,(4)(5)は実行されません.
+
 ■入力ファイルのフォーマット
 
 -f オプションを指定してトランザクションに含まれる SQL コマンドの内容を
diff --git a/contrib/pgbench/pgbench.c b/contrib/pgbench/pgbench.c
index 369b7669f12..2ffd24b25b9 100644
--- a/contrib/pgbench/pgbench.c
+++ b/contrib/pgbench/pgbench.c
@@ -1,5 +1,5 @@
 /*
- * $PostgreSQL: pgsql/contrib/pgbench/pgbench.c,v 1.63 2007/04/06 08:49:44 ishii Exp $
+ * $PostgreSQL: pgsql/contrib/pgbench/pgbench.c,v 1.64 2007/04/06 09:16:16 ishii Exp $
  *
  * pgbench: a simple benchmark program for PostgreSQL
  * written by Tatsuo Ishii
@@ -469,7 +469,8 @@ top:
 			diff = (int) (now.tv_sec - st->txn_begin.tv_sec) * 1000000.0 +
 				(int) (now.tv_usec - st->txn_begin.tv_usec);
 
-			fprintf(LOGFILE, "%d %d %.0f\n", st->id, st->cnt, diff);
+			fprintf(LOGFILE, "%d %d %.0f %d %ld %ld\n",
+				st->id, st->cnt, diff, st->use_file, now.tv_sec,now.tv_usec);
 		}
 
 		if (commands[st->state]->type == SQL_COMMAND)
-- 
GitLab