aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Rostedt <srostedt@redhat.com>2010-04-06 14:39:06 -0400
committerSteven Rostedt <rostedt@goodmis.org>2010-04-09 11:56:19 -0400
commit25d1c51565706f7d9e2a8cec31a80dd32c2c889b (patch)
tree58513717e24f80aafcd8bbb66e2cab0e674e89a7
parentb75d856e313af97226686e3ada78b633874ded29 (diff)
parse-events: Move parse-event utils to separate file
Move the util functions used by parse-events into a separate file and compile it with the libparsevents library. Also add "__die()" equivalent functions that are always available. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
-rw-r--r--Makefile2
-rw-r--r--parse-events.h10
-rw-r--r--parse-utils.c105
-rw-r--r--trace-util.c67
4 files changed, 116 insertions, 68 deletions
diff --git a/Makefile b/Makefile
index cd4db4a..7dde5cf 100644
--- a/Makefile
+++ b/Makefile
@@ -223,7 +223,7 @@ TRACE_GRAPH_MAIN_OBJS = trace-graph-main.o $(TRACE_GRAPH_OBJS) $(TRACE_GUI_OBJS)
223KERNEL_SHARK_OBJS = $(TRACE_VIEW_OBJS) $(TRACE_GRAPH_OBJS) $(TRACE_GUI_OBJS) \ 223KERNEL_SHARK_OBJS = $(TRACE_VIEW_OBJS) $(TRACE_GRAPH_OBJS) $(TRACE_GUI_OBJS) \
224 kernel-shark.o 224 kernel-shark.o
225 225
226PEVENT_LIB_OBJS = parse-events.o trace-seq.o parse-filter.o 226PEVENT_LIB_OBJS = parse-events.o trace-seq.o parse-filter.o parse-utils.o
227TCMD_LIB_OBJS = $(PEVENT_LIB_OBJS) trace-util.o trace-input.o trace-ftrace.o \ 227TCMD_LIB_OBJS = $(PEVENT_LIB_OBJS) trace-util.o trace-input.o trace-ftrace.o \
228 trace-output.o trace-record.o 228 trace-output.o trace-record.o
229 229
diff --git a/parse-events.h b/parse-events.h
index 0c6a330..5afbd1a 100644
--- a/parse-events.h
+++ b/parse-events.h
@@ -342,11 +342,21 @@ struct pevent {
342 struct event_format *last_event; 342 struct event_format *last_event;
343}; 343};
344 344
345/* Can be overridden */
345void die(char *fmt, ...); 346void die(char *fmt, ...);
346void *malloc_or_die(unsigned int size); 347void *malloc_or_die(unsigned int size);
347void warning(char *fmt, ...); 348void warning(char *fmt, ...);
348void pr_stat(char *fmt, ...); 349void pr_stat(char *fmt, ...);
349 350
351/* Always available */
352void __die(char *fmt, ...);
353void __warning(char *fmt, ...);
354void __pr_stat(char *fmt, ...);
355
356void __vdie(char *fmt, ...);
357void __vwarning(char *fmt, ...);
358void __vpr_stat(char *fmt, ...);
359
350static inline unsigned short 360static inline unsigned short
351__data2host2(struct pevent *pevent, unsigned short data) 361__data2host2(struct pevent *pevent, unsigned short data)
352{ 362{
diff --git a/parse-utils.c b/parse-utils.c
new file mode 100644
index 0000000..103bbd8
--- /dev/null
+++ b/parse-utils.c
@@ -0,0 +1,105 @@
1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4#include <stdarg.h>
5#include <errno.h>
6
7#define __weak __attribute__((weak))
8
9void __vdie(char *fmt, va_list ap)
10{
11 int ret = errno;
12
13 if (errno)
14 perror("trace-cmd");
15 else
16 ret = -1;
17
18 fprintf(stderr, " ");
19 vfprintf(stderr, fmt, ap);
20
21 fprintf(stderr, "\n");
22 exit(ret);
23}
24
25void __die(char *fmt, ...)
26{
27 va_list ap;
28
29 va_start(ap, fmt);
30 __vdie(fmt, ap);
31 va_end(ap);
32}
33
34void __weak die(char *fmt, ...)
35{
36 va_list ap;
37
38 va_start(ap, fmt);
39 __vdie(fmt, ap);
40 va_end(ap);
41}
42
43void __vwarning(char *fmt, va_list ap)
44{
45 if (errno)
46 perror("trace-cmd");
47 errno = 0;
48
49 fprintf(stderr, " ");
50 vfprintf(stderr, fmt, ap);
51
52 fprintf(stderr, "\n");
53}
54
55void __warning(char *fmt, ...)
56{
57 va_list ap;
58
59 va_start(ap, fmt);
60 __vwarning(fmt, ap);
61 va_end(ap);
62}
63
64void __weak warning(char *fmt, ...)
65{
66 va_list ap;
67
68 va_start(ap, fmt);
69 __vwarning(fmt, ap);
70 va_end(ap);
71}
72
73void __vpr_stat(char *fmt, va_list ap)
74{
75 vprintf(fmt, ap);
76 printf("\n");
77}
78
79void __pr_stat(char *fmt, ...)
80{
81 va_list ap;
82
83 va_start(ap, fmt);
84 __vpr_stat(fmt, ap);
85 va_end(ap);
86}
87
88void __weak pr_stat(char *fmt, ...)
89{
90 va_list ap;
91
92 va_start(ap, fmt);
93 __vpr_stat(fmt, ap);
94 va_end(ap);
95}
96
97void __weak *malloc_or_die(unsigned int size)
98{
99 void *data;
100
101 data = malloc(size);
102 if (!data)
103 die("malloc");
104 return data;
105}
diff --git a/trace-util.c b/trace-util.c
index 7f6f0bb..0397732 100644
--- a/trace-util.c
+++ b/trace-util.c
@@ -38,8 +38,6 @@
38int tracecmd_disable_sys_plugins; 38int tracecmd_disable_sys_plugins;
39int tracecmd_disable_plugins; 39int tracecmd_disable_plugins;
40 40
41#define __weak __attribute__((weak))
42
43#define _STR(x) #x 41#define _STR(x) #x
44#define STR(x) _STR(x) 42#define STR(x) _STR(x)
45 43
@@ -53,71 +51,6 @@ struct plugin_list {
53 void *handle; 51 void *handle;
54}; 52};
55 53
56void __weak die(char *fmt, ...)
57{
58 va_list ap;
59 int ret = errno;
60
61 if (errno)
62 perror("trace-cmd");
63 else
64 ret = -1;
65
66 va_start(ap, fmt);
67 fprintf(stderr, " ");
68 vfprintf(stderr, fmt, ap);
69 va_end(ap);
70
71 fprintf(stderr, "\n");
72 exit(ret);
73}
74
75void __weak warning(char *fmt, ...)
76{
77 va_list ap;
78
79 if (errno)
80 perror("trace-cmd");
81 errno = 0;
82
83 va_start(ap, fmt);
84 fprintf(stderr, " ");
85 vfprintf(stderr, fmt, ap);
86 va_end(ap);
87
88 fprintf(stderr, "\n");
89}
90
91void __weak pr_stat(char *fmt, ...)
92{
93 va_list ap;
94
95 va_start(ap, fmt);
96 vprintf(fmt, ap);
97 va_end(ap);
98
99 printf("\n");
100}
101
102void __weak *malloc_or_die(unsigned int size)
103{
104 void *data;
105
106 data = malloc(size);
107 if (!data)
108 die("malloc");
109 return data;
110}
111
112int __weak bigendian(void)
113{
114 unsigned char str[] = { 0x1, 0x2, 0x3, 0x4 };
115 unsigned int *ptr;
116
117 ptr = (unsigned int *)str;
118 return *ptr == 0x01020304;
119}
120
121void parse_cmdlines(struct pevent *pevent, 54void parse_cmdlines(struct pevent *pevent,
122 char *file, int size __unused) 55 char *file, int size __unused)
123{ 56{