perftools.rb 0.3.6 → 0.3.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +8 -0
- data/ext/extconf.rb +2 -1
- data/ext/perftools.c +1 -1
- data/patches/perftools-realtime.patch +68 -0
- data/patches/perftools.patch +0 -6
- data/perftools.rb.gemspec +3 -2
- metadata +3 -2
data/README
CHANGED
|
@@ -21,6 +21,14 @@ google-perftools for ruby code
|
|
|
21
21
|
|
|
22
22
|
$ CPUPROFILE=/tmp/my_app_profile RUBYOPT="-r`gem which perftools | tail -1`" ruby my_app.rb
|
|
23
23
|
|
|
24
|
+
Change the sampling interval (defaults to 100 times a second, valid range is 1-4000):
|
|
25
|
+
|
|
26
|
+
$ CPUPROFILE_FREQUENCY=500 ruby my_app.rb
|
|
27
|
+
|
|
28
|
+
Use walltime instead of cputime profiling:
|
|
29
|
+
|
|
30
|
+
$ CPUPROFILE_REALTIME=1 ruby my_app.rb
|
|
31
|
+
|
|
24
32
|
|
|
25
33
|
=== Reporting
|
|
26
34
|
|
data/ext/extconf.rb
CHANGED
|
@@ -45,7 +45,8 @@ Dir.chdir('src') do
|
|
|
45
45
|
['perftools-gc', true],
|
|
46
46
|
['perftools-osx', RUBY_PLATFORM =~ /darwin/],
|
|
47
47
|
['perftools-osx-106', RUBY_PLATFORM =~ /darwin10/],
|
|
48
|
-
['perftools-debug', true]
|
|
48
|
+
['perftools-debug', true],
|
|
49
|
+
['perftools-realtime', true]
|
|
49
50
|
].each do |patch, apply|
|
|
50
51
|
if apply
|
|
51
52
|
sys("patch -p1 < ../../../patches/#{patch}.patch")
|
data/ext/perftools.c
CHANGED
|
@@ -54,7 +54,7 @@ static VALUE I__send__;
|
|
|
54
54
|
*/
|
|
55
55
|
|
|
56
56
|
for (; frame && (n = frame->node); frame = frame->prev) {
|
|
57
|
-
if (frame->prev && frame->prev->last_func) {
|
|
57
|
+
if (frame->prev > 0xff && frame->prev->last_func) {
|
|
58
58
|
if (frame->prev->node == n) {
|
|
59
59
|
if (frame->prev->last_func == frame->last_func) continue;
|
|
60
60
|
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
diff --git a/src/profile-handler.cc b/src/profile-handler.cc
|
|
2
|
+
index 370d012..619b980 100644
|
|
3
|
+
--- a/src/profile-handler.cc
|
|
4
|
+
+++ b/src/profile-handler.cc
|
|
5
|
+
@@ -133,6 +133,9 @@ class ProfileHandler {
|
|
6
|
+
// SIGPROF interrupt frequency, read-only after construction.
|
|
7
|
+
int32 frequency_;
|
|
8
|
+
|
|
9
|
+
+ // use SIGALRM/ITIMER_REAL
|
|
10
|
+
+ bool realtime_;
|
|
11
|
+
+
|
|
12
|
+
// Counts the number of callbacks registered.
|
|
13
|
+
int32 callback_count_ GUARDED_BY(control_lock_);
|
|
14
|
+
|
|
15
|
+
@@ -241,6 +244,13 @@ ProfileHandler::ProfileHandler()
|
|
16
|
+
callback_count_(0),
|
|
17
|
+
timer_sharing_(TIMERS_UNTOUCHED) {
|
|
18
|
+
SpinLockHolder cl(&control_lock_);
|
|
19
|
+
+
|
|
20
|
+
+ const char* rt = getenv("CPUPROFILE_REALTIME");
|
|
21
|
+
+ if (rt != NULL)
|
|
22
|
+
+ realtime_ = true;
|
|
23
|
+
+ else
|
|
24
|
+
+ realtime_ = false;
|
|
25
|
+
+
|
|
26
|
+
// Get frequency of interrupts (if specified)
|
|
27
|
+
char junk;
|
|
28
|
+
const char* fr = getenv("CPUPROFILE_FREQUENCY");
|
|
29
|
+
@@ -396,18 +406,18 @@ void ProfileHandler::StartTimer() {
|
|
30
|
+
timer.it_interval.tv_sec = 0;
|
|
31
|
+
timer.it_interval.tv_usec = 1000000 / frequency_;
|
|
32
|
+
timer.it_value = timer.it_interval;
|
|
33
|
+
- setitimer(ITIMER_PROF, &timer, 0);
|
|
34
|
+
+ setitimer(realtime_ ? ITIMER_REAL : ITIMER_PROF, &timer, 0);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
void ProfileHandler::StopTimer() {
|
|
38
|
+
struct itimerval timer;
|
|
39
|
+
memset(&timer, 0, sizeof timer);
|
|
40
|
+
- setitimer(ITIMER_PROF, &timer, 0);
|
|
41
|
+
+ setitimer(realtime_ ? ITIMER_REAL : ITIMER_PROF, &timer, 0);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
bool ProfileHandler::IsTimerRunning() {
|
|
45
|
+
struct itimerval current_timer;
|
|
46
|
+
- RAW_CHECK(0 == getitimer(ITIMER_PROF, ¤t_timer), "getitimer");
|
|
47
|
+
+ RAW_CHECK(0 == getitimer(realtime_ ? ITIMER_REAL : ITIMER_PROF, ¤t_timer), "getitimer");
|
|
48
|
+
return (current_timer.it_value.tv_sec != 0 ||
|
|
49
|
+
current_timer.it_value.tv_usec != 0);
|
|
50
|
+
}
|
|
51
|
+
@@ -417,7 +427,7 @@ void ProfileHandler::EnableHandler() {
|
|
52
|
+
sa.sa_sigaction = SignalHandler;
|
|
53
|
+
sa.sa_flags = SA_RESTART | SA_SIGINFO;
|
|
54
|
+
sigemptyset(&sa.sa_mask);
|
|
55
|
+
- RAW_CHECK(sigaction(SIGPROF, &sa, NULL) == 0, "sigprof (enable)");
|
|
56
|
+
+ RAW_CHECK(sigaction(realtime_ ? SIGALRM : SIGPROF, &sa, NULL) == 0, "sigprof (enable)");
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
void ProfileHandler::DisableHandler() {
|
|
60
|
+
@@ -425,7 +435,7 @@ void ProfileHandler::DisableHandler() {
|
|
61
|
+
sa.sa_handler = SIG_IGN;
|
|
62
|
+
sa.sa_flags = SA_RESTART;
|
|
63
|
+
sigemptyset(&sa.sa_mask);
|
|
64
|
+
- RAW_CHECK(sigaction(SIGPROF, &sa, NULL) == 0, "sigprof (disable)");
|
|
65
|
+
+ RAW_CHECK(sigaction(realtime_ ? SIGALRM : SIGPROF, &sa, NULL) == 0, "sigprof (disable)");
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
void ProfileHandler::SignalHandler(int sig, siginfo_t* sinfo, void* ucontext) {
|
data/patches/perftools.patch
CHANGED
data/perftools.rb.gemspec
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
spec = Gem::Specification.new do |s|
|
|
2
2
|
s.name = 'perftools.rb'
|
|
3
|
-
s.version = '0.3.
|
|
4
|
-
s.date = '2009-
|
|
3
|
+
s.version = '0.3.7'
|
|
4
|
+
s.date = '2009-11-03'
|
|
5
5
|
s.rubyforge_project = 'perftools-rb'
|
|
6
6
|
s.summary = 'google-perftools for ruby code'
|
|
7
7
|
s.description = 'A sampling profiler for ruby code based on patches to google-perftools'
|
|
@@ -28,6 +28,7 @@ spec = Gem::Specification.new do |s|
|
|
|
28
28
|
"patches/perftools-osx-106.patch",
|
|
29
29
|
"patches/perftools-osx.patch",
|
|
30
30
|
"patches/perftools-pprof.patch",
|
|
31
|
+
"patches/perftools-realtime.patch",
|
|
31
32
|
"patches/perftools-notests.patch",
|
|
32
33
|
"patches/perftools.patch",
|
|
33
34
|
"perftools.rb.gemspec"
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: perftools.rb
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.
|
|
4
|
+
version: 0.3.7
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Aman Gupta
|
|
@@ -9,7 +9,7 @@ autorequire:
|
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
11
|
|
|
12
|
-
date: 2009-
|
|
12
|
+
date: 2009-11-03 00:00:00 -08:00
|
|
13
13
|
default_executable:
|
|
14
14
|
dependencies: []
|
|
15
15
|
|
|
@@ -32,6 +32,7 @@ files:
|
|
|
32
32
|
- patches/perftools-osx-106.patch
|
|
33
33
|
- patches/perftools-osx.patch
|
|
34
34
|
- patches/perftools-pprof.patch
|
|
35
|
+
- patches/perftools-realtime.patch
|
|
35
36
|
- patches/perftools-notests.patch
|
|
36
37
|
- patches/perftools.patch
|
|
37
38
|
- perftools.rb.gemspec
|