pgsql: pg_test_timing utility, to measure clock monotonicity and timing

Started by Robert Haasalmost 14 years ago14 messages
#1Robert Haas
rhaas@postgresql.org

pg_test_timing utility, to measure clock monotonicity and timing cost.

Ants Aasma, Greg Smith

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/cee523867db29c0bfc5de7ec638ce0a4ad9b3817

Modified Files
--------------
contrib/Makefile | 1 +
contrib/pg_test_timing/.gitignore | 1 +
contrib/pg_test_timing/Makefile | 18 ++
contrib/pg_test_timing/pg_test_timing.c | 162 +++++++++++++++++++
doc/src/sgml/config.sgml | 4 +-
doc/src/sgml/contrib.sgml | 1 +
doc/src/sgml/filelist.sgml | 1 +
doc/src/sgml/perform.sgml | 4 +-
doc/src/sgml/pgtesttiming.sgml | 261 +++++++++++++++++++++++++++++++
9 files changed, 451 insertions(+), 2 deletions(-)

#2Fujii Masao
masao.fujii@gmail.com
In reply to: Robert Haas (#1)
1 attachment(s)
Re: [COMMITTERS] pgsql: pg_test_timing utility, to measure clock monotonicity and timing

On Wed, Mar 28, 2012 at 5:17 AM, Robert Haas <rhaas@postgresql.org> wrote:

pg_test_timing utility, to measure clock monotonicity and timing cost.

When I compiled this, I got a compiler warning. Attached patch
silences the warning.

Also I found one trivial problem in the doc of pg_test_timing. The
patch fixes that.

Regards,

--
Fujii Masao
NIPPON TELEGRAPH AND TELEPHONE CORPORATION
NTT Open Source Software Center

Attachments:

pgtesttiming_silence_compiler_warning_v1.patchtext/x-diff; charset=US-ASCII; name=pgtesttiming_silence_compiler_warning_v1.patchDownload
*** a/contrib/pg_test_timing/pg_test_timing.c
--- b/contrib/pg_test_timing/pg_test_timing.c
***************
*** 155,161 **** test_timing(int32 duration)
          if (found || histogram[i])
          {
              found = 1;
!             printf("%9ld: %10ld %8.5f%%\n", 1l << i, histogram[i],
                  (double) histogram[i] * 100 / loop_count);
          }
      }
--- 155,161 ----
          if (found || histogram[i])
          {
              found = 1;
!             printf("%9ld: %10lld %8.5f%%\n", 1l << i, histogram[i],
                  (double) histogram[i] * 100 / loop_count);
          }
      }
*** a/doc/src/sgml/pgtesttiming.sgml
--- b/doc/src/sgml/pgtesttiming.sgml
***************
*** 28,35 **** pg_test_timing [options]
      <variablelist>
  
       <varlistentry>
!       <term><option>-d</option></term>
!       <term><option>--duration</option></term>
        <listitem>
         <para>
          Specifies the test duration, in seconds. Longer durations
--- 28,35 ----
      <variablelist>
  
       <varlistentry>
!       <term><option>-d <replaceable class="parameter">duration</replaceable></option></term>
!       <term><option>--duration=<replaceable class="parameter">duration</replaceable></option></term>
        <listitem>
         <para>
          Specifies the test duration, in seconds. Longer durations
