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

Commit0f3351a

Browse files
committed
Adjust pg_test_timing to show shortest test durations first, place
percentage column before count column. Docs updated.
1 parent65b2ee2 commit0f3351a

File tree

2 files changed

+59
-47
lines changed

2 files changed

+59
-47
lines changed

‎contrib/pg_test_timing/pg_test_timing.c

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,24 @@ static const char *progname;
1414
staticint32test_duration=3;
1515

1616
staticvoidhandle_args(intargc,char*argv[]);
17-
staticvoidtest_timing(int32);
17+
staticuint64test_timing(int32);
18+
staticvoidoutput(uint64loop_count);
19+
20+
/* record duration in powers of 2 microseconds */
21+
int64histogram[32];
1822

1923
int
2024
main(intargc,char*argv[])
2125
{
26+
uint64loop_count;
27+
2228
progname=get_progname(argv[0]);
2329

2430
handle_args(argc,argv);
2531

26-
test_timing(test_duration);
32+
loop_count=test_timing(test_duration);
33+
34+
output(loop_count);
2735

2836
return0;
2937
}
@@ -95,25 +103,14 @@ handle_args(int argc, char *argv[])
95103
}
96104
}
97105

98-
staticvoid
106+
staticuint64
99107
test_timing(int32duration)
100108
{
101109
uint64total_time;
102110
int64time_elapsed=0;
103111
uint64loop_count=0;
104-
uint64prev,
105-
cur;
106-
int32diff,
107-
i,
108-
bits,
109-
found;
110-
111-
instr_timestart_time,
112-
end_time,
113-
temp;
114-
115-
staticint64histogram[32];
116-
charbuf[100];
112+
uint64prev,cur;
113+
instr_timestart_time,end_time,temp;
117114

118115
total_time=duration>0 ?duration*1000000 :0;
119116

@@ -122,24 +119,29 @@ test_timing(int32 duration)
122119

123120
while (time_elapsed<total_time)
124121
{
122+
int32diff,bits=0;
123+
125124
prev=cur;
126125
INSTR_TIME_SET_CURRENT(temp);
127126
cur=INSTR_TIME_GET_MICROSEC(temp);
128127
diff=cur-prev;
129128

129+
/* Did time go backwards? */
130130
if (diff<0)
131131
{
132132
printf("Detected clock going backwards in time.\n");
133133
printf("Time warp: %d microseconds\n",diff);
134134
exit(1);
135135
}
136136

137-
bits=0;
137+
/* What is the highest bit in the time diff? */
138138
while (diff)
139139
{
140140
diff >>=1;
141141
bits++;
142142
}
143+
144+
/* Update appropriate duration bucket */
143145
histogram[bits]++;
144146

145147
loop_count++;
@@ -153,19 +155,29 @@ test_timing(int32 duration)
153155

154156
printf("Per loop time including overhead: %0.2f nsec\n",
155157
INSTR_TIME_GET_DOUBLE(end_time)*1e9 /loop_count);
158+
159+
returnloop_count;
160+
}
161+
162+
staticvoid
163+
output(uint64loop_count)
164+
{
165+
int64max_bit=31,i;
166+
167+
/* find highest bit value */
168+
while (max_bit>0&&histogram[max_bit]==0)
169+
max_bit--;
170+
156171
printf("Histogram of timing durations:\n");
157-
printf("%9s:%10s %9s\n","< usec","count","percent");
172+
printf("%6s%10s %10s\n","< usec","% of total","count");
158173

159-
found=0;
160-
for (i=31;i >=0;i--)
174+
for (i=0;i <=max_bit;i++)
161175
{
162-
if (found||histogram[i])
163-
{
164-
found=1;
165-
/* lame hack to work around INT64_FORMAT deficiencies */
166-
snprintf(buf,sizeof(buf),INT64_FORMAT,histogram[i]);
167-
printf("%9ld: %10s %8.5f%%\n",1l <<i,buf,
168-
(double)histogram[i]*100 /loop_count);
169-
}
176+
charbuf[100];
177+
178+
/* lame hack to work around INT64_FORMAT deficiencies */
179+
snprintf(buf,sizeof(buf),INT64_FORMAT,histogram[i]);
180+
printf("%6ld %9.5f %10s\n",1l <<i,
181+
(double)histogram[i]*100 /loop_count,buf);
170182
}
171183
}

‎doc/src/sgml/pgtesttiming.sgml

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,12 @@
9898
Testing timing overhead for 3 seconds.
9999
Per loop time including overhead: 35.96 nsec
100100
Histogram of timing durations:
101-
< usec: countpercent
102-
16: 2 0.00000%
103-
8: 13 0.00002%
104-
4: 1260.00015%
105-
2: 2999652 3.59518%
106-
1: 80435604 96.40465%
101+
< usec% of total count
102+
196.4046580435604
103+
23.595182999652
104+
40.00015126
105+
80.00002 13
106+
16 0.00000 2
107107
</screen>
108108
</para>
109109

@@ -159,12 +159,12 @@ tsc hpet acpi_pm
159159
# pg_test_timing
160160
Per loop time including overhead: 722.92 nsec
161161
Histogram of timing durations:
162-
< usec: countpercent
163-
16: 3 0.00007%
164-
8: 563 0.01357%
165-
4: 32410.07810%
166-
2: 2990371 72.05956%
167-
1: 1155682 27.84870%
162+
< usec% of total count
163+
127.848701155682
164+
2 72.059562990371
165+
40.078103241
166+
80.01357 563
167+
16 0.00007 3
168168
</screen>
169169
</para>
170170

@@ -206,13 +206,13 @@ $ pg_test_timing
206206
Testing timing overhead for 3 seconds.
207207
Per timing duration including loop overhead: 97.75 ns
208208
Histogram of timing durations:
209-
< usec: countpercent
210-
32: 1 0.00000%
211-
16: 1 0.00000%
212-
8:22 0.00007%
213-
4:3010 0.00981%
214-
2: 2993204 9.75277%
215-
1: 27694571 90.23734%
209+
< usec% of total count
210+
190.2373427694571
211+
29.752772993204
212+
40.00981 3010
213+
80.00007 22
214+
16 0.00000 1
215+
32 0.00000 1
216216
</screen></para>
217217

218218
</refsect2>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp