Permalink
Browse files

Add a runtime option to nuke hardware counters.

Eval.ProfileHWEnable (defaults to true) can be used to keep hhvm's
grubby mits off the perf counters. This is useful for some profiling work
we would like to do with Intel.
  • Loading branch information...
kma authored and joelpob committed Sep 26, 2012
1 parent 51d2aff commit 630e61a25f7258d41f56f5ae3875f9bf6b4c7c51
Showing with 17 additions and 7 deletions.
  1. +2 −0 src/runtime/base/runtime_option.cpp
  2. +1 −0 src/runtime/base/runtime_option.h
  3. +14 −7 src/util/hardware_counter.cpp
@@ -390,6 +390,7 @@ uint32 RuntimeOption::EvalJitWarmupRequests = kDefaultWarmupRequests;
bool RuntimeOption::EvalJitProfileRecord = false;
bool RuntimeOption::EvalJitNoGdb = true;
bool RuntimeOption::EvalProfileBC = false;
+bool RuntimeOption::EvalProfileHWEnable = true;
std::string RuntimeOption::EvalProfileHWEvents = "";
#define JIT_TRAMPOLINES_DEFAULT true
bool RuntimeOption::EvalJitTrampolines = JIT_TRAMPOLINES_DEFAULT;
@@ -1167,6 +1168,7 @@ void RuntimeOption::Load(Hdf &config, StringVec *overwrites /* = NULL */,
EvalAllowHhas = eval["AllowHhas"].getBool(false);
EvalJitNoGdb = eval["JitNoGdb"].getBool(true);
EvalProfileBC = eval["ProfileBC"].getBool(false);
+ EvalProfileHWEnable = eval["ProfileHWEnable"].getBool(true);
EvalProfileHWEvents = eval["ProfileHWEvents"].getString();
EvalJitTrampolines =
eval["JitTrampolines"].getBool(JIT_TRAMPOLINES_DEFAULT);
@@ -393,6 +393,7 @@ class RuntimeOption {
static bool EvalAllowHhas;
static bool EvalJitNoGdb;
static bool EvalProfileBC;
+ static bool EvalProfileHWEnable;
static std::string EvalProfileHWEvents;
static bool EvalJitTrampolines;
static string EvalJitProfilePath;
@@ -41,6 +41,14 @@ namespace HPHP { namespace Util {
IMPLEMENT_THREAD_LOCAL_NO_CHECK(HardwareCounter,
HardwareCounter::s_counter);
+static inline bool useCounters() {
+#ifdef VALGRIND
+ return false;
+#else
+ return RuntimeOption::EvalProfileHWEnable;
+#endif
+}
+
class HardwareCounterImpl {
public:
HardwareCounterImpl(int type, unsigned long config, StringData* desc = NULL)
@@ -56,37 +64,37 @@ class HardwareCounterImpl {
pe.read_format =
PERF_FORMAT_TOTAL_TIME_ENABLED|PERF_FORMAT_TOTAL_TIME_RUNNING;
-#ifndef VALGRIND
+ if (!useCounters()) return;
/*
* perf_event_open(struct perf_event_attr *hw_event_uptr, pid_t pid,
* int cpu, int group_fd, unsigned long flags)
*/
m_fd = syscall(__NR_perf_event_open, &pe, 0, -1, -1, 0);
if (m_fd < 0) {
Logger::Verbose("perf_event_open failed with: %s",
- Util::safe_strerror(errno).c_str());
+ Util::safe_strerror(errno).c_str());
m_err = -1;
return;
}
if (ioctl(m_fd, PERF_EVENT_IOC_ENABLE, 0) < 0) {
Logger::Warning("perf_event failed to enable: %s",
- Util::safe_strerror(errno).c_str());
+ Util::safe_strerror(errno).c_str());
close();
m_err = -1;
return;
}
reset();
-#endif
- }
+ }
~HardwareCounterImpl() {
close();
}
int64 read() {
+ if (!useCounters()) return 0;
+
int64 count = 0;
-#ifndef VALGRIND
if (m_fd > 0) {
int64 values[3];
int ret;
@@ -110,7 +118,6 @@ class HardwareCounterImpl {
}
}
}
-#endif
return count;
}

0 comments on commit 630e61a

Please sign in to comment.