forked from tmm1/perftools.rb
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CPUPROFILE_REALTIME env var to use ITIMER_REAL instead of ITIMER_…
…PROF
- Loading branch information
Showing
4 changed files
with
81 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
diff --git a/src/profile-handler.cc b/src/profile-handler.cc | ||
index 370d012..619b980 100644 | ||
--- a/src/profile-handler.cc | ||
+++ b/src/profile-handler.cc | ||
@@ -133,6 +133,9 @@ class ProfileHandler { | ||
// SIGPROF interrupt frequency, read-only after construction. | ||
int32 frequency_; | ||
|
||
+ // use SIGALRM/ITIMER_REAL | ||
+ bool realtime_; | ||
+ | ||
// Counts the number of callbacks registered. | ||
int32 callback_count_ GUARDED_BY(control_lock_); | ||
|
||
@@ -241,6 +244,13 @@ ProfileHandler::ProfileHandler() | ||
callback_count_(0), | ||
timer_sharing_(TIMERS_UNTOUCHED) { | ||
SpinLockHolder cl(&control_lock_); | ||
+ | ||
+ const char* rt = getenv("CPUPROFILE_REALTIME"); | ||
+ if (rt != NULL) | ||
+ realtime_ = true; | ||
+ else | ||
+ realtime_ = false; | ||
+ | ||
// Get frequency of interrupts (if specified) | ||
char junk; | ||
const char* fr = getenv("CPUPROFILE_FREQUENCY"); | ||
@@ -396,18 +406,18 @@ void ProfileHandler::StartTimer() { | ||
timer.it_interval.tv_sec = 0; | ||
timer.it_interval.tv_usec = 1000000 / frequency_; | ||
timer.it_value = timer.it_interval; | ||
- setitimer(ITIMER_PROF, &timer, 0); | ||
+ setitimer(realtime_ ? ITIMER_REAL : ITIMER_PROF, &timer, 0); | ||
} | ||
|
||
void ProfileHandler::StopTimer() { | ||
struct itimerval timer; | ||
memset(&timer, 0, sizeof timer); | ||
- setitimer(ITIMER_PROF, &timer, 0); | ||
+ setitimer(realtime_ ? ITIMER_REAL : ITIMER_PROF, &timer, 0); | ||
} | ||
|
||
bool ProfileHandler::IsTimerRunning() { | ||
struct itimerval current_timer; | ||
- RAW_CHECK(0 == getitimer(ITIMER_PROF, ¤t_timer), "getitimer"); | ||
+ RAW_CHECK(0 == getitimer(realtime_ ? ITIMER_REAL : ITIMER_PROF, ¤t_timer), "getitimer"); | ||
return (current_timer.it_value.tv_sec != 0 || | ||
current_timer.it_value.tv_usec != 0); | ||
} | ||
@@ -417,7 +427,7 @@ void ProfileHandler::EnableHandler() { | ||
sa.sa_sigaction = SignalHandler; | ||
sa.sa_flags = SA_RESTART | SA_SIGINFO; | ||
sigemptyset(&sa.sa_mask); | ||
- RAW_CHECK(sigaction(SIGPROF, &sa, NULL) == 0, "sigprof (enable)"); | ||
+ RAW_CHECK(sigaction(realtime_ ? SIGALRM : SIGPROF, &sa, NULL) == 0, "sigprof (enable)"); | ||
} | ||
|
||
void ProfileHandler::DisableHandler() { | ||
@@ -425,7 +435,7 @@ void ProfileHandler::DisableHandler() { | ||
sa.sa_handler = SIG_IGN; | ||
sa.sa_flags = SA_RESTART; | ||
sigemptyset(&sa.sa_mask); | ||
- RAW_CHECK(sigaction(SIGPROF, &sa, NULL) == 0, "sigprof (disable)"); | ||
+ RAW_CHECK(sigaction(realtime_ ? SIGALRM : SIGPROF, &sa, NULL) == 0, "sigprof (disable)"); | ||
} | ||
|
||
void ProfileHandler::SignalHandler(int sig, siginfo_t* sinfo, void* ucontext) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters