ruby-static-tracing 0.0.12 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
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,46 @@
1
+ #ifndef _SHARED_LIB_H
2
+ #define _SHARED_LIB_H
3
+
4
+ #include "section.h"
5
+ #include "string-table.h"
6
+ #include "sdtnote.h"
7
+ #include "dynamic-symbols.h"
8
+
9
+ typedef struct {
10
+ Section
11
+ *hash,
12
+ *dynSym,
13
+ *dynStr,
14
+ *text,
15
+ *sdtBase,
16
+ *ehFrame,
17
+ *dynamic,
18
+ *sdtNote,
19
+ *shStrTab;
20
+ } SectionsList;
21
+
22
+ typedef struct {
23
+ Elf *elf;
24
+ Elf64_Ehdr *ehdr;
25
+ Elf64_Phdr *phdrLoad1, *phdrLoad2, *phdrDyn, *phdrStack;
26
+
27
+ StringTable *stringTable;
28
+ StringTable *dynamicString;
29
+
30
+ DynamicSymbolTable *dynamicSymbols;
31
+
32
+ SDTNoteList_t *sdtNotes;
33
+ size_t sdtNotesCount;
34
+
35
+ SectionsList sections;
36
+ } DynElf;
37
+
38
+ DynElf *dynElfInit();
39
+
40
+ int dynElfAddProbe(DynElf *dynElf, SDTProbe_t *probe);
41
+
42
+ int dynElfSave(DynElf *dynElf);
43
+
44
+ void dynElfClose(DynElf *dynElf);
45
+
46
+ #endif
@@ -0,0 +1,67 @@
1
+ #include <stdio.h>
2
+ #include <stdlib.h>
3
+
4
+ #include "string-table.h"
5
+
6
+ StringTable *stringTableInit() {
7
+ StringTable *stringTable = (StringTable *)calloc(sizeof(StringTable), 1);
8
+ stringTable->count = 1;
9
+ stringTable->size = 1;
10
+
11
+ stringTable->first = (StringTableNode *)calloc(sizeof(StringTableNode), 1);
12
+
13
+ stringTable->first->index = 0;
14
+ stringTable->first->size = 1;
15
+ stringTable->first->str = (char *)calloc(sizeof(char), 1);
16
+ stringTable->first->str[0] = '\0';
17
+ stringTable->first->next = NULL;
18
+
19
+ return stringTable;
20
+ }
21
+
22
+ StringTableNode *stringTableAdd(StringTable *stringTable, char *str) {
23
+ StringTableNode *current;
24
+
25
+ for (current = stringTable->first; current->next != NULL;
26
+ current = current->next) {
27
+ }
28
+
29
+ current->next = (StringTableNode *)calloc(sizeof(StringTableNode), 1);
30
+ current->next->index = current->index + current->size;
31
+
32
+ current = current->next;
33
+ current->size = strlen(str) + 1;
34
+
35
+ current->str = (char *)calloc(current->size, 1);
36
+ memcpy(current->str, str, current->size);
37
+ current->next = NULL;
38
+
39
+ stringTable->count += 1;
40
+ stringTable->size += current->size;
41
+
42
+ return current;
43
+ }
44
+
45
+ char *stringTableToBuffer(StringTable *stringTable) {
46
+ int offset;
47
+ StringTableNode *current;
48
+ char *buffer = (char *)calloc(stringTable->size, 1);
49
+
50
+ for (current = stringTable->first, offset = 0; current != NULL;
51
+ offset += current->size, current = current->next) {
52
+ memcpy(&buffer[offset], current->str, current->size);
53
+ }
54
+
55
+ return buffer;
56
+ }
57
+
58
+ void stringTableFree(StringTable *table) {
59
+ StringTableNode *node=NULL, *next=NULL;
60
+ for(node=table->first; node!=NULL; node=next) {
61
+ free(node->str);
62
+
63
+ next=node->next;
64
+ free(node);
65
+ }
66
+ free(table);
67
+ }
@@ -0,0 +1,28 @@
1
+ #ifndef _STRING_TABLE_H
2
+ #define _STRING_TABLE_H
3
+
4
+ #include <stdlib.h>
5
+ #include <string.h>
6
+
7
+ typedef struct StringTableNode_ {
8
+ int index;
9
+ int size;
10
+ char *str;
11
+ struct StringTableNode_ *next;
12
+ } StringTableNode;
13
+
14
+ typedef struct {
15
+ int count;
16
+ size_t size;
17
+ StringTableNode *first;
18
+ } StringTable;
19
+
20
+ StringTable *stringTableInit();
21
+
22
+ StringTableNode *stringTableAdd(StringTable *stringTable, char *str);
23
+
24
+ char *stringTableToBuffer(StringTable *stringTable);
25
+
26
+ void stringTableFree(StringTable *stringTable);
27
+
28
+ #endif
@@ -0,0 +1,12 @@
1
+ int roundUp(int numToRound, int multiple) {
2
+ if (multiple == 0) {
3
+ return numToRound;
4
+ }
5
+
6
+ int remainder = numToRound % multiple;
7
+ if (remainder == 0) {
8
+ return numToRound;
9
+ }
10
+
11
+ return numToRound + multiple - remainder;
12
+ }
@@ -0,0 +1,6 @@
1
+ #ifndef _UTIL_H
2
+ #define _UTIL_H
3
+
4
+ int roundUp(int numToRound, int multiple);
5
+
6
+ #endif
@@ -0,0 +1,77 @@
1
+ #include "libstapsdt.h"
2
+ #include <stdio.h>
3
+ #include <unistd.h>
4
+ #include <dlfcn.h>
5
+
6
+ int testElfCreationError() {
7
+ // TODO (mmarchini) write test case for elf creation error
8
+ return 1;
9
+ }
10
+
11
+ int testTmpCreationError() {
12
+ SDTProvider_t *provider;
13
+ SDTError_t errno;
14
+ provider = providerInit("test/probe/creation/error");
15
+ if(providerLoad(provider) == 0) {
16
+ return 0;
17
+ }
18
+ printf("[testTmpCreationError] Error message: %s\n", provider->error);
19
+ errno = provider->errno;
20
+ providerDestroy(provider);
21
+ return errno == tmpCreationError;
22
+ }
23
+
24
+ int testSharedLibraryOpenError() {
25
+ // TODO (mmarchini) write test case for shared library loading error
26
+ return 1;
27
+ }
28
+
29
+ int testSymbolLoadingError() {
30
+ // TODO (mmarchini) write test case for symbol loading error
31
+ return 1;
32
+ }
33
+
34
+ int testSharedLibraryCloseError() {
35
+ SDTProvider_t *provider;
36
+ SDTError_t errno;
37
+ provider = providerInit("test-error");
38
+ providerLoad(provider);
39
+ dlclose(provider->_handle);
40
+ if(providerUnload(provider) == 0) {
41
+ return 0;
42
+ }
43
+ errno = provider->errno;
44
+ printf("[testSharedLibraryCloseError] Error message: %s\n", provider->error);
45
+ providerDestroy(provider);
46
+ return errno == sharedLibraryCloseError;
47
+ }
48
+
49
+ int main() {
50
+ if (!testElfCreationError()) {
51
+ printf("Test case failed: testElfCreationError\n");
52
+ return -1;
53
+ }
54
+
55
+ if (!testTmpCreationError()) {
56
+ printf("Test case failed: testTmpCreationError\n");
57
+ return -2;
58
+ }
59
+
60
+ if (!testSharedLibraryOpenError()) {
61
+ printf("Test case failed: testSharedLibraryOpenError\n");
62
+ return -3;
63
+ }
64
+
65
+ if (!testSymbolLoadingError()) {
66
+ printf("Test case failed: testSymbolLoadingError\n");
67
+ return -4;
68
+ }
69
+
70
+ if (!testSharedLibraryCloseError()) {
71
+ printf("Test case failed: testSharedLibraryCloseError\n");
72
+ return -5;
73
+ }
74
+
75
+
76
+ return 0;
77
+ }
@@ -0,0 +1,25 @@
1
+ #include <stdio.h>
2
+ #include <unistd.h>
3
+ #include <libstapsdt.h>
4
+
5
+ int main( int argc, char *argv[] ) {
6
+ SDTProvider_t *provider;
7
+ SDTProbe_t *probe1, *probe2;
8
+
9
+ provider = providerInit("testProvider");
10
+ probe1 = providerAddProbe(provider, "testProbe1", 4, int8, uint8, int64, uint64);
11
+ probe2 = providerAddProbe(provider, "testProbe2", 2, int8, uint8);
12
+
13
+ if(providerLoad(provider) == -1) {
14
+ printf("Something went wrong...\n");
15
+ return -1;
16
+ }
17
+
18
+ probeFire(probe1, 1, 2, 3, 4);
19
+ probeFire(probe2, -3, 8);
20
+
21
+ providerUnload(provider);
22
+ providerDestroy(provider);
23
+
24
+ return 0;
25
+ }
@@ -0,0 +1,168 @@
1
+ CC = gcc
2
+ CFLAGS = -O2 -Wall
3
+
4
+ # MAC_BUILD - set this to "universal" to build a 2-way fat library
5
+ MAC_BUILD = universal
6
+
7
+ ARCH=x86_64
8
+
9
+ # if ARCH set, disable universal build on the mac
10
+ ifdef ARCH
11
+ MAC_BUILD =
12
+ else
13
+ ARCH = $(shell uname -m)
14
+ endif
15
+
16
+ UNAME = $(shell uname -s)
17
+
18
+ ifeq ($(UNAME), Linux)
19
+ RANLIB=ranlib
20
+ CFLAGS+=-D_GNU_SOURCE -fPIC
21
+ endif
22
+
23
+ ifeq ($(UNAME), SunOS)
24
+ RANLIB=/bin/true
25
+ PATH +=:/usr/perl5/5.10.0/bin:/usr/perl5/5.12/bin
26
+ CFLAGS += -fPIC
27
+ ifeq ($(ARCH), i86pc)
28
+ ARCH = $(shell isainfo -k)
29
+ ifeq ($(ARCH), amd64)
30
+ ARCH = x86_64
31
+ else
32
+ ARCH = i386
33
+ endif
34
+ endif
35
+ ifeq ($(ARCH), x86_64)
36
+ CFLAGS += -m64
37
+ else
38
+ CFLAGS += -m32
39
+ endif
40
+ endif
41
+
42
+ ifeq ($(UNAME), FreeBSD)
43
+ RANLIB=ranlib
44
+ CFLAGS += -Wno-error=unknown-pragmas -I/usr/src/sys/cddl/compat/opensolaris -I/usr/src/sys/cddl/contrib/opensolaris/uts/common
45
+ CFLAGS += -fPIC
46
+ ifeq ($(ARCH), i386)
47
+ CFLAGS += -m32
48
+ endif
49
+ ifeq ($(ARCH), amd64)
50
+ ARCH = x86_64
51
+ endif
52
+ endif
53
+
54
+ ifeq ($(UNAME), Darwin)
55
+ RANLIB=ranlib
56
+ ifeq ($(MAC_BUILD), universal)
57
+ CFLAGS += -arch i386 -arch x86_64
58
+ else
59
+ CFLAGS += -arch $(ARCH)
60
+ endif
61
+ endif
62
+
63
+ # main library build
64
+ objects = usdt.o usdt_dof_file.o usdt_tracepoints.o usdt_probe.o usdt_dof.o usdt_dof_sections.o
65
+ headers = usdt.h usdt_internal.h
66
+
67
+ .c.o: $(headers)
68
+
69
+ ifeq ($(UNAME), Darwin)
70
+ all: libusdt.a libusdt.dylib
71
+ else
72
+ all: libusdt.a
73
+ endif
74
+
75
+ libusdt.dylib: $(objects)
76
+ $(CC) $(CFLAGS) -dynamiclib -o $@ $^
77
+
78
+ libusdt.a: $(objects) $(headers)
79
+ rm -f libusdt.a
80
+ $(AR) cru libusdt.a $(objects)
81
+ $(RANLIB) libusdt.a
82
+
83
+ # Tracepoints build.
84
+ #
85
+ # If on Darwin and building a universal library, manually assemble a
86
+ # two-way fat object file from both the 32 and 64 bit tracepoint asm
87
+ # files.
88
+ #
89
+ # Otherwise, just choose the appropriate asm file based on the build
90
+ # architecture.
91
+
92
+ ifeq ($(UNAME), Darwin)
93
+ ifeq ($(MAC_BUILD), universal)
94
+
95
+ usdt_tracepoints_i386.o: usdt_tracepoints_i386.s
96
+ $(CC) -arch i386 -o usdt_tracepoints_i386.o -c usdt_tracepoints_i386.s
97
+
98
+ usdt_tracepoints_x86_64.o: usdt_tracepoints_x86_64.s
99
+ $(CC) -arch x86_64 -o usdt_tracepoints_x86_64.o -c usdt_tracepoints_x86_64.s
100
+
101
+ usdt_tracepoints.o: usdt_tracepoints_i386.o usdt_tracepoints_x86_64.o
102
+ lipo -create -output usdt_tracepoints.o usdt_tracepoints_i386.o \
103
+ usdt_tracepoints_x86_64.o
104
+
105
+ else # Darwin, not universal
106
+ usdt_tracepoints.o: usdt_tracepoints_$(ARCH).s
107
+ $(CC) -arch $(ARCH) -o usdt_tracepoints.o -c usdt_tracepoints_$(ARCH).s
108
+ endif
109
+
110
+ else # not Darwin; FreeBSD and Illumos
111
+
112
+ ifeq ($(ARCH), x86_64)
113
+ usdt_tracepoints.o: usdt_tracepoints_x86_64.s
114
+ $(CC) $(CFLAGS) -o usdt_tracepoints.o -c usdt_tracepoints_x86_64.s
115
+ endif
116
+ ifeq ($(ARCH), i386)
117
+ usdt_tracepoints.o: usdt_tracepoints_i386.s
118
+ $(CC) $(CFLAGS) -o usdt_tracepoints.o -c usdt_tracepoints_i386.s
119
+ endif
120
+
121
+ endif
122
+
123
+ clean:
124
+ rm -f *.gch
125
+ rm -f *.o
126
+ rm -f libusdt.a
127
+ rm -f libusdt.dylib
128
+ rm -f test_usdt
129
+ rm -f test_usdt32
130
+ rm -f test_usdt64
131
+ rm -f test_mem_usage
132
+
133
+ .PHONY: clean test
134
+
135
+ # testing
136
+
137
+ test_mem_usage: libusdt.a test_mem_usage.o
138
+ $(CC) $(CFLAGS) -o test_mem_usage test_mem_usage.o libusdt.a
139
+
140
+ ifeq ($(UNAME), Darwin)
141
+ ifeq ($(MAC_BUILD), universal)
142
+ test_usdt64: libusdt.a test_usdt.o
143
+ $(CC) -arch x86_64 -o test_usdt64 test_usdt.o libusdt.a
144
+ test_usdt32: libusdt.a test_usdt.o
145
+ $(CC) -arch i386 -o test_usdt32 test_usdt.o libusdt.a
146
+ else
147
+ test_usdt: libusdt.a test_usdt.o
148
+ $(CC) $(CFLAGS) -o test_usdt test_usdt.o libusdt.a
149
+ endif
150
+ else
151
+ test_usdt: libusdt.a test_usdt.o
152
+ $(CC) $(CFLAGS) -o test_usdt test_usdt.o libusdt.a
153
+ endif
154
+
155
+ ifeq ($(UNAME), Darwin)
156
+ ifeq ($(MAC_BUILD), universal)
157
+ test: test_usdt32 test_usdt64
158
+ sudo prove test.pl :: 64
159
+ sudo prove test.pl :: 32
160
+ else
161
+ test: test_usdt
162
+ sudo prove test.pl
163
+ endif
164
+ else
165
+ test: test_usdt
166
+ sudo prove test.pl
167
+ endif
168
+
@@ -0,0 +1,77 @@
1
+ /*
2
+ * Copyright (c) 2012, Chris Andrews. All rights reserved.
3
+ */
4
+
5
+ #include "usdt.h"
6
+
7
+ #include <stdio.h>
8
+ #include <stdlib.h>
9
+ #include <string.h>
10
+
11
+ static void
12
+ create_and_free_provider(int argc, char **argv)
13
+ {
14
+ usdt_provider_t *provider;
15
+ usdt_probedef_t *probedef;
16
+
17
+ if ((provider = usdt_create_provider("testlibusdt", "modname")) == NULL) {
18
+ fprintf(stderr, "unable to create provider\n");
19
+ exit (1);
20
+ }
21
+ if ((probedef = usdt_create_probe((const char *)argv[1],
22
+ (const char *)argv[2],
23
+ (argc-3), (const char **)&argv[3])) == NULL)
24
+ {
25
+ fprintf(stderr, "unable to create probe\n");
26
+ exit (1);
27
+ }
28
+ usdt_provider_add_probe(provider, probedef);
29
+
30
+ if ((usdt_provider_enable(provider)) < 0) {
31
+ fprintf(stderr, "unable to enable provider: %s\n", usdt_errstr(provider));
32
+ exit (1);
33
+ }
34
+
35
+ if ((usdt_provider_disable(provider)) < 0) {
36
+ fprintf(stderr, "unable to disable provider: %s\n", usdt_errstr(provider));
37
+ exit (1);
38
+ }
39
+
40
+ usdt_probe_release(probedef);
41
+ usdt_provider_free(provider);
42
+ }
43
+
44
+ int
45
+ main(int argc, char **argv)
46
+ {
47
+ char char_argv[USDT_ARG_MAX];
48
+ int int_argv[USDT_ARG_MAX * 2];
49
+ int i;
50
+ char buf[255];
51
+
52
+ for (i = 0; i < USDT_ARG_MAX; i++)
53
+ int_argv[i] = i + 1;
54
+ for (i = 0; i < USDT_ARG_MAX; i++)
55
+ char_argv[i] = (char) i + 65;
56
+
57
+ if (argc < 3) {
58
+ fprintf(stderr, "usage: %s func name [types ...]\n", argv[0]);
59
+ return(1);
60
+ }
61
+
62
+ for (i = 0; i < USDT_ARG_MAX; i++) {
63
+ if (argv[i+3] != NULL && i+3 < argc) {
64
+ if (strncmp("c", argv[i+3], 1) == 0) {
65
+ argv[i+3] = strdup("char *");
66
+ }
67
+ if (strncmp("i", argv[i+3], 1) == 0) {
68
+ argv[i+3] = strdup("int");
69
+ }
70
+ }
71
+ }
72
+
73
+ for (i = 0; i < 100000; i++)
74
+ create_and_free_provider(argc, argv);
75
+
76
+ return 0;
77
+ }