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
This commit is contained in:
parent
57c48e9b5f
commit
e5b095abdc
|
@ -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)) {
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue