~ubuntu-branches/ubuntu/jaunty/google-perftools/jaunty

« back to all changes in this revision

Viewing changes to src/tests/profiler_unittest.sh

  • Committer: Bazaar Package Importer
  • Author(s): Daigo Moriwaki
  • Date: 2008-06-15 23:41:36 UTC
  • mfrom: (3.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20080615234136-al5gawvdvt5vhdtz
Tags: 0.98-1
* New upstream release. (Closes: #425147)
* Compiled with GCC 4.3. (Closes: #454841)
* debian/watch: can now report upstream's version (Closes: #450294)
* Because of a file conflict between tau and libgoogle-perftools the
  binary pprof is renamed as google-pprof. (Closes: #404001)
  Great thanks to Michael Mende.
* debian/rules: autoconf files are now generated at the build time.
* Bumped up Standards-Version to 3.7.3, no changes are required.
* Split a new package, libtcmallc_minimal0. The upstream supports
  this module for wider platforms. So I leave its architecture to be
  `any'.
* libgoogle-perftools0's architecture is now i386. The upstream
  supports this module for x86 and x86_64. However, x86_64 requires
  libunwind's development head, which Debian does not have yet.
* Removed an unnecessary patch, debian/patches/02_profiler.cc_alpha.diff.

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
# This is because libtool sometimes turns the 'executable' into a
43
43
# shell script which runs an actual binary somewhere else.
44
44
 
45
 
if [ -z "$2" ]
46
 
then
47
 
    echo "USAGE: $0 <unittest dir> <pprof dir>"
48
 
    exit 1
 
45
# We expect BINDIR and PPROF_PATH to be set in the environment.
 
46
# If not, we set them to some reasonable values
 
47
BINDIR="${BINDIR:-.}"
 
48
PPROF_PATH="${PPROF_PATH:-$BINDIR/src/pprof}"
 
49
 
 
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"
 
53
  exit 1
49
54
fi
50
55
 
51
 
UNITTEST_DIR=$1
52
 
PPROF=$2/pprof
 
56
UNITTEST_DIR=${1:-$BINDIR}
 
57
PPROF=${2:-$PPROF_PATH}
53
58
 
54
59
PROFILER1=$UNITTEST_DIR/profiler1_unittest
55
60
PROFILER2=$UNITTEST_DIR/profiler2_unittest
66
71
 
67
72
num_failures=0
68
73
 
 
74
RegisterFailure() {
 
75
  num_failures=`expr $num_failures + 1`
 
76
}
 
77
 
69
78
# Takes two filenames representing profiles, with their executable scripts,
70
79
# and a multiplier, and verifies that the 'contentful' functions in
71
80
# each profile take the same time (possibly scaled by the given
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.
75
84
VerifySimilar() {
76
 
    prof1=$TMPDIR/$1
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;}'`
79
 
    prof2=$TMPDIR/$3
80
 
    exec2=`$4 2>&1 | awk '{print $2; exit;}'`
81
 
    mult=$5
 
85
  prof1=$TMPDIR/$1
 
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;}'`
 
88
  prof2=$TMPDIR/$3
 
89
  exec2=`$4 2>&1 | awk '{print $2; exit;}'`
 
90
  mult=$5
82
91
 
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` ]
91
 
    then
92
 
        echo
93
 
        echo ">>> profile on $exec1 vs $exec2 with multiplier $mult failed:"
94
 
        echo "Actual times (in profiling units) were '$mthread1' vs. '$mthread2'"
95
 
        echo
96
 
        num_failures=`expr $num_failures + 1`
97
 
    fi
 
100
  then
 
101
    echo
 
102
    echo ">>> profile on $exec1 vs $exec2 with multiplier $mult failed:"
 
103
    echo "Actual times (in profiling units) were '$mthread1' vs. '$mthread2'"
 
104
    echo
 
105
    RegisterFailure
 
106
  fi
98
107
}
99
108
 
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() {
109
 
    prof1=$TMPDIR/$1
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;}'`
112
 
    mult=$3
 
118
  prof1=$TMPDIR/$1
 
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;}'`
 
121
  mult=$3
113
122
 
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` ]
120
 
    then
121
 
        echo
122
 
        echo ">>> profile on $exec1 vs $exec2 with multiplier $mult failed:"
123
 
        echo "Actual times (in profiling units) were '$mthread1' vs. '$mthread2'"
124
 
        echo
125
 
        num_failures=`expr $num_failures + 1`
126
 
    fi
 
129
  then
 
130
    echo
 
131
    echo ">>> profile on $exec1 vs $exec2 with multiplier $mult failed:"
 
132
    echo "Actual times (in profiling units) were '$mthread1' vs. '$mthread2'"
 
133
    echo
 
134
    RegisterFailure
 
135
  fi
127
136
}
128
137
 
129
138
echo
134
143
echo
135
144
 
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
140
149
 
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
145
154
 
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
150
159
 
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
155
164
 
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
160
169
 
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
164
173
 
165
174
# More threads!
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
169
178
 
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
174
183
 
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"