diff options
author | Steven Rostedt <srostedt@redhat.com> | 2010-02-12 09:43:02 -0500 |
---|---|---|
committer | Steven Rostedt <rostedt@goodmis.org> | 2010-02-12 09:43:02 -0500 |
commit | 0f64a9efd51a8e08fdba826c6399c7ffb4f2442c (patch) | |
tree | 6b47ca6c655514df00110238f76a37ed6b46b769 /trace-input.c | |
parent | eb2271faa2557999f3e98def46002d8914bf9e65 (diff) |
trace-cmd: Add tracecmd_get_cursor()
Add the helper routine tracecmd_get_cursor() that returns the offset
of the next tracecmd_read_data() or tracecmd_peek_data().
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Diffstat (limited to 'trace-input.c')
-rw-r--r-- | trace-input.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/trace-input.c b/trace-input.c index 3cf079d..306b7a5 100644 --- a/trace-input.c +++ b/trace-input.c | |||
@@ -1246,6 +1246,50 @@ int tracecmd_set_cursor(struct tracecmd_input *handle, | |||
1246 | return 0; | 1246 | return 0; |
1247 | } | 1247 | } |
1248 | 1248 | ||
1249 | /** | ||
1250 | * tracecmd_get_cursor - get the offset for the next tracecmd_read_data | ||
1251 | * @handle: input handle for the trace.dat file | ||
1252 | * @cpu: the CPU pointer to get the cursor from | ||
1253 | * | ||
1254 | * Returns the offset of the next record that would be read. | ||
1255 | */ | ||
1256 | unsigned long long | ||
1257 | tracecmd_get_cursor(struct tracecmd_input *handle, int cpu) | ||
1258 | { | ||
1259 | struct cpu_data *cpu_data = &handle->cpu_data[cpu]; | ||
1260 | struct pevent *pevent; | ||
1261 | int index; | ||
1262 | |||
1263 | if (cpu < 0 || cpu >= handle->cpus) | ||
1264 | return 0; | ||
1265 | |||
1266 | /* | ||
1267 | * Use the next pointer if it exists and matches the | ||
1268 | * current timestamp. | ||
1269 | */ | ||
1270 | if (cpu_data->next && | ||
1271 | cpu_data->next->ts == cpu_data->timestamp) | ||
1272 | return cpu_data->next->offset; | ||
1273 | |||
1274 | /* | ||
1275 | * Either the next point does not exist, or it does | ||
1276 | * not match the timestamp. The next read will use the | ||
1277 | * current page. | ||
1278 | * | ||
1279 | * If the offset is at the end, then return that. | ||
1280 | */ | ||
1281 | if (cpu_data->offset >= cpu_data->file_offset + | ||
1282 | cpu_data->file_size) | ||
1283 | return cpu_data->offset; | ||
1284 | |||
1285 | pevent = handle->pevent; | ||
1286 | |||
1287 | index = cpu_data->index ? cpu_data->index : | ||
1288 | pevent->header_page_data_offset; | ||
1289 | |||
1290 | return cpu_data->offset + index; | ||
1291 | } | ||
1292 | |||
1249 | 1293 | ||
1250 | static unsigned int | 1294 | static unsigned int |
1251 | translate_data(struct tracecmd_input *handle, | 1295 | translate_data(struct tracecmd_input *handle, |