Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 0f3351a

Browse files
committed
Adjust pg_test_timing to show shortest test durations first, place
percentage column before count column. Docs updated.
1 parent 65b2ee2 commit 0f3351a

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
static int32 test_duration = 3;
1515

1616
static void handle_args(int argc, char *argv[]);
17-
static void test_timing(int32);
17+
static uint64 test_timing(int32);
18+
static void output(uint64 loop_count);
19+
20+
/* record duration in powers of 2 microseconds */
21+
int64 histogram[32];
1822

1923
int
2024
main(int argc, char *argv[])
2125
{
26+
uint64 loop_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
return 0;
2937
}
@@ -95,25 +103,14 @@ handle_args(int argc, char *argv[])
95103
}
96104
}
97105

98-
static void
106+
static uint64
99107
test_timing(int32 duration)
100108
{
101109
uint64 total_time;
102110
int64 time_elapsed = 0;
103111
uint64 loop_count = 0;
104-
uint64 prev,
105-
cur;
106-
int32 diff,
107-
i,
108-
bits,
109-
found;
110-
111-
instr_time start_time,
112-
end_time,
113-
temp;
114-
115-
static int64 histogram[32];
116-
char buf[100];
112+
uint64 prev, cur;
113+
instr_time start_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+
int32 diff, 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+
return loop_count;
160+
}
161+
162+
static void
163+
output(uint64 loop_count)
164+
{
165+
int64 max_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+
char buf[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: count percent
102-
16: 2 0.00000%
103-
8: 13 0.00002%
104-
4: 126 0.00015%
105-
2: 2999652 3.59518%
106-
1: 80435604 96.40465%
101+
< usec % of total count
102+
1 96.40465 80435604
103+
2 3.59518 2999652
104+
4 0.00015 126
105+
8 0.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: count percent
163-
16: 3 0.00007%
164-
8: 563 0.01357%
165-
4: 3241 0.07810%
166-
2: 2990371 72.05956%
167-
1: 1155682 27.84870%
162+
< usec % of total count
163+
1 27.84870 1155682
164+
2 72.05956 2990371
165+
4 0.07810 3241
166+
8 0.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: count percent
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+
1 90.23734 27694571
211+
2 9.75277 2993204
212+
4 0.00981 3010
213+
8 0.00007 22
214+
16 0.00000 1
215+
32 0.00000 1
216216
</screen></para>
217217

218218
</refsect2>

0 commit comments

Comments
 (0)