42
42
# This is because libtool sometimes turns the 'executable' into a
43
43
# shell script which runs an actual binary somewhere else.
47
echo "USAGE: $0 <unittest dir> <pprof dir>"
45
# We expect BINDIR and PPROF_PATH to be set in the environment.
46
# If not, we set them to some reasonable values
48
PPROF_PATH="${PPROF_PATH:-$BINDIR/src/pprof}"
50
if [ "x$1" = "x-h" -o "x$1" = "x--help" ]; then
51
echo "USAGE: $0 [unittest dir] [path to pprof]"
52
echo " By default, unittest_dir=$BINDIR, pprof_path=$PPROF_PATH"
56
UNITTEST_DIR=${1:-$BINDIR}
57
PPROF=${2:-$PPROF_PATH}
54
59
PROFILER1=$UNITTEST_DIR/profiler1_unittest
55
60
PROFILER2=$UNITTEST_DIR/profiler2_unittest
73
82
# noise-reducing X units to each value. But even that would often
74
83
# spuriously fail, so now it's "both non-zero". We're pretty forgiving.
77
# We need to run the script with no args to get the actual exe name
78
exec1=`$2 2>&1 | awk '{print $2; exit;}'`
80
exec2=`$4 2>&1 | awk '{print $2; exit;}'`
86
# We need to run the script with no args to get the actual exe name
87
exec1=`$2 2>&1 | awk '{print $2; exit;}'`
89
exec2=`$4 2>&1 | awk '{print $2; exit;}'`
83
mthread1=`$PPROF $exec1 $prof1 | grep test_main_thread | awk '{print $1}'`
84
mthread2=`$PPROF $exec2 $prof2 | grep test_main_thread | awk '{print $1}'`
85
mthread1_plus=`expr $mthread1 + 5`
86
mthread2_plus=`expr $mthread2 + 5`
87
if [ -z "$mthread1" ] || [ -z "$mthread2" ] || \
88
[ "$mthread1" -le 0 -o "$mthread2" -le 0 ]
92
mthread1=`$PPROF $exec1 $prof1 | grep test_main_thread | awk '{print $1}'`
93
mthread2=`$PPROF $exec2 $prof2 | grep test_main_thread | awk '{print $1}'`
94
mthread1_plus=`expr $mthread1 + 5`
95
mthread2_plus=`expr $mthread2 + 5`
96
if [ -z "$mthread1" ] || [ -z "$mthread2" ] || \
97
[ "$mthread1" -le 0 -o "$mthread2" -le 0 ]
89
98
# || [ `expr $mthread1_plus \* $mult` -gt `expr $mthread2_plus \* 2` -o \
90
99
# `expr $mthread1_plus \* $mult \* 2` -lt `expr $mthread2_plus` ]
93
echo ">>> profile on $exec1 vs $exec2 with multiplier $mult failed:"
94
echo "Actual times (in profiling units) were '$mthread1' vs. '$mthread2'"
96
num_failures=`expr $num_failures + 1`
102
echo ">>> profile on $exec1 vs $exec2 with multiplier $mult failed:"
103
echo "Actual times (in profiling units) were '$mthread1' vs. '$mthread2'"
100
109
# Takes a filenames representing a profile, with its executables,
106
115
# noise-reducing X units to each value. But even that would often
107
116
# spuriously fail, so now it's "both non-zero". We're pretty forgiving.
108
117
VerifyAcrossThreads() {
110
# We need to run the script with no args to get the actual exe name
111
exec1=`$2 2>&1 | awk '{print $2; exit;}'`
119
# We need to run the script with no args to get the actual exe name
120
exec1=`$2 2>&1 | awk '{print $2; exit;}'`
114
mthread=`$PPROF $exec1 $prof1 | grep test_main_thread | awk '{print $1}'`
115
othread=`$PPROF $exec2 $prof2 | grep test_other_thread | awk '{print $1}'`
116
if [ -z "$mthread" ] || [ -z "$othread" ] || \
117
[ "$mthread" -le 0 -o "$othread" -le 0 ]
123
mthread=`$PPROF $exec1 $prof1 | grep test_main_thread | awk '{print $1}'`
124
othread=`$PPROF $exec2 $prof2 | grep test_other_thread | awk '{print $1}'`
125
if [ -z "$mthread" ] || [ -z "$othread" ] || \
126
[ "$mthread" -le 0 -o "$othread" -le 0 ]
118
127
# || [ `expr $mthread \* $mult \* 3` -gt `expr $othread \* 10` -o \
119
128
# `expr $mthread \* $mult \* 10` -lt `expr $othread \* 3` ]
122
echo ">>> profile on $exec1 vs $exec2 with multiplier $mult failed:"
123
echo "Actual times (in profiling units) were '$mthread1' vs. '$mthread2'"
125
num_failures=`expr $num_failures + 1`
131
echo ">>> profile on $exec1 vs $exec2 with multiplier $mult failed:"
132
echo "Actual times (in profiling units) were '$mthread1' vs. '$mthread2'"
136
145
# profiler1 is a non-threaded version
137
$PROFILER1 50 1 $TMPDIR/p1
138
$PROFILER1 100 1 $TMPDIR/p2
146
$PROFILER1 50 1 $TMPDIR/p1 || RegisterFailure
147
$PROFILER1 100 1 $TMPDIR/p2 || RegisterFailure
139
148
VerifySimilar p1 $PROFILER1 p2 $PROFILER1 2
141
150
# Verify the same thing works if we statically link
142
$PROFILER2 50 1 $TMPDIR/p3
143
$PROFILER2 100 1 $TMPDIR/p4
151
$PROFILER2 50 1 $TMPDIR/p3 || RegisterFailure
152
$PROFILER2 100 1 $TMPDIR/p4 || RegisterFailure
144
153
VerifySimilar p3 $PROFILER2 p4 $PROFILER2 2
146
155
# Verify the same thing works if we specify via CPUPROFILE
147
CPUPROFILE=$TMPDIR/p5 $PROFILER2 50
148
CPUPROFILE=$TMPDIR/p6 $PROFILER2 100
156
CPUPROFILE=$TMPDIR/p5 $PROFILER2 50 || RegisterFailure
157
CPUPROFILE=$TMPDIR/p6 $PROFILER2 100 || RegisterFailure
149
158
VerifySimilar p5 $PROFILER2 p6 $PROFILER2 2
151
160
# When we compile with threads, things take a lot longer even when we only use 1
152
CPUPROFILE=$TMPDIR/p5b $PROFILER3 10
153
CPUPROFILE=$TMPDIR/p5c $PROFILER3 20
161
CPUPROFILE=$TMPDIR/p5b $PROFILER3 10 || RegisterFailure
162
CPUPROFILE=$TMPDIR/p5c $PROFILER3 20 || RegisterFailure
154
163
VerifySimilar p5b $PROFILER3 p5c $PROFILER3 2
156
165
# Now try what happens when we use threads
157
$PROFILER3 5 2 $TMPDIR/p7
158
$PROFILER3 10 2 $TMPDIR/p8
166
$PROFILER3 5 2 $TMPDIR/p7 || RegisterFailure
167
$PROFILER3 10 2 $TMPDIR/p8 || RegisterFailure
159
168
VerifySimilar p7 $PROFILER3 p8 $PROFILER3 2
161
$PROFILER4 5 2 $TMPDIR/p9
162
$PROFILER4 10 2 $TMPDIR/p10
170
$PROFILER4 5 2 $TMPDIR/p9 || RegisterFailure
171
$PROFILER4 10 2 $TMPDIR/p10 || RegisterFailure
163
172
VerifySimilar p9 $PROFILER4 p10 $PROFILER4 2
166
$PROFILER4 2 3 $TMPDIR/p9
167
$PROFILER4 4 3 $TMPDIR/p10
175
$PROFILER4 2 3 $TMPDIR/p9 || RegisterFailure
176
$PROFILER4 4 3 $TMPDIR/p10 || RegisterFailure
168
177
VerifySimilar p9 $PROFILER4 p10 $PROFILER4 2
170
179
# Compare how much time the main thread takes compared to the other threads
171
180
# Recall the main thread runs twice as long as the other threads, by design.
172
$PROFILER4 2 4 $TMPDIR/p11
181
$PROFILER4 2 4 $TMPDIR/p11 || RegisterFailure
173
182
VerifyAcrossThreads p11 $PROFILER4 2
175
184
# Make sure that when we have a process with a fork, the profiles don't
176
185
# clobber each other
177
CPUPROFILE=$TMPDIR/p6 $PROFILER1 1 -2
186
CPUPROFILE=$TMPDIR/p6 $PROFILER1 1 -2 || RegisterFailure
178
187
n=`ls $TMPDIR/p6* | wc -l`
179
188
if [ $n != 3 ]; then
180
189
echo "FORK test FAILED: expected 3 profiles (for main + 2 children), found $n"