summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchappedm@gmail.com <chappedm@gmail.com@6b5cf1ce-ec42-a296-1ba9-69fdba395a50>2012-10-28 18:28:21 +0000
committerchappedm@gmail.com <chappedm@gmail.com@6b5cf1ce-ec42-a296-1ba9-69fdba395a50>2012-10-28 18:28:21 +0000
commite5b095abdc2368111f53cedf376cd1505a2c7583 (patch)
tree73630ac250a06d9791a7ed4b58d12d8975424896
parent57c48e9b5ffdb0f177c07ea8420c4072e816e1a7 (diff)
downloadgperftools-e5b095abdc2368111f53cedf376cd1505a2c7583.tar.gz
issue-411: This commit adds additional logging to the cpu profiler to warn when the profiler is run and no CPUPROFILE environment setting can be found. It also adds a new environment variable PERFTOOLS_UNITTEST to allow certain modules to take action when running under the umbrella of a unit test.
git-svn-id: http://gperftools.googlecode.com/svn/trunk@162 6b5cf1ce-ec42-a296-1ba9-69fdba395a50
-rw-r--r--src/profiler.cc15
-rwxr-xr-xsrc/tests/profiler_unittest.sh18
2 files changed, 27 insertions, 6 deletions
diff --git a/src/profiler.cc b/src/profiler.cc
index dfb6aab..3272fa4 100644
--- a/src/profiler.cc
+++ b/src/profiler.cc
@@ -70,6 +70,12 @@ typedef int ucontext_t; // just to quiet the compiler, mostly
using std::string;
+DEFINE_bool(cpu_profile_unittest,
+ EnvToBool("PERFTOOLS_UNITTEST", true),
+ "Determines whether or not we are running under the \
+ control of a unit test. This allows us to include or \
+ exclude certain behaviours.");
+
// Collects up all profile data. This is a singleton, which is
// initialized by a constructor at startup.
class CpuProfiler {
@@ -139,12 +145,19 @@ CpuProfiler::CpuProfiler()
// is no need to limit the number of profilers.
char fname[PATH_MAX];
if (!GetUniquePathFromEnv("CPUPROFILE", fname)) {
+ if (!FLAGS_cpu_profile_unittest) {
+ RAW_LOG(WARNING, "CPU profiler linked but no valid CPUPROFILE environment variable found\n");
+ }
return;
}
// We don't enable profiling if setuid -- it's a security risk
#ifdef HAVE_GETEUID
- if (getuid() != geteuid())
+ if (getuid() != geteuid()) {
+ if (!FLAGS_cpu_profile_unittest) {
+ RAW_LOG(WARNING, "Cannot perform CPU profiling when running with setuid\n");
+ }
return;
+ }
#endif
if (!Start(fname, NULL)) {
diff --git a/src/tests/profiler_unittest.sh b/src/tests/profiler_unittest.sh
index 4668fa7..4085f2c 100755
--- a/src/tests/profiler_unittest.sh
+++ b/src/tests/profiler_unittest.sh
@@ -85,6 +85,14 @@ PROFILER4_REALNAME=`Realname "$PROFILER4"`
# It's meaningful to the profiler, so make sure we know its state
unset CPUPROFILE
+# Some output/logging in the profiler can cause issues when running the unit
+# tests. For example, logging a warning when the profiler is detected as being
+# present but no CPUPROFILE is specified in the environment. Especially when
+# we are checking for a silent run or specific timing constraints are being
+# checked. So set the env variable signifying that we are running in a unit
+# test environment.
+PERFTOOLS_UNITTEST=1
+
rm -rf "$TMPDIR"
mkdir "$TMPDIR" || exit 2
@@ -95,11 +103,11 @@ RegisterFailure() {
}
# Takes two filenames representing profiles, with their executable scripts,
-# and a multiplier, and verifies that the 'contentful' functions in
-# each profile take the same time (possibly scaled by the given
-# multiplier). It used to be "same" meant within 50%, after adding an
-# noise-reducing X units to each value. But even that would often
-# spuriously fail, so now it's "both non-zero". We're pretty forgiving.
+# and a multiplier, and verifies that the 'contentful' functions in each
+# profile take the same time (possibly scaled by the given multiplier). It
+# used to be "same" meant within 50%, after adding an noise-reducing X units
+# to each value. But even that would often spuriously fail, so now it's
+# "both non-zero". We're pretty forgiving.
VerifySimilar() {
prof1="$TMPDIR/$1"
exec1="$2"