ruby-static-tracing 0.0.12 → 0.0.13

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.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/ext/ruby-static-tracing/lib/deps-extconf.rb +1 -1
  3. data/ext/ruby-static-tracing/lib/libstapsdt/Makefile +76 -0
  4. data/ext/ruby-static-tracing/lib/libstapsdt/example/demo.c +42 -0
  5. data/ext/ruby-static-tracing/lib/libstapsdt/src/asm/libstapsdt-x86_64.s +14 -0
  6. data/ext/ruby-static-tracing/lib/libstapsdt/src/dynamic-symbols.c +41 -0
  7. data/ext/ruby-static-tracing/lib/libstapsdt/src/dynamic-symbols.h +34 -0
  8. data/ext/ruby-static-tracing/lib/libstapsdt/src/errors.c +30 -0
  9. data/ext/ruby-static-tracing/lib/libstapsdt/src/errors.h +8 -0
  10. data/ext/ruby-static-tracing/lib/libstapsdt/src/hash-table.c +27 -0
  11. data/ext/ruby-static-tracing/lib/libstapsdt/src/hash-table.h +3 -0
  12. data/ext/ruby-static-tracing/lib/libstapsdt/src/libstapsdt.c +258 -0
  13. data/ext/ruby-static-tracing/lib/libstapsdt/src/libstapsdt.h +67 -0
  14. data/ext/ruby-static-tracing/lib/libstapsdt/src/sdtnote.c +176 -0
  15. data/ext/ruby-static-tracing/lib/libstapsdt/src/sdtnote.h +46 -0
  16. data/ext/ruby-static-tracing/lib/libstapsdt/src/section.c +30 -0
  17. data/ext/ruby-static-tracing/lib/libstapsdt/src/section.h +21 -0
  18. data/ext/ruby-static-tracing/lib/libstapsdt/src/shared-lib.c +563 -0
  19. data/ext/ruby-static-tracing/lib/libstapsdt/src/shared-lib.h +46 -0
  20. data/ext/ruby-static-tracing/lib/libstapsdt/src/string-table.c +67 -0
  21. data/ext/ruby-static-tracing/lib/libstapsdt/src/string-table.h +28 -0
  22. data/ext/ruby-static-tracing/lib/libstapsdt/src/util.c +12 -0
  23. data/ext/ruby-static-tracing/lib/libstapsdt/src/util.h +6 -0
  24. data/ext/ruby-static-tracing/lib/libstapsdt/tests/test-errors.c +77 -0
  25. data/ext/ruby-static-tracing/lib/libstapsdt/tests/test-memory-leaks.c +25 -0
  26. data/ext/ruby-static-tracing/lib/libusdt/Makefile +168 -0
  27. data/ext/ruby-static-tracing/lib/libusdt/test_mem_usage.c +77 -0
  28. data/ext/ruby-static-tracing/lib/libusdt/test_usdt.c +87 -0
  29. data/ext/ruby-static-tracing/lib/libusdt/usdt.c +321 -0
  30. data/ext/ruby-static-tracing/lib/libusdt/usdt.h +65 -0
  31. data/ext/ruby-static-tracing/lib/libusdt/usdt_dof.c +126 -0
  32. data/ext/ruby-static-tracing/lib/libusdt/usdt_dof_file.c +290 -0
  33. data/ext/ruby-static-tracing/lib/libusdt/usdt_dof_sections.c +180 -0
  34. data/ext/ruby-static-tracing/lib/libusdt/usdt_internal.h +107 -0
  35. data/ext/ruby-static-tracing/lib/libusdt/usdt_probe.c +133 -0
  36. data/ext/ruby-static-tracing/lib/libusdt/usdt_tracepoints_i386.s +69 -0
  37. data/ext/ruby-static-tracing/lib/libusdt/usdt_tracepoints_x86_64.s +123 -0
  38. data/lib/ruby-static-tracing/version.rb +1 -1
  39. metadata +38 -2
@@ -0,0 +1,107 @@
1
+ /*
2
+ * Copyright (c) 2012, Chris Andrews. All rights reserved.
3
+ */
4
+
5
+ #ifndef __LIB_USDT_USDT_INTERNAL_H__
6
+ #define __LIB_USDT_USDT_INTERNAL_H__
7
+
8
+ #ifdef __linux__
9
+ #include <endian.h>
10
+ #if __BYTE_ORDER == __LITTLE_ENDIAN
11
+ #ifndef _LITTLE_ENDIAN
12
+ #define _LITTLE_ENDIAN
13
+ #endif
14
+ #endif
15
+ #endif
16
+
17
+ #include <sys/dtrace.h>
18
+ #include <sys/types.h>
19
+ #include <sys/mman.h>
20
+
21
+ #include <stdlib.h>
22
+ #include <errno.h>
23
+ #include <string.h>
24
+ #include <fcntl.h>
25
+ #include <unistd.h>
26
+ #include <stdint.h>
27
+ #include <assert.h>
28
+
29
+ #define FUNC_SIZE 32
30
+
31
+ #include "usdt.h"
32
+
33
+ extern void usdt_tracepoint_isenabled(void);
34
+ extern void usdt_tracepoint_probe(void);
35
+ extern void usdt_tracepoint_end(void);
36
+ extern void usdt_probe_args(void *, int, void**);
37
+
38
+ uint32_t usdt_probe_offset(usdt_probe_t *probe, char *dof, uint8_t argc);
39
+ uint32_t usdt_is_enabled_offset(usdt_probe_t *probe, char *dof);
40
+ int usdt_create_tracepoints(usdt_probe_t *probe);
41
+ void usdt_free_tracepoints(usdt_probe_t *probe);
42
+
43
+ typedef struct usdt_dof_section {
44
+ dof_secidx_t index;
45
+ uint32_t type;
46
+ uint32_t flags;
47
+ uint32_t align;
48
+ uint64_t offset;
49
+ uint64_t size;
50
+ uint32_t entsize;
51
+ size_t pad;
52
+ struct usdt_dof_section *next;
53
+ char *data;
54
+ } usdt_dof_section_t;
55
+
56
+ int usdt_dof_section_init(usdt_dof_section_t *section,
57
+ uint32_t type, dof_secidx_t index);
58
+ int usdt_dof_section_add_data(usdt_dof_section_t *section,
59
+ void *data, size_t length);
60
+ void usdt_dof_section_free(usdt_dof_section_t *section);
61
+
62
+ typedef struct usdt_strtab {
63
+ dof_secidx_t index;
64
+ uint32_t type;
65
+ uint32_t flags;
66
+ uint32_t align;
67
+ uint64_t offset;
68
+ uint64_t size;
69
+ uint32_t entsize;
70
+ size_t pad;
71
+ int strindex;
72
+ char *data;
73
+ } usdt_strtab_t;
74
+
75
+ int usdt_strtab_init(usdt_strtab_t *strtab, dof_secidx_t index);
76
+ dof_stridx_t usdt_strtab_add(usdt_strtab_t *strtab, const char *string);
77
+ char *usdt_strtab_header(usdt_strtab_t *strtab);
78
+ size_t usdt_strtab_size(usdt_strtab_t *strtab);
79
+
80
+ size_t usdt_provider_dof_size(usdt_provider_t *provider, usdt_strtab_t *strtab);
81
+
82
+ typedef struct usdt_dof_file {
83
+ char *dof;
84
+ int gen;
85
+ size_t size;
86
+ usdt_dof_section_t *sections;
87
+ } usdt_dof_file_t;
88
+
89
+ usdt_dof_file_t *usdt_dof_file_init(usdt_provider_t *provider, size_t size);
90
+ void usdt_dof_file_append_section(usdt_dof_file_t *file, usdt_dof_section_t *section);
91
+ void usdt_dof_file_generate(usdt_dof_file_t *file, usdt_strtab_t *strtab);
92
+ int usdt_dof_file_load(usdt_dof_file_t *file, const char *module);
93
+ int usdt_dof_file_unload(usdt_dof_file_t *file);
94
+ void usdt_dof_file_free(usdt_dof_file_t *file);
95
+
96
+ int usdt_dof_probes_sect(usdt_dof_section_t *probes,
97
+ usdt_provider_t *provider, usdt_strtab_t *strtab);
98
+ int usdt_dof_prargs_sect(usdt_dof_section_t *prargs,
99
+ usdt_provider_t *provider);
100
+ int usdt_dof_proffs_sect(usdt_dof_section_t *proffs,
101
+ usdt_provider_t *provider, char *dof);
102
+ int usdt_dof_prenoffs_sect(usdt_dof_section_t *prenoffs,
103
+ usdt_provider_t *provider, char *dof);
104
+ int usdt_dof_provider_sect(usdt_dof_section_t *provider_s,
105
+ usdt_provider_t *provider);
106
+
107
+ #endif // __LIB_USDT_USDT_INTERNAL_H__
@@ -0,0 +1,133 @@
1
+ /*
2
+ * Copyright (c) 2012, Chris Andrews. All rights reserved.
3
+ */
4
+
5
+ #include "usdt_internal.h"
6
+
7
+ #ifdef __APPLE__
8
+
9
+ uint32_t
10
+ usdt_probe_offset(usdt_probe_t *probe, char *dof, uint8_t argc)
11
+ {
12
+ uint32_t offset;
13
+ #ifdef __x86_64__
14
+ offset = ((uint64_t) probe->probe_addr - (uint64_t) dof + 2);
15
+ #elif __i386__
16
+ offset = ((uint32_t) probe->probe_addr - (uint32_t) dof + 2);
17
+ #else
18
+ #error "only x86_64 and i386 supported"
19
+ #endif
20
+ return (offset);
21
+ }
22
+
23
+ uint32_t
24
+ usdt_is_enabled_offset(usdt_probe_t *probe, char *dof)
25
+ {
26
+ uint32_t offset;
27
+ #ifdef __x86_64__
28
+ offset = ((uint64_t) probe->isenabled_addr - (uint64_t) dof + 6);
29
+ #elif __i386__
30
+ offset = ((uint32_t) probe->isenabled_addr - (uint32_t) dof + 6);
31
+ #else
32
+ #error "only x86_64 and i386 supported"
33
+ #endif
34
+ return (offset);
35
+ }
36
+
37
+ #elif defined __linux__
38
+
39
+ uint32_t
40
+ usdt_probe_offset(usdt_probe_t *probe, char *dof, uint8_t argc)
41
+ {
42
+ return (16);
43
+ }
44
+
45
+ uint32_t
46
+ usdt_is_enabled_offset(usdt_probe_t *probe, char *dof)
47
+ {
48
+ return (10);
49
+ }
50
+
51
+ #else /* solaris and freebsd */
52
+
53
+ uint32_t
54
+ usdt_probe_offset(usdt_probe_t *probe, char *dof, uint8_t argc)
55
+ {
56
+ return (16);
57
+ }
58
+
59
+ uint32_t
60
+ usdt_is_enabled_offset(usdt_probe_t *probe, char *dof)
61
+ {
62
+ return (8);
63
+ }
64
+
65
+ #endif
66
+
67
+ int
68
+ usdt_create_tracepoints(usdt_probe_t *probe)
69
+ {
70
+ /* Prepare the tracepoints - for each probe, a separate chunk
71
+ * of memory with the tracepoint code copied into it, to give
72
+ * us unique addresses for each tracepoint.
73
+ *
74
+ * On Oracle Linux, this must be an mmapped file because USDT
75
+ * probes there are implemented as uprobes, which are
76
+ * addressed by inode and offset. The file used is a small
77
+ * mkstemp'd file we immediately unlink.
78
+ *
79
+ * Elsewhere, we can use the heap directly because USDT will
80
+ * instrument any memory mapped by the process.
81
+ */
82
+
83
+ size_t size;
84
+ #ifdef __linux__
85
+ int fd;
86
+ char tmp[20] = "/tmp/libusdtXXXXXX";
87
+
88
+ if ((fd = mkstemp(tmp)) < 0)
89
+ return (-1);
90
+ if (unlink(tmp) < 0)
91
+ return (-1);
92
+ if (write(fd, "\0", FUNC_SIZE) < FUNC_SIZE)
93
+ return (-1);
94
+
95
+ probe->isenabled_addr = (int (*)())mmap(NULL, FUNC_SIZE,
96
+ PROT_READ | PROT_WRITE | PROT_EXEC,
97
+ MAP_PRIVATE, fd, 0);
98
+ #else
99
+ probe->isenabled_addr = (int (*)())valloc(FUNC_SIZE);
100
+ #endif
101
+ if (probe->isenabled_addr == NULL)
102
+ return (-1);
103
+
104
+ /* ensure that the tracepoints will fit the heap we're allocating */
105
+ size = ((char *)usdt_tracepoint_end - (char *)usdt_tracepoint_isenabled);
106
+ assert(size < FUNC_SIZE);
107
+
108
+ size = ((char *)usdt_tracepoint_probe - (char *)usdt_tracepoint_isenabled);
109
+ probe->probe_addr = (char *)probe->isenabled_addr + size;
110
+
111
+ memcpy((void *)probe->isenabled_addr,
112
+ (const void *)usdt_tracepoint_isenabled, FUNC_SIZE);
113
+
114
+ #ifdef __linux__
115
+ mprotect((void *)probe->isenabled_addr, FUNC_SIZE,
116
+ PROT_READ | PROT_EXEC);
117
+ #else
118
+ mprotect((void *)probe->isenabled_addr, FUNC_SIZE,
119
+ PROT_READ | PROT_WRITE | PROT_EXEC);
120
+ #endif
121
+
122
+ return (0);
123
+ }
124
+
125
+ void
126
+ usdt_free_tracepoints(usdt_probe_t *probe)
127
+ {
128
+ #ifdef __linux__
129
+ (void) munmap(probe->isenabled_addr, FUNC_SIZE);
130
+ #else
131
+ free(probe->isenabled_addr);
132
+ #endif
133
+ }
@@ -0,0 +1,69 @@
1
+ /*
2
+ * Copyright (c) 2012, Chris Andrews. All rights reserved.
3
+ */
4
+
5
+ /*
6
+ * Stub functions containing DTrace tracepoints for probes and
7
+ * is-enabled probes. These functions are copied for each probe
8
+ * dynamically created.
9
+ *
10
+ */
11
+ .text
12
+
13
+ .align 4, 0x90
14
+ .globl usdt_tracepoint_isenabled
15
+ .globl _usdt_tracepoint_isenabled
16
+ .globl usdt_tracepoint_probe
17
+ .globl _usdt_tracepoint_probe
18
+ .globl usdt_tracepoint_end
19
+ .globl _usdt_tracepoint_end
20
+ .globl usdt_probe_args
21
+ .globl _usdt_probe_args
22
+
23
+ usdt_tracepoint_isenabled:
24
+ _usdt_tracepoint_isenabled:
25
+ pushl %ebp
26
+ movl %esp, %ebp
27
+ subl $8, %esp
28
+ xorl %eax, %eax
29
+ nop
30
+ nop
31
+ leave
32
+ ret
33
+ usdt_tracepoint_probe:
34
+ _usdt_tracepoint_probe:
35
+ nop
36
+ nop
37
+ nop
38
+ nop
39
+ nop
40
+ addl $0x20,%esp
41
+ leave
42
+ usdt_tracepoint_end:
43
+ _usdt_tracepoint_end:
44
+ ret
45
+
46
+ /*
47
+ * Probe argument marshalling, i386 style
48
+ *
49
+ */
50
+
51
+ usdt_probe_args:
52
+ _usdt_probe_args:
53
+ pushl %ebp
54
+ movl %esp,%ebp
55
+ subl $8,%esp
56
+ subl $8,%esp
57
+ movl 8(%ebp),%edx
58
+ movl 0xc(%ebp),%ecx
59
+ test %ecx,%ecx
60
+ je fire
61
+ args: movl %ecx,%eax
62
+ sal $2,%eax
63
+ subl $4,%eax
64
+ addl 0x10(%ebp),%eax
65
+ pushl (%eax)
66
+ dec %ecx
67
+ jne args
68
+ fire: jmp *%edx
69
+
@@ -0,0 +1,123 @@
1
+ /*
2
+ * Copyright (c) 2012, Chris Andrews. All rights reserved.
3
+ */
4
+
5
+ /*
6
+ * Stub functions containing DTrace tracepoints for probes and
7
+ * is-enabled probes. These functions are copied for each probe
8
+ * dynamically created.
9
+ *
10
+ */
11
+ .text
12
+
13
+ .align 4, 0x90
14
+ .globl usdt_tracepoint_isenabled
15
+ .globl _usdt_tracepoint_isenabled
16
+ .globl usdt_tracepoint_probe
17
+ .globl _usdt_tracepoint_probe
18
+ .globl usdt_tracepoint_end
19
+ .globl _usdt_tracepoint_end
20
+ .globl usdt_probe_args
21
+ .globl _usdt_probe_args
22
+
23
+ usdt_tracepoint_isenabled:
24
+ _usdt_tracepoint_isenabled:
25
+ pushq %rbp
26
+ movq %rsp, %rbp
27
+ addq $1, %rax
28
+ xorq %rax, %rax
29
+ nop
30
+ nop
31
+ leave
32
+ ret
33
+ usdt_tracepoint_probe:
34
+ _usdt_tracepoint_probe:
35
+ nop
36
+ nop
37
+ nop
38
+ nop
39
+ nop
40
+ addq %r14,%rsp
41
+ popq %rbx
42
+ popq %r14
43
+ popq %r13
44
+ popq %r12
45
+ leave
46
+ usdt_tracepoint_end:
47
+ _usdt_tracepoint_end:
48
+ ret
49
+
50
+ /*
51
+ * Probe argument marshalling, x86_64 style
52
+ *
53
+ */
54
+
55
+ usdt_probe_args:
56
+ _usdt_probe_args:
57
+ pushq %rbp
58
+ movq %rsp,%rbp
59
+ pushq %r12
60
+ pushq %r13
61
+ pushq %r14
62
+ pushq %rbx
63
+
64
+ movq %rdi,%r12
65
+ movq %rsi,%rbx
66
+ movq %rdx,%r11
67
+ movq $0,%r14
68
+
69
+ test %rbx,%rbx
70
+ je fire
71
+ movq (%r11),%rdi
72
+ dec %rbx
73
+ test %rbx,%rbx
74
+ je fire
75
+ addq $8,%r11
76
+ movq (%r11),%rsi
77
+ dec %rbx
78
+ test %rbx,%rbx
79
+ je fire
80
+ addq $8,%r11
81
+ movq (%r11),%rdx
82
+ dec %rbx
83
+ test %rbx,%rbx
84
+ je fire
85
+ addq $8,%r11
86
+ movq (%r11),%rcx
87
+ dec %rbx
88
+ test %rbx,%rbx
89
+ je fire
90
+ addq $8,%r11
91
+ movq (%r11),%r8
92
+ dec %rbx
93
+ test %rbx,%rbx
94
+ je fire
95
+ addq $8,%r11
96
+ movq (%r11),%r9
97
+
98
+ movq %rbx,%r13
99
+ morestack:
100
+ dec %rbx
101
+ test %rbx,%rbx
102
+ je args
103
+ subq $16,%rsp
104
+ addq $16,%r14
105
+ dec %rbx
106
+ test %rbx,%rbx
107
+ je args
108
+ jmp morestack
109
+
110
+ args:
111
+ movq %r13,%rbx
112
+ movq $0,%r13
113
+ moreargs:
114
+ dec %rbx
115
+ test %rbx,%rbx
116
+ je fire
117
+ addq $8,%r11
118
+ movq (%r11),%rax
119
+ movq %rax,(%rsp,%r13)
120
+ addq $8,%r13
121
+ jmp moreargs
122
+
123
+ fire: jmp *%r12
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module StaticTracing
4
- VERSION = '0.0.12'
4
+ VERSION = '0.0.13'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-static-tracing
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dale Hamel
@@ -113,6 +113,41 @@ files:
113
113
  - ext/ruby-static-tracing/extconf.rb
114
114
  - ext/ruby-static-tracing/include/ruby_static_tracing.h
115
115
  - ext/ruby-static-tracing/lib/deps-extconf.rb
116
+ - ext/ruby-static-tracing/lib/libstapsdt/Makefile
117
+ - ext/ruby-static-tracing/lib/libstapsdt/example/demo.c
118
+ - ext/ruby-static-tracing/lib/libstapsdt/src/asm/libstapsdt-x86_64.s
119
+ - ext/ruby-static-tracing/lib/libstapsdt/src/dynamic-symbols.c
120
+ - ext/ruby-static-tracing/lib/libstapsdt/src/dynamic-symbols.h
121
+ - ext/ruby-static-tracing/lib/libstapsdt/src/errors.c
122
+ - ext/ruby-static-tracing/lib/libstapsdt/src/errors.h
123
+ - ext/ruby-static-tracing/lib/libstapsdt/src/hash-table.c
124
+ - ext/ruby-static-tracing/lib/libstapsdt/src/hash-table.h
125
+ - ext/ruby-static-tracing/lib/libstapsdt/src/libstapsdt.c
126
+ - ext/ruby-static-tracing/lib/libstapsdt/src/libstapsdt.h
127
+ - ext/ruby-static-tracing/lib/libstapsdt/src/sdtnote.c
128
+ - ext/ruby-static-tracing/lib/libstapsdt/src/sdtnote.h
129
+ - ext/ruby-static-tracing/lib/libstapsdt/src/section.c
130
+ - ext/ruby-static-tracing/lib/libstapsdt/src/section.h
131
+ - ext/ruby-static-tracing/lib/libstapsdt/src/shared-lib.c
132
+ - ext/ruby-static-tracing/lib/libstapsdt/src/shared-lib.h
133
+ - ext/ruby-static-tracing/lib/libstapsdt/src/string-table.c
134
+ - ext/ruby-static-tracing/lib/libstapsdt/src/string-table.h
135
+ - ext/ruby-static-tracing/lib/libstapsdt/src/util.c
136
+ - ext/ruby-static-tracing/lib/libstapsdt/src/util.h
137
+ - ext/ruby-static-tracing/lib/libstapsdt/tests/test-errors.c
138
+ - ext/ruby-static-tracing/lib/libstapsdt/tests/test-memory-leaks.c
139
+ - ext/ruby-static-tracing/lib/libusdt/Makefile
140
+ - ext/ruby-static-tracing/lib/libusdt/test_mem_usage.c
141
+ - ext/ruby-static-tracing/lib/libusdt/test_usdt.c
142
+ - ext/ruby-static-tracing/lib/libusdt/usdt.c
143
+ - ext/ruby-static-tracing/lib/libusdt/usdt.h
144
+ - ext/ruby-static-tracing/lib/libusdt/usdt_dof.c
145
+ - ext/ruby-static-tracing/lib/libusdt/usdt_dof_file.c
146
+ - ext/ruby-static-tracing/lib/libusdt/usdt_dof_sections.c
147
+ - ext/ruby-static-tracing/lib/libusdt/usdt_internal.h
148
+ - ext/ruby-static-tracing/lib/libusdt/usdt_probe.c
149
+ - ext/ruby-static-tracing/lib/libusdt/usdt_tracepoints_i386.s
150
+ - ext/ruby-static-tracing/lib/libusdt/usdt_tracepoints_x86_64.s
116
151
  - ext/ruby-static-tracing/lib/post-extconf.rb
117
152
  - ext/ruby-static-tracing/linux/provider.c
118
153
  - ext/ruby-static-tracing/linux/provider.h
@@ -154,7 +189,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
154
189
  - !ruby/object:Gem::Version
155
190
  version: '0'
156
191
  requirements: []
157
- rubygems_version: 3.0.3
192
+ rubyforge_project:
193
+ rubygems_version: 2.7.6.2
158
194
  signing_key:
159
195
  specification_version: 4
160
196
  summary: USDT tracing for Ruby