-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathtest_usdt.c
87 lines (72 loc) · 2.67 KB
/
test_usdt.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
* Copyright (c) 2012, Chris Andrews. All rights reserved.
*/
#include "usdt.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static void
fire_probe(usdt_probedef_t *probedef, int argc, void **argv)
{
if (usdt_is_enabled(probedef->probe))
usdt_fire_probe(probedef->probe, argc, argv);
}
int main(int argc, char **argv) {
usdt_provider_t *provider;
usdt_probedef_t *probedef;
char char_argv[USDT_ARG_MAX];
int int_argv[USDT_ARG_MAX * 2];
void **args = NULL;
int i;
char buf[255];
for (i = 0; i < USDT_ARG_MAX; i++)
int_argv[i] = i + 1;
for (i = 0; i < USDT_ARG_MAX; i++)
char_argv[i] = (char) i + 65;
if (argc < 3) {
fprintf(stderr, "usage: %s func name [types ...]\n", argv[0]);
return(1);
}
if (argc > 3) {
args = malloc((argc-3) * sizeof(void *));
}
for (i = 0; i < USDT_ARG_MAX; i++) {
if (argv[i+3] != NULL && i+3 < argc) {
if (strncmp("c", argv[i+3], 1) == 0) {
args[i] = (void *)strndup(&char_argv[i], 1);
argv[i+3] = strdup("char *");
}
if (strncmp("i", argv[i+3], 1) == 0) {
args[i] = (void *)(long)int_argv[i];
argv[i+3] = strdup("int");
}
}
}
if ((provider = usdt_create_provider("testlibusdt", "modname")) == NULL) {
fprintf(stderr, "unable to create provider\n");
exit (1);
}
if ((probedef = usdt_create_probe((const char *)argv[1],
(const char *)argv[2],
(argc-3), (const char **)&argv[3])) == NULL)
{
fprintf(stderr, "unable to create probe\n");
exit (1);
}
usdt_provider_add_probe(provider, probedef);
if ((usdt_provider_enable(provider)) < 0) {
fprintf(stderr, "unable to enable provider: %s\n", usdt_errstr(provider));
exit (1);
}
fprintf(stdout, "enabled\n");
fflush(stdout);
fgets(buf, 255, stdin);
fire_probe(probedef, (argc-3), (void **)args);
usdt_probe_release(probedef);
if ((usdt_provider_disable(provider)) < 0) {
fprintf(stderr, "unable to disable provider: %s\n", usdt_errstr(provider));
exit (1);
}
usdt_provider_free(provider);
return 0;
}