perftools.rb 0.4.4 → 0.4.5
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/ext/perftools.c +24 -21
- data/perftools.rb.gemspec +2 -2
- metadata +5 -17
data/ext/perftools.c
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
#ifndef _GNU_SOURCE
|
2
|
+
#define _GNU_SOURCE
|
3
|
+
#endif
|
4
|
+
#ifndef _XOPEN_SOURCE
|
5
|
+
#define _XOPEN_SOURCE 600
|
6
|
+
#endif
|
7
|
+
|
1
8
|
#include <assert.h>
|
2
9
|
#include <ruby.h>
|
3
10
|
|
@@ -261,13 +268,6 @@ cpuprofiler_gc_mark()
|
|
261
268
|
|
262
269
|
/* ObjProfiler */
|
263
270
|
|
264
|
-
#ifndef _GNU_SOURCE
|
265
|
-
#define _GNU_SOURCE
|
266
|
-
#endif
|
267
|
-
#ifndef _XOPEN_SOURCE
|
268
|
-
#define _XOPEN_SOURCE 600
|
269
|
-
#endif
|
270
|
-
|
271
271
|
#include <assert.h>
|
272
272
|
#include <ucontext.h>
|
273
273
|
#include <unistd.h>
|
@@ -281,7 +281,7 @@ static VALUE bObjProfilerRunning;
|
|
281
281
|
#define NUM_ORIG_BYTES 2
|
282
282
|
|
283
283
|
struct {
|
284
|
-
|
284
|
+
char *location;
|
285
285
|
unsigned char value;
|
286
286
|
} orig_bytes[NUM_ORIG_BYTES];
|
287
287
|
|
@@ -292,14 +292,11 @@ page_align(void *addr) {
|
|
292
292
|
}
|
293
293
|
|
294
294
|
static void
|
295
|
-
|
296
|
-
assert(
|
297
|
-
|
298
|
-
|
299
|
-
void *aligned_addr = page_align(dest);
|
300
|
-
if (mprotect(aligned_addr, (dest - aligned_addr) + count, PROT_READ|PROT_WRITE|PROT_EXEC) != 0)
|
295
|
+
unprotect_page(void *addr) {
|
296
|
+
assert(addr != NULL);
|
297
|
+
void *aligned_addr = page_align(addr);
|
298
|
+
if (mprotect(aligned_addr, (addr - aligned_addr), PROT_READ|PROT_WRITE|PROT_EXEC) != 0)
|
301
299
|
perror("mprotect");
|
302
|
-
memcpy(dest, src, count);
|
303
300
|
}
|
304
301
|
|
305
302
|
static inline void**
|
@@ -309,7 +306,11 @@ uc_get_ip(ucontext_t *uc) {
|
|
309
306
|
#elif defined(__dietlibc__)
|
310
307
|
return (void**)&uc->uc_mcontext.rip;
|
311
308
|
#elif defined(__APPLE__)
|
312
|
-
|
309
|
+
#if defined(__LP64__)
|
310
|
+
return (void**)&uc->uc_mcontext->__ss.__rip;
|
311
|
+
#else
|
312
|
+
return (void**)&uc->uc_mcontext->__ss.__eip;
|
313
|
+
#endif
|
313
314
|
#else
|
314
315
|
return (void**)&uc->uc_mcontext.gregs[REG_RIP];
|
315
316
|
#endif
|
@@ -326,10 +327,10 @@ trap_handler(int sig, siginfo_t *info, void *data) {
|
|
326
327
|
for (i=0; i<NUM_ORIG_BYTES; i++) {
|
327
328
|
if (orig_bytes[i].location == *ip-1) {
|
328
329
|
// restore original byte
|
329
|
-
|
330
|
+
orig_bytes[i].location[0] = orig_bytes[i].value;
|
330
331
|
|
331
332
|
// setup next breakpoint
|
332
|
-
|
333
|
+
orig_bytes[(i+1)%NUM_ORIG_BYTES].location[0] = '\xCC';
|
333
334
|
|
334
335
|
// first breakpoint is the notification
|
335
336
|
if (i == 0)
|
@@ -354,10 +355,12 @@ objprofiler_setup()
|
|
354
355
|
sigemptyset(&sig.sa_mask);
|
355
356
|
sigaction(SIGTRAP, &sig, NULL);
|
356
357
|
|
358
|
+
unprotect_page(rb_newobj);
|
359
|
+
|
357
360
|
for (i=0; i<NUM_ORIG_BYTES; i++) {
|
358
|
-
orig_bytes[i].location = rb_newobj + i;
|
361
|
+
orig_bytes[i].location = (char *)(rb_newobj + i);
|
359
362
|
orig_bytes[i].value = ((unsigned char*)rb_newobj)[i];
|
360
|
-
|
363
|
+
orig_bytes[i].location[0] = '\xCC';
|
361
364
|
}
|
362
365
|
|
363
366
|
// setenv("CPUPROFILE_OBJECTS", "1", 1);
|
@@ -377,7 +380,7 @@ objprofiler_teardown()
|
|
377
380
|
sigaction(SIGTRAP, &sig, NULL);
|
378
381
|
|
379
382
|
for (i=0; i<NUM_ORIG_BYTES; i++) {
|
380
|
-
|
383
|
+
orig_bytes[i].location[0] = orig_bytes[i].value;
|
381
384
|
}
|
382
385
|
|
383
386
|
// unsetenv("CPUPROFILE_OBJECTS");
|
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.4.
|
4
|
-
s.date = '2010-08-
|
3
|
+
s.version = '0.4.5'
|
4
|
+
s.date = '2010-08-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'
|
metadata
CHANGED
@@ -1,13 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: perftools.rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease: false
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 4
|
9
|
-
- 4
|
10
|
-
version: 0.4.4
|
4
|
+
version: 0.4.5
|
11
5
|
platform: ruby
|
12
6
|
authors:
|
13
7
|
- Aman Gupta
|
@@ -15,7 +9,7 @@ autorequire:
|
|
15
9
|
bindir: bin
|
16
10
|
cert_chain: []
|
17
11
|
|
18
|
-
date: 2010-08-
|
12
|
+
date: 2010-08-03 00:00:00 -07:00
|
19
13
|
default_executable:
|
20
14
|
dependencies: []
|
21
15
|
|
@@ -55,27 +49,21 @@ rdoc_options: []
|
|
55
49
|
require_paths:
|
56
50
|
- lib
|
57
51
|
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
-
none: false
|
59
52
|
requirements:
|
60
53
|
- - ">="
|
61
54
|
- !ruby/object:Gem::Version
|
62
|
-
hash: 3
|
63
|
-
segments:
|
64
|
-
- 0
|
65
55
|
version: "0"
|
56
|
+
version:
|
66
57
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
-
none: false
|
68
58
|
requirements:
|
69
59
|
- - ">="
|
70
60
|
- !ruby/object:Gem::Version
|
71
|
-
hash: 3
|
72
|
-
segments:
|
73
|
-
- 0
|
74
61
|
version: "0"
|
62
|
+
version:
|
75
63
|
requirements: []
|
76
64
|
|
77
65
|
rubyforge_project: perftools-rb
|
78
|
-
rubygems_version: 1.3.
|
66
|
+
rubygems_version: 1.3.5
|
79
67
|
signing_key:
|
80
68
|
specification_version: 3
|
81
69
|
summary: google-perftools for ruby code
|