Revision fb3a5085
b/trace/simple.c | ||
---|---|---|
53 | 53 |
uint8_t trace_buf[TRACE_BUF_LEN]; |
54 | 54 |
static unsigned int trace_idx; |
55 | 55 |
static unsigned int writeout_idx; |
56 |
static uint64_t dropped_events;
|
|
56 |
static int dropped_events;
|
|
57 | 57 |
static FILE *trace_fp; |
58 | 58 |
static char *trace_file_name; |
59 | 59 |
|
... | ... | |
63 | 63 |
uint64_t timestamp_ns; |
64 | 64 |
uint32_t length; /* in bytes */ |
65 | 65 |
uint32_t reserved; /* unused */ |
66 |
uint8_t arguments[];
|
|
66 |
uint64_t arguments[];
|
|
67 | 67 |
} TraceRecord; |
68 | 68 |
|
69 | 69 |
typedef struct { |
... | ... | |
160 | 160 |
uint8_t bytes[sizeof(TraceRecord) + sizeof(uint64_t)]; |
161 | 161 |
} dropped; |
162 | 162 |
unsigned int idx = 0; |
163 |
uint64_t dropped_count;
|
|
163 |
int dropped_count;
|
|
164 | 164 |
size_t unused __attribute__ ((unused)); |
165 | 165 |
|
166 | 166 |
for (;;) { |
... | ... | |
169 | 169 |
if (dropped_events) { |
170 | 170 |
dropped.rec.event = DROPPED_EVENT_ID, |
171 | 171 |
dropped.rec.timestamp_ns = get_clock(); |
172 |
dropped.rec.length = sizeof(TraceRecord) + sizeof(dropped_events),
|
|
172 |
dropped.rec.length = sizeof(TraceRecord) + sizeof(uint64_t),
|
|
173 | 173 |
dropped.rec.reserved = 0; |
174 | 174 |
while (1) { |
175 | 175 |
dropped_count = dropped_events; |
176 |
if (g_atomic_int_compare_and_exchange((gint *)&dropped_events,
|
|
176 |
if (g_atomic_int_compare_and_exchange(&dropped_events, |
|
177 | 177 |
dropped_count, 0)) { |
178 | 178 |
break; |
179 | 179 |
} |
180 | 180 |
} |
181 |
memcpy(dropped.rec.arguments, &dropped_count, sizeof(uint64_t));
|
|
181 |
dropped.rec.arguments[0] = dropped_count;
|
|
182 | 182 |
unused = fwrite(&dropped.rec, dropped.rec.length, 1, trace_fp); |
183 | 183 |
} |
184 | 184 |
|
... | ... | |
220 | 220 |
|
221 | 221 |
if (new_idx - writeout_idx > TRACE_BUF_LEN) { |
222 | 222 |
/* Trace Buffer Full, Event dropped ! */ |
223 |
g_atomic_int_inc((gint *)&dropped_events);
|
|
223 |
g_atomic_int_inc(&dropped_events); |
|
224 | 224 |
return -ENOSPC; |
225 | 225 |
} |
226 | 226 |
|
227 |
if (g_atomic_int_compare_and_exchange((gint *)&trace_idx,
|
|
227 |
if (g_atomic_int_compare_and_exchange(&trace_idx, |
|
228 | 228 |
old_idx, new_idx)) { |
229 | 229 |
break; |
230 | 230 |
} |
Also available in: Unified diff