Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
93 lines (85 sloc) 3.04 KB
commit 7a33a39f5b31e41f87a47bcadff818208fcc6c05
Author: Aman Gupta <aman@tmm1.net>
Date: Wed Mar 7 22:55:33 2012 -0800
perftools-objects
diff --git a/src/profile-handler.cc b/src/profile-handler.cc
index f9d8d8b..91f6f72 100644
--- a/src/profile-handler.cc
+++ b/src/profile-handler.cc
@@ -426,6 +426,8 @@ void ProfileHandler::StartTimer() {
if (!allowed_) {
return;
}
+ if (getenv("CPUPROFILE_OBJECTS") || getenv("CPUPROFILE_METHODS")) return;
+
struct itimerval timer;
timer.it_interval.tv_sec = 0;
timer.it_interval.tv_usec = 1000000 / frequency_;
@@ -437,6 +439,8 @@ void ProfileHandler::StopTimer() {
if (!allowed_) {
return;
}
+ if (getenv("CPUPROFILE_OBJECTS") || getenv("CPUPROFILE_METHODS")) return;
+
struct itimerval timer;
memset(&timer, 0, sizeof timer);
setitimer(timer_type_, &timer, 0);
@@ -446,6 +450,8 @@ bool ProfileHandler::IsTimerRunning() {
if (!allowed_) {
return false;
}
+ if (getenv("CPUPROFILE_OBJECTS") || getenv("CPUPROFILE_METHODS")) return false;
+
struct itimerval current_timer;
RAW_CHECK(0 == getitimer(timer_type_, &current_timer), "getitimer");
return (current_timer.it_value.tv_sec != 0 ||
@@ -456,6 +462,8 @@ void ProfileHandler::EnableHandler() {
if (!allowed_) {
return;
}
+ if (getenv("CPUPROFILE_OBJECTS") || getenv("CPUPROFILE_METHODS")) return;
+
struct sigaction sa;
sa.sa_sigaction = SignalHandler;
sa.sa_flags = SA_RESTART | SA_SIGINFO;
@@ -468,6 +476,8 @@ void ProfileHandler::DisableHandler() {
if (!allowed_) {
return;
}
+ if (getenv("CPUPROFILE_OBJECTS") || getenv("CPUPROFILE_METHODS")) return;
+
struct sigaction sa;
sa.sa_handler = SIG_IGN;
sa.sa_flags = SA_RESTART;
diff --git a/src/profiler.cc b/src/profiler.cc
index 6538299..8e92b91 100644
--- a/src/profiler.cc
+++ b/src/profiler.cc
@@ -102,6 +102,10 @@ class CpuProfiler {
static CpuProfiler instance_;
+ // Signal handler that records the interrupted pc in the profile data.
+ static void prof_handler(int sig, siginfo_t*, void* signal_ucontext,
+ void* cpu_profiler);
+
private:
// This lock implements the locking requirements described in the ProfileData
// documentation, specifically:
@@ -130,10 +134,6 @@ class CpuProfiler {
// Disables receiving SIGPROF interrupt.
void DisableHandler();
-
- // Signal handler that records the interrupted pc in the profile data.
- static void prof_handler(int sig, siginfo_t*, void* signal_ucontext,
- void* cpu_profiler);
};
// Profile data structure singleton: Constructor will check to see if
@@ -323,6 +323,10 @@ extern "C" PERFTOOLS_DLL_DECL void ProfilerFlush() {
extern "C" PERFTOOLS_DLL_DECL void ProfilerGcMark(void (*cb)(VALUE)) {
CpuProfiler::instance_.GcMark(cb);
}
+
+extern "C" PERFTOOLS_DLL_DECL void ProfilerRecord(int sig, siginfo_t* info, void* signal_ucontext) {
+ CpuProfiler::prof_handler(sig, info, signal_ucontext, (void*)&CpuProfiler::instance_);
+}
#endif
extern "C" PERFTOOLS_DLL_DECL int ProfilingIsEnabledForAllThreads() {