-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathlttng2lxt.h
251 lines (213 loc) · 5.92 KB
/
lttng2lxt.h
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
/**
* LTTng to GTKwave trace conversion
*
* Authors:
* Ivan Djelic <[email protected]>
* Matthieu Castet <[email protected]>
*
* Copyright (C) 2013 Parrot S.A.
*/
#ifndef LTTNG2LXT_H
#define LTTNG2LXT_H
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <unistd.h>
#include <errno.h>
#include <assert.h>
#include <stdarg.h>
#include <sys/types.h>
#include <regex.h>
#include <getopt.h>
#include <search.h>
#include <fnmatch.h>
#include <inttypes.h>
enum {
TRACE_SYM_F_BITS,
TRACE_SYM_F_INTEGER,
TRACE_SYM_F_STRING,
TRACE_SYM_F_DOUBLE,
};
/* Additional pseudo-trace symbol type */
#define TRACE_SYM_F_ANALOG ((1U<<29)|TRACE_SYM_F_DOUBLE)
#define TRACE_SYM_F_U16 ((1U<<30)|TRACE_SYM_F_INTEGER)
#define TRACE_SYM_F_ADDR (1U<<31)
#define PFX "lttng2lxt: "
#define LINEBUF_MAX (1024)
#define LT_S0 "x"
#define LT_S1 "u"
#define LT_S2 "w"
#define LT_S3 "-"
#define LT_IDLE "z"
#define LT_1 "1"
#define LT_0 "0"
#define MAX_CPU (4)
#define MAX_IRQS (1024)
#define PROCESS_IDLE LT_IDLE
#define PROCESS_KERNEL (gtkwave_parrot ? LT_S0 : LT_1)
#define PROCESS_USER (gtkwave_parrot ? LT_S1 : LT_S0)
#define PROCESS_WAKEUP (gtkwave_parrot ? LT_S2 : LT_0)
#define PROCESS_PREEMPTED (gtkwave_parrot ? LT_S3 : LT_0)
#define PROCESS_DEAD LT_0
enum trace_group {
TG_NONE,
TG_IRQ,
TG_MM,
TG_GLOBAL,
TG_USER,
TG_PROCESS,
};
union ltt_value {
char *state;
uint32_t data;
const char *format;
double dataf;
};
struct ltt_trace {
void *sym;
int fst_handle;
uint32_t flags;
enum trace_group group;
double pos;
const char *name;
const char *fst_name; /* fst allowed chars only */
int emitted;
struct ltt_trace *next;
/* XXX alow to save the task state before cs. should be done
in another struct */
union ltt_value value;
};
struct parse_result {
struct ltt_module *module;
double clock;
int pid;
const char *pname;
const char *mode;
const char *values;
};
struct task {
int pid;
int tgid;
struct ltt_trace *state_trace;
struct ltt_trace *info_trace;
const char *mode;
char *name;
int current_cpu;
};
enum arg_type {
ARG_I64,
ARG_U64,
ARG_STR,
};
struct arg_value {
enum arg_type type;
union {
uint64_t u64;
int64_t i64;
const char *s;
};
};
struct ltt_module {
const char *name;
void (*process)(const char *modname, int pass, double clock,
int cpu_id, void *args);
};
#define MODULE(_name_) \
static __attribute__((constructor)) void __r_ ## _name_(void) \
{ \
register_module(#_name_, _name_ ## _process); \
}
#define MODULE2(_n, _s) \
static __attribute__((constructor)) void __r_ ## _n ## _s(void) \
{ \
register_module(#_n ":" #_s, _n ##_## _s ## _process); \
}
#define MODULE_PATTERN(_name_, _pattern_) \
static __attribute__((constructor)) void __r_ ## _name_(void) \
{ \
register_module(#_pattern_, _name_ ## _process); \
}
#define FATAL(_fmt, args...) \
do { \
fprintf(stderr, PFX _fmt, ##args); \
exit(1); \
} while (0)
#define INFO(_fmt, args...) \
do { \
if (verbose) { \
fprintf(stderr, PFX _fmt, ##args); \
} \
} while (0)
#define DIAG(_fmt, args...) fprintf(stderr, PFX _fmt, ##args)
#define TDIAG(_name, _clock, _fmt, args...) \
do { \
if (diag) { \
fprintf(stderr, PFX "%s\t@%.0f ns :", \
(_name), (_clock)*1000000000); \
fprintf(stderr, _fmt, ##args); \
} \
} while (0)
extern int verbose;
extern int diag;
extern int gtkwave_parrot;
extern int show_cpu_switch;
extern int do_stats;
enum {
STAT_IRQ = 1,
STAT_SOFTIRQ = 2,
};
extern int atag_enabled;
void irq_stats(void);
void softirq_stats(void);
void atag_init(const char *name);
char *atag_get(uint32_t addr);
void atag_store(uint32_t addr);
void atag_flush(void);
void init_trace(struct ltt_trace *tr,
enum trace_group group,
double pos,
uint32_t flags,
const char *fmt, ...);
void refresh_name(struct ltt_trace *tr,
const char *fmt, ...);
void symbol_flush(void);
void emit_trace(struct ltt_trace *tr, union ltt_value value, ...);
struct ltt_trace *trace_head(void);
void emit_clock(double clock);
void save_dump_init(const char *name);
void save_dump_close(void);
struct task *get_current_task(int cpu);
struct task *find_or_add_task(const char *comm, int pid);
void parse_init(void);
int parse_line(char *line, struct parse_result *res);
const struct ltt_module *find_module_by_name(const char *name);
void register_module(const char *name, void (*process)(const char *modname,
int pass,
double clock,
int cpu,
void *args));
void unregister_modules(void);
void display_modules(void);
void write_savefile(const char *name);
void scan_lttng_trace(const char *nam, int rebase_clock);
int get_arg(void *args, const char *name, struct arg_value *value);
int64_t get_arg_i64(void *args, const char *name);
uint64_t get_arg_u64(void *args, const char *name);
const char *get_arg_str(void *args, const char *name);
void for_each_arg(void *args,
void (*pfn)(void *cookie,
const char *name,
const struct arg_value *value),
void *cookie);
void set_cpu_idle(double clock, int cpu);
void set_cpu_running(double clock, int cpu);
void cpu_preempt(double clock, int cpu);
void cpu_unpreempt(double clock, int cpu);
void init_cpu(int cpu);
void symbol_clean_name(char *name);
#ifndef ARRAY_SIZE
#define ARRAY_SIZE(x) ((int)(sizeof(x)/sizeof((x)[0])))
#endif
#endif /* LTTNG2LXT_H */