#3Robert Haas
robertmhaas@gmail.com
In reply to: Fujii Masao (#2)
Re: [COMMITTERS] pgsql: pg_test_timing utility, to measure clock monotonicity and timing

On Tue, Mar 27, 2012 at 10:10 PM, Fujii Masao <masao.fujii@gmail.com> wrote:

On Wed, Mar 28, 2012 at 5:17 AM, Robert Haas <rhaas@postgresql.org> wrote:

pg_test_timing utility, to measure clock monotonicity and timing cost.

When I compiled this, I got a compiler warning. Attached patch
silences the warning.

Unfortunately, that *produces* a warning on my machine. Normally, I
think we handle this using INT64_FORMAT, but the fact that it's %10ld
here and not just %lld makes that awkward. I guess we maybe need to
insert some kludgy workaround here - write it into a separate buffer,
and then blank-pad it, or something like that.

Also I found one trivial problem in the doc of pg_test_timing. The
patch fixes that.

Thanks, committed.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

#4Marko Kreen
markokr@gmail.com
In reply to: Robert Haas (#3)
Re: Re: [COMMITTERS] pgsql: pg_test_timing utility, to measure clock monotonicity and timing

On Wed, Mar 28, 2012 at 08:19:37AM -0400, Robert Haas wrote:

On Tue, Mar 27, 2012 at 10:10 PM, Fujii Masao <masao.fujii@gmail.com> wrote:

On Wed, Mar 28, 2012 at 5:17 AM, Robert Haas <rhaas@postgresql.org> wrote:

pg_test_timing utility, to measure clock monotonicity and timing cost.

When I compiled this, I got a compiler warning. Attached patch
silences the warning.

Unfortunately, that *produces* a warning on my machine. Normally, I
think we handle this using INT64_FORMAT, but the fact that it's %10ld
here and not just %lld makes that awkward. I guess we maybe need to
insert some kludgy workaround here - write it into a separate buffer,
and then blank-pad it, or something like that.

How about: ".. %10" INT64_FORMAT " .. " ?

--
marko

#5Marko Kreen
markokr@gmail.com
In reply to: Marko Kreen (#4)
Re: Re: [COMMITTERS] pgsql: pg_test_timing utility, to measure clock monotonicity and timing

On Wed, Mar 28, 2012 at 03:46:26PM +0300, Marko Kreen wrote:

On Wed, Mar 28, 2012 at 08:19:37AM -0400, Robert Haas wrote:

On Tue, Mar 27, 2012 at 10:10 PM, Fujii Masao <masao.fujii@gmail.com> wrote:

On Wed, Mar 28, 2012 at 5:17 AM, Robert Haas <rhaas@postgresql.org> wrote:

pg_test_timing utility, to measure clock monotonicity and timing cost.

When I compiled this, I got a compiler warning. Attached patch
silences the warning.

Unfortunately, that *produces* a warning on my machine. Normally, I
think we handle this using INT64_FORMAT, but the fact that it's %10ld
here and not just %lld makes that awkward. I guess we maybe need to
insert some kludgy workaround here - write it into a separate buffer,
and then blank-pad it, or something like that.

How about: ".. %10" INT64_FORMAT " .. " ?

Well, it won't work because unlike <inttypes.h>, Postgres *_FORMAT
includes '%' in it.

I guess that why <inttypes.h> does not do it...

--
marko

#6Robert Haas
robertmhaas@gmail.com
In reply to: Marko Kreen (#5)
Re: Re: [COMMITTERS] pgsql: pg_test_timing utility, to measure clock monotonicity and timing

On Wed, Mar 28, 2012 at 8:51 AM, Marko Kreen <markokr@gmail.com> wrote:

How about:  ".. %10" INT64_FORMAT " .. " ?

Well, it won't work because unlike <inttypes.h>, Postgres *_FORMAT
includes '%' in it.

I guess that why <inttypes.h> does not do it...

Hmm, I guess we could change that, but it would create a hazard for
thirty-party code that wants to be cross-version, and for
back-patching. We could work around that by doing something more
complex, like creating additional symbols, but I'm thinking it ain't
worth it just for this.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

#7Marko Kreen
markokr@gmail.com
In reply to: Robert Haas (#6)
Re: Re: [COMMITTERS] pgsql: pg_test_timing utility, to measure clock monotonicity and timing

On Wed, Mar 28, 2012 at 08:57:42AM -0400, Robert Haas wrote:

On Wed, Mar 28, 2012 at 8:51 AM, Marko Kreen <markokr@gmail.com> wrote:

How about:  ".. %10" INT64_FORMAT " .. " ?

Well, it won't work because unlike <inttypes.h>, Postgres *_FORMAT
includes '%' in it.

I guess that why <inttypes.h> does not do it...

Hmm, I guess we could change that, but it would create a hazard for
thirty-party code that wants to be cross-version, and for
back-patching. We could work around that by doing something more
complex, like creating additional symbols, but I'm thinking it ain't
worth it just for this.

Changing existing definition is bad idea indeed.

And long-term path should be to move to standard int types,
so another custom definition seems counter-productive.
(OTOH, the 2 int64 _FORMATs are the only formats we maintain.)

In this case the simple approach would be to use 'long long':

".. %10lld ..", (long long)(..)

At least ecpg code uses it freely, and nobody has complained, so I guess
we don't have any platforms that do not have it.

--
marko

#8Fujii Masao
masao.fujii@gmail.com
In reply to: Robert Haas (#3)
1 attachment(s)
Re: [COMMITTERS] pgsql: pg_test_timing utility, to measure clock monotonicity and timing

On Wed, Mar 28, 2012 at 9:19 PM, Robert Haas <robertmhaas@gmail.com> wrote:

On Tue, Mar 27, 2012 at 10:10 PM, Fujii Masao <masao.fujii@gmail.com> wrote:

On Wed, Mar 28, 2012 at 5:17 AM, Robert Haas <rhaas@postgresql.org> wrote:

pg_test_timing utility, to measure clock monotonicity and timing cost.

When I compiled this, I got a compiler warning. Attached patch
silences the warning.

Unfortunately, that *produces* a warning on my machine.  Normally, I
think we handle this using INT64_FORMAT, but the fact that it's %10ld
here and not just %lld makes that awkward.  I guess we maybe need to
insert some kludgy workaround here - write it into a separate buffer,
and then blank-pad it, or something like that.

This seems a simplest workaround. How about attached patch?

Regards,

--
Fujii Masao
NIPPON TELEGRAPH AND TELEPHONE CORPORATION
NTT Open Source Software Center

Attachments:

pgtesttiming_int64format.patchapplication/octet-stream; name=pgtesttiming_int64format.patchDownload
*** a/contrib/pg_test_timing/pg_test_timing.c
--- b/contrib/pg_test_timing/pg_test_timing.c
***************
*** 107,112 **** test_timing(int32 duration)
--- 107,113 ----
  	instr_time start_time, end_time, temp;
  
  	static int64 histogram[32];
+ 	char	buf[100];
  
  	total_time = duration > 0 ? duration * 1000000 : 0;
  
***************
*** 155,161 **** test_timing(int32 duration)
          if (found || histogram[i])
          {
              found = 1;
!             printf("%9ld: %10ld %8.5f%%\n", 1l << i, histogram[i],
                  (double) histogram[i] * 100 / loop_count);
          }
      }
--- 156,163 ----
          if (found || histogram[i])
          {
              found = 1;
! 			snprintf(buf, sizeof(buf), INT64_FORMAT, histogram[i]);
!             printf("%9ld: %10s %8.5f%%\n", 1l << i, buf,
                  (double) histogram[i] * 100 / loop_count);
          }
      }
#9Tom Lane
tgl@sss.pgh.pa.us
In reply to: Fujii Masao (#8)
Re: Re: [COMMITTERS] pgsql: pg_test_timing utility, to measure clock monotonicity and timing

Fujii Masao <masao.fujii@gmail.com> writes:

This seems a simplest workaround. How about attached patch?

I think you need to tweak that to get the number to be right-justified
not left-justified.

regards, tom lane

#10Alvaro Herrera
alvherre@commandprompt.com
In reply to: Robert Haas (#1)
Re: pgsql: pg_test_timing utility, to measure clock monotonicity and timing

Excerpts from Robert Haas's message of mar mar 27 17:17:18 -0300 2012:

pg_test_timing utility, to measure clock monotonicity and timing cost.

Ants Aasma, Greg Smith

Did anyone notice that this broke several win32 buildfarm members? It
seems to be missing snprintf and other stuff. I guess it needs pgport.

--
Álvaro Herrera <alvherre@commandprompt.com>
The PostgreSQL Company - Command Prompt, Inc.
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

#11Robert Haas
robertmhaas@gmail.com
In reply to: Alvaro Herrera (#10)
Re: pgsql: pg_test_timing utility, to measure clock monotonicity and timing

On Wed, Mar 28, 2012 at 12:02 PM, Alvaro Herrera
<alvherre@commandprompt.com> wrote:

Excerpts from Robert Haas's message of mar mar 27 17:17:18 -0300 2012:

pg_test_timing utility, to measure clock monotonicity and timing cost.

Ants Aasma, Greg Smith

Did anyone notice that this broke several win32 buildfarm members?  It
seems to be missing snprintf and other stuff.  I guess it needs pgport.

I did not. I'll take a look.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

#12Fujii Masao
masao.fujii@gmail.com
In reply to: Tom Lane (#9)
Re: Re: [COMMITTERS] pgsql: pg_test_timing utility, to measure clock monotonicity and timing

On Thu, Mar 29, 2012 at 12:15 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

Fujii Masao <masao.fujii@gmail.com> writes:

This seems a simplest workaround. How about attached patch?

I think you need to tweak that to get the number to be right-justified
not left-justified.

Unless I'm missing something, I did that because the patch uses %10s
not %-10s. No?

Regards,

--
Fujii Masao
NIPPON TELEGRAPH AND TELEPHONE CORPORATION
NTT Open Source Software Center

#13Tom Lane
tgl@sss.pgh.pa.us
In reply to: Fujii Masao (#12)
Re: Re: [COMMITTERS] pgsql: pg_test_timing utility, to measure clock monotonicity and timing

Fujii Masao <masao.fujii@gmail.com> writes:

On Thu, Mar 29, 2012 at 12:15 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

I think you need to tweak that to get the number to be right-justified
not left-justified.

Unless I'm missing something, I did that because the patch uses %10s
not %-10s. No?

Oh, you're right, I was misremembering which direction that went.
Sorry for the noise.

regards, tom lane

#14Robert Haas
robertmhaas@gmail.com
In reply to: Fujii Masao (#8)
Re: [COMMITTERS] pgsql: pg_test_timing utility, to measure clock monotonicity and timing

On Wed, Mar 28, 2012 at 10:43 AM, Fujii Masao <masao.fujii@gmail.com> wrote:

On Wed, Mar 28, 2012 at 9:19 PM, Robert Haas <robertmhaas@gmail.com> wrote:

On Tue, Mar 27, 2012 at 10:10 PM, Fujii Masao <masao.fujii@gmail.com> wrote:

On Wed, Mar 28, 2012 at 5:17 AM, Robert Haas <rhaas@postgresql.org> wrote:

pg_test_timing utility, to measure clock monotonicity and timing cost.

When I compiled this, I got a compiler warning. Attached patch
silences the warning.

Unfortunately, that *produces* a warning on my machine.  Normally, I
think we handle this using INT64_FORMAT, but the fact that it's %10ld
here and not just %lld makes that awkward.  I guess we maybe need to
insert some kludgy workaround here - write it into a separate buffer,
and then blank-pad it, or something like that.

This seems a simplest workaround. How about attached patch?

Thanks, committed.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